From 359076b868b369b5a2af01879e3472fc2c89cc77 Mon Sep 17 00:00:00 2001 From: SaurabhForge Date: Thu, 27 Aug 2026 22:28:53 +0530 Subject: [PATCH] feat: add optional Icon field to Goal model and implement GetForUser test --- CommBank-Server/Models/Goal.cs | 4 +++- CommBank.Tests/Fake/FakeCollections.cs | 11 +++++++---- CommBank.Tests/GoalControllerTests.cs | 20 +++++++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad5..ed464405 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -1,4 +1,4 @@ -using MongoDB.Bson; +using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; namespace CommBank.Models; @@ -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..8a9f927e 100644 --- a/CommBank.Tests/Fake/FakeCollections.cs +++ b/CommBank.Tests/Fake/FakeCollections.cs @@ -1,4 +1,4 @@ -using CommBank.Models; +using CommBank.Models; namespace CommBank.Tests.Fake { @@ -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 = "1" }, }; diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181f..a9c071c3 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -1,4 +1,4 @@ -using CommBank.Controllers; +using CommBank.Controllers; using CommBank.Services; using CommBank.Models; using CommBank.Tests.Fake; @@ -66,9 +66,23 @@ 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); + foreach (Goal goal in result!) + { + Assert.IsAssignableFrom(goal); + Assert.Equal(users[0].Id, goal.UserId); + } } } \ No newline at end of file