diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad5..81f01923 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -11,6 +11,8 @@ public class Goal public string? Name { get; set; } + public string? Icon { get; set; } + public UInt64 TargetAmount { get; set; } = 0; public DateTime TargetDate { get; set; } diff --git a/CommBank.Tests/Fake/FakeCollections.cs b/CommBank.Tests/Fake/FakeCollections.cs index 28452832..751a6092 100644 --- a/CommBank.Tests/Fake/FakeCollections.cs +++ b/CommBank.Tests/Fake/FakeCollections.cs @@ -10,7 +10,6 @@ public class FakeCollections List transactions; List users; - public FakeCollections() { accounts = new() @@ -19,12 +18,14 @@ public FakeCollections() { Id = "1", Name = "Tag's GoalSaver" + }, new() { Id = "2", Name = "Trot's GoalSaver" + } }; @@ -33,19 +34,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 = "2" }, new() { Id = "3", - Name = "Trip to London" + Name = "Trip to London", + UserId = "3" }, }; diff --git a/CommBank.Tests/Fake/FakeGoalsService.cs b/CommBank.Tests/Fake/FakeGoalsService.cs index 643a27e6..6bc39fcc 100644 --- a/CommBank.Tests/Fake/FakeGoalsService.cs +++ b/CommBank.Tests/Fake/FakeGoalsService.cs @@ -18,8 +18,12 @@ public FakeGoalsService(List goals, Goal goal) public async Task> GetAsync() => await Task.FromResult(_goals); - public async Task?> GetForUserAsync(string id) => - await Task.FromResult(_goals); + public async Task?> GetForUserAsync(string id) +{ + var userGoals = _goals.Where(goal => goal.UserId == id).ToList(); + + return await Task.FromResult(userGoals); +} public async Task GetAsync(string id) => await Task.FromResult(_goal); diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181f..57e47601 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -66,9 +66,25 @@ 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(users[0].Id!); // Assert + Assert.NotNull(result); + +Assert.Single(result!); +Assert.Equal(goals[0].Id, result[0].Id); +Assert.Equal(goals[0].UserId, result[0].UserId); } } \ No newline at end of file