From 5df93fd665ef7685c6c3d94e21d01647f4d02fb2 Mon Sep 17 00:00:00 2001 From: abhizroy Date: Mon, 10 Aug 2026 21:25:49 +0530 Subject: [PATCH 1/2] Add optional icon field to Goal model --- .gitignore | 2 ++ CommBank-Server/Models/Goal.cs | 2 ++ CommBank-Server/Secrets.json | 5 ----- 3 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 CommBank-Server/Secrets.json diff --git a/.gitignore b/.gitignore index 67697151..fe095b10 100644 --- a/.gitignore +++ b/.gitignore @@ -405,3 +405,5 @@ ASALocalRun/ .localhistory/ +# Local secrets +Secrets.json \ No newline at end of file diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad5..20b9b5d4 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-Server/Secrets.json b/CommBank-Server/Secrets.json deleted file mode 100644 index 0e5bf949..00000000 --- a/CommBank-Server/Secrets.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" - } -} \ No newline at end of file From 3ccd9534ab3bbc95d1f10f5a2097097e5298e29d Mon Sep 17 00:00:00 2001 From: abhizroy Date: Tue, 11 Aug 2026 11:55:50 +0530 Subject: [PATCH 2/2] Add GetGoalsForUser test --- CommBank.Tests/GoalControllerTests.cs | 38 ++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181f..f798d6c9 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -2,7 +2,6 @@ using CommBank.Services; using CommBank.Models; using CommBank.Tests.Fake; -using Microsoft.AspNetCore.Mvc; namespace CommBank.Tests; @@ -16,44 +15,52 @@ public GoalControllerTests() } [Fact] - public async void GetAll() + public async Task GetAll() { // 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.Get(); // Assert 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++; } } [Fact] - public async void Get() + public async Task Get() { // 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.Get(goals[0].Id!); // Assert @@ -63,12 +70,31 @@ public async void Get() } [Fact] - public async void GetForUser() + public async Task 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 result = await controller.GetForUser(users[0].Id!); + // Assert + Assert.NotNull(result); + Assert.Equal(goals.Count, result.Count); + + for (var index = 0; index < goals.Count; index++) + { + Assert.Equal(goals[index].Id, result[index].Id); + Assert.Equal(goals[index].Name, result[index].Name); + Assert.Equal(goals[index].TargetAmount, result[index].TargetAmount); + Assert.Equal(goals[index].Balance, result[index].Balance); + Assert.Equal(goals[index].UserId, result[index].UserId); + } } } \ No newline at end of file