From 3c602f801e27eab4781071f8181ab642d78fbbc8 Mon Sep 17 00:00:00 2001 From: Ansh Date: Thu, 25 Jun 2026 18:44:07 +0530 Subject: [PATCH] Add goal icon support and tests --- CommBank-Server/Models/Goal.cs | 2 ++ CommBank.Tests/GoalControllerTests.cs | 28 ++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad..20b9b5d 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -27,4 +27,6 @@ public class Goal [BsonRepresentation(BsonType.ObjectId)] public string? UserId { get; set; } + + public string? Icon { get; set; } } \ No newline at end of file diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181..fe8e23b 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -65,10 +65,28 @@ public async void Get() [Fact] public async void GetForUser() { - // Arrange - - // Act - - // Assert + // 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); + + var index = 0; + foreach (Goal goal in result!) + { + Assert.IsAssignableFrom(goal); + Assert.Equal(goals[index].Id, goal.Id); + Assert.Equal(goals[index].Name, goal.Name); + index++; + } } } \ No newline at end of file