Skip to content
Merged
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
1 change: 1 addition & 0 deletions backend/src/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ CancellationToken cancellationToken
error switch
{
GetUsersError.OrganisationNotFound => BadRequest("Organisation not found."),
GetUsersError.NotAllowed => Forbid("User is forbidden from accessing data."),
_ => throw new UnreachableException("Unhandled GetUsersError variant."),
}
);
Expand Down
26 changes: 26 additions & 0 deletions backend/tests/Controllers/UserControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ public async Task GetUsers_ReturnsNotFound_WhenOrganisationDoesNotExist()
badRequest.Value.ShouldBe("Organisation not found.");
}

[Fact]
public async Task GetUsers_ReturnsForbid_WhenNotAllowed()
{
var sampleId = 1;
_mockUserService
.GetUsers(
Arg.Any<int?>(),
Arg.Any<int>(),
Arg.Any<int>(),
Arg.Any<IReadOnlyCollection<UserOrgStatus>>(),
TestContext.Current.CancellationToken
)
.Returns(
Result<PaginatedResponseDto<UserListItemDto>, GetUsersError>.Err(
new GetUsersError.NotAllowed(sampleId)
)
);

ActionResult<PaginatedResponseDto<UserListItemDto>> result = await _controller.GetUsers(
CreateQuery(),
TestContext.Current.CancellationToken
);

result.Result.ShouldBeOfType<ForbidResult>();
}

[Fact]
public async Task GetUsers_ReturnsBadRequest_WhenQueryIsNull()
{
Expand Down