From ad2f4ccde042dbae75f94546cb60326c09e9e6b5 Mon Sep 17 00:00:00 2001 From: Pallavi Gupta Date: Tue, 3 Mar 2026 17:06:12 +0530 Subject: [PATCH] Added icon property support and updated JSON response --- CommBank-Server/CommBank.csproj | 3 ++- CommBank-Server/Models/Goal.cs | 3 +++ CommBank-Server/Program.cs | 2 +- CommBank-Server/Secrets.json | 6 ++--- CommBank.Tests/GoalControllerTests.cs | 38 ++++++++++++++++++++++++--- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/CommBank-Server/CommBank.csproj b/CommBank-Server/CommBank.csproj index 983cc88..7bc93ff 100644 --- a/CommBank-Server/CommBank.csproj +++ b/CommBank-Server/CommBank.csproj @@ -9,11 +9,12 @@ + - + diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad..29f0566 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -27,4 +27,7 @@ public class Goal [BsonRepresentation(BsonType.ObjectId)] public string? UserId { get; set; } + // New optional icon + public string? Icon { get; set; } + } \ No newline at end of file diff --git a/CommBank-Server/Program.cs b/CommBank-Server/Program.cs index a88e560..bdcde71 100644 --- a/CommBank-Server/Program.cs +++ b/CommBank-Server/Program.cs @@ -12,7 +12,7 @@ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json"); var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank")); -var mongoDatabase = mongoClient.GetDatabase("CommBank"); +var mongoDatabase = mongoClient.GetDatabase("rserver_db"); IAccountsService accountsService = new AccountsService(mongoDatabase); IAuthService authService = new AuthService(mongoDatabase); diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json index 0e5bf94..7f2f0e1 100644 --- a/CommBank-Server/Secrets.json +++ b/CommBank-Server/Secrets.json @@ -1,5 +1,5 @@ { - "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" + "ConnectionStrings": { + "CommBank": "mongodb+srv://rserver_user:PASSWORD@cluster0.flnxkb0.mongodb.net/rserver_db?retryWrites=true&w=majority" } -} \ No newline at end of file +} diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181..1f9d0b1 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -63,12 +63,44 @@ public async void Get() } [Fact] - public async void GetForUser() + public async Task GetForUser_ReturnsGoalsForCorrectUser() { // Arrange - + var userId = "1"; + + var goals = new List + { + new Goal + { + Id = "1", + UserId = userId, + Name = "Car", + TargetAmount = 5000, + Icon = "🚗" + }, + new Goal + { + Id = "2", + UserId = userId, + Name = "House", + TargetAmount = 10000, + Icon = "🏠" + } + }; + + 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(userId); + // Assert + Assert.NotNull(result); + Assert.IsAssignableFrom>(result); + Assert.Equal(2, result!.Count()); + Assert.All(result!, g => Assert.Equal(userId, g.UserId)); + Assert.All(result!, g => Assert.NotNull(g.Icon)); } } \ No newline at end of file