Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CommBank-Server/CommBank.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<PackageReference Include="MongoDB.Driver" Version="3.7.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public class Goal

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }
// New optional icon
public string? Icon { get; set; }

}
2 changes: 1 addition & 1 deletion CommBank-Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions CommBank-Server/Secrets.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
38 changes: 35 additions & 3 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Goal>
{
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<IEnumerable<Goal>>(result);
Assert.Equal(2, result!.Count());
Assert.All(result!, g => Assert.Equal(userId, g.UserId));
Assert.All(result!, g => Assert.NotNull(g.Icon));
}
}