Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test-results/
*.app

# content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore
# General

.DS_Store
.AppleDouble
.LSOverride
Expand Down Expand Up @@ -405,3 +405,15 @@ ASALocalRun/
.localhistory/


.env
.env.local
.env.*.local

Secrets.json

# Test/Mock Data Files
getAll.json
getId.json
getId_withIcon.json


17 changes: 17 additions & 0 deletions CommBank-Server/Controllers/GoalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ public async Task<IActionResult> Update(string id, Goal updatedGoal)
return NoContent();
}

[HttpPut("{id:length(24)}/icon")]
public async Task<IActionResult> UpdateIcon(string id, [FromBody] UpdatedIcon updatedIcon)
{
var goal = await _goalsService.GetAsync(id);

if (goal is null)
{
return NotFound();
}

goal.Icon = updatedIcon.Icon;

await _goalsService.UpdateAsync(id, goal);

return NoContent();
}

[HttpDelete("{id:length(24)}")]
public async Task<IActionResult> Delete(string id)
{
Expand Down
2 changes: 2 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public class Goal

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }

public string? Icon { get; set; }
}
5 changes: 0 additions & 5 deletions CommBank-Server/Secrets.json

This file was deleted.

9 changes: 6 additions & 3 deletions CommBank.Tests/Fake/FakeCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ public FakeCollections()
new()
{
Id = "1",
Name = "House Down Payment"
Name = "House Down Payment",
UserId = "1"
},

new()
{
Id = "2",
Name = "Tesla Model Y"
Name = "Tesla Model Y",
UserId = "1"
},

new()
{
Id = "3",
Name = "Trip to London"
Name = "Trip to London",
UserId = "2"
},
};

Expand Down
2 changes: 1 addition & 1 deletion CommBank.Tests/Fake/FakeGoalsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<List<Goal>> GetAsync() =>
await Task.FromResult(_goals);

public async Task<List<Goal>?> GetForUserAsync(string id) =>
await Task.FromResult(_goals);
await Task.FromResult(_goals.Where(g => g.UserId == id).ToList());

public async Task<Goal?> GetAsync(string id) =>
await Task.FromResult(_goal);
Expand Down
21 changes: 19 additions & 2 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,26 @@ public async void Get()
public async void GetForUser()
{
// Arrange

var goals = collections.GetGoals();
var users = collections.GetUsers();
IGoalsService goalsService = new FakeGoalsService(goals, goals[0]);
IUsersService usersService = new FakeUsersService(users, users[0]);
GoalController controller = new(goalsService, usersService);

// Act

var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();
controller.ControllerContext.HttpContext = httpContext;
var result = await controller.GetForUser(goals[0].UserId!);

// Assert
Assert.NotNull(result);

var index = 0;
foreach (Goal goal in result!)
{
Assert.IsAssignableFrom<Goal>(goal);
Assert.Equal(goals[0].UserId, goal.UserId);
index++;
}
}
}