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
5 changes: 4 additions & 1 deletion CommBank-Server/CommBank.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<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="2.19.0" />
<PackageReference Include="Snappier" Version="1.3.1" />
<PackageReference Include="SharpCompress" Version="0.48.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.3.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 @@ -25,6 +25,9 @@ public class Goal
[BsonRepresentation(BsonType.ObjectId)]
public List<string>? TagIds { get; set; }

// Added for Task 1
public string? Icon { get; set; }

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }
}
2 changes: 1 addition & 1 deletion CommBank-Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json");

var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank"));
var mongoClient = new MongoClient(builder.Configuration["CONNECTION_STRING"]);
var mongoDatabase = mongoClient.GetDatabase("CommBank");

IAccountsService accountsService = new AccountsService(mongoDatabase);
Expand Down
4 changes: 1 addition & 3 deletions CommBank-Server/Secrets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"ConnectionStrings": {
"CommBank": "{CONNECTION_STRING}"
}
"CONNECTION_STRING": "mongodb+srv://admin:Ouma2001@cluster0.xkhaia3.mongodb.net/CommBank?retryWrites=true&w=majority&appName=Cluster0"
}
77 changes: 74 additions & 3 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,80 @@ 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>(goal);
Assert.Equal(users[0].Id, goal.UserId);
}
}
[Fact]
public async void Update()
{
// 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);

var updatedGoal = new Goal
{
Id = goals[0].Id,
Name = "Updated Goal",
UserId = goals[0].UserId,
Icon = "🎯",
TargetAmount = goals[0].TargetAmount,
Balance = goals[0].Balance,
TargetDate = goals[0].TargetDate,
Created = goals[0].Created,
AccountId = goals[0].AccountId,
TransactionIds = goals[0].TransactionIds,
TagIds = goals[0].TagIds
};

// Act

var result = await controller.Update(goals[0].Id!, updatedGoal);

// Assert
Assert.IsType<NoContentResult>(result);
}
}

[Fact]
public async void Update_ReturnsNotFound_WhenGoalDoesNotExist()
{
// Arrange
var goals = collections.GetGoals();
var users = collections.GetUsers();

IGoalsService goalsService = new FakeGoalsService(goals, null);
IUsersService usersService = new FakeUsersService(users, users[0]);

GoalController controller = new(goalsService, usersService);

var updatedGoal = new Goal();

// Act
var result = await controller.Update("123456789012345678901234", updatedGoal);

// Assert
Assert.IsType<NotFoundResult>(result);
}