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
8 changes: 4 additions & 4 deletions CommBank-Server/Controllers/GoalController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using CommBank.Services;
using CommBank.Models;

Expand Down Expand Up @@ -69,7 +69,7 @@ public async Task<IActionResult> Post(Goal newGoal)
}

[HttpPut("{id:length(24)}")]
public async Task<IActionResult> Update(string id, Goal updatedGoal)
public async Task<IActionResult> Update(string id, UpdatedIcon updatedIcon)
{
var goal = await _goalsService.GetAsync(id);

Expand All @@ -78,9 +78,9 @@ public async Task<IActionResult> Update(string id, Goal updatedGoal)
return NotFound();
}

updatedGoal.Id = goal.Id;
goal.Icon = updatedIcon.Icon;

await _goalsService.UpdateAsync(id, updatedGoal);
await _goalsService.UpdateAsync(id, goal);

return NoContent();
}
Expand Down
4 changes: 3 additions & 1 deletion CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MongoDB.Bson;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace CommBank.Models;
Expand Down Expand Up @@ -27,4 +27,6 @@ public class Goal

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }

public string? Icon { get; set; }
}
7 changes: 6 additions & 1 deletion CommBank-Server/Models/UpdatedIcon.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CommBank.Models;
namespace CommBank.Models;

interface IUpdatedIcon
{
Expand All @@ -8,6 +8,11 @@ interface IUpdatedIcon

public class UpdatedIcon : IUpdatedIcon
{
public UpdatedIcon()
{
Icon = string.Empty;
}

public UpdatedIcon(string icon)
{
Icon = icon;
Expand Down
24 changes: 21 additions & 3 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommBank.Controllers;
using CommBank.Controllers;
using CommBank.Services;
using CommBank.Models;
using CommBank.Tests.Fake;
Expand Down Expand Up @@ -66,9 +66,27 @@ public async void Get()
public async void GetForUser()
{
// Arrange

var goals = collections.GetGoals();
var users = collections.GetUsers();
foreach (var goal in goals)
{
goal.UserId = users[0].Id;
}
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);
}
}
}