From c331581583e7a3a5a69a5e15fd028246d55f4aca Mon Sep 17 00:00:00 2001 From: daksh-lodha Date: Tue, 16 Jun 2026 10:46:46 +0530 Subject: [PATCH] Add Icon to Goal model and GoalControllerTests --- CommBank-Server/Models/Goal.cs | 6 ++-- CommBank.Tests/GoalControllerTests.cs | 47 +++++---------------------- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad5..c203a61e 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -19,12 +19,14 @@ public class Goal public DateTime Created { get; set; } = DateTime.Now; + [BsonRepresentation(BsonType.ObjectId)] + public string? AccountId { get; set; } + [BsonRepresentation(BsonType.ObjectId)] public List? TransactionIds { get; set; } [BsonRepresentation(BsonType.ObjectId)] public List? TagIds { get; set; } - [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 8380181f..e97f8e3d 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -1,8 +1,7 @@ using CommBank.Controllers; -using CommBank.Services; using CommBank.Models; -using CommBank.Tests.Fake; -using Microsoft.AspNetCore.Mvc; +using CommBank.Services; +using CommBank.Tests.Fakes; namespace CommBank.Tests; @@ -16,7 +15,7 @@ public GoalControllerTests() } [Fact] - public async void GetAll() + public async void GetForUser() { // Arrange var goals = collections.GetGoals(); @@ -28,47 +27,17 @@ public async void GetAll() // Act var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext(); controller.ControllerContext.HttpContext = httpContext; - var result = await controller.Get(); + var result = await controller.GetForUser(goals[0].UserId!); // Assert + Assert.NotNull(result); + var index = 0; - foreach (Goal goal in result) + foreach (Goal goal in result!) { Assert.IsAssignableFrom(goal); - Assert.Equal(goals[index].Id, goal.Id); - Assert.Equal(goals[index].Name, goal.Name); + Assert.Equal(goals[0].UserId, goal.UserId); index++; } } - - [Fact] - public async void 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 - Assert.IsAssignableFrom(result.Value); - Assert.Equal(goals[0], result.Value); - Assert.NotEqual(goals[1], result.Value); - } - - [Fact] - public async void GetForUser() - { - // Arrange - - // Act - - // Assert - } } \ No newline at end of file