Skip to content

Commit

Permalink
Set the user's role in relevant tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTedder committed Oct 28, 2024
1 parent 28bccf0 commit 18b527c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion LeaderboardBackend.Test/Leaderboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,11 @@ public async Task DeleteLeaderboard_BadRole(UserRole role)
IUserService userService = _factory.Services.CreateScope().ServiceProvider.GetRequiredService<IUserService>();
ApplicationContext context = _factory.Services.CreateScope().ServiceProvider.GetRequiredService<ApplicationContext>();

string email = $"testuser.deletelb.{role}@example.com";

RegisterRequest registerRequest = new()
{
Email = $"testuser.deletelb.{role}@example.com",
Email = email,
Password = "Passw0rd",
Username = $"DeleteLBTest{role}"
};
Expand All @@ -575,12 +577,18 @@ public async Task DeleteLeaderboard_BadRole(UserRole role)
context.Leaderboards.Add(lb);
await context.SaveChangesAsync();
LoginResponse res = await _apiClient.LoginUser(registerRequest.Email, registerRequest.Password);
User? user = await userService.GetUserByEmail(email);
user.Should().NotBeNull();
user!.Role = role;
context.Users.Update(user);
await context.SaveChangesAsync();

await FluentActions.Awaiting(() => _apiClient.Delete(
$"/leaderboard/{lb.Id}",
new() { Jwt = res.Token }
)).Should().ThrowAsync<RequestFailureException>().Where(e => e.Response.StatusCode == HttpStatusCode.Forbidden);

context.ChangeTracker.Clear();
Leaderboard? found = await context.Leaderboards.FindAsync(lb.Id);
found.Should().NotBeNull();
found!.DeletedAt.Should().BeNull();
Expand Down

0 comments on commit 18b527c

Please sign in to comment.