-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
53 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using LeaderboardBackend.Models.Entities; | ||
using LeaderboardBackend.Models.Requests; | ||
|
@@ -15,7 +12,6 @@ | |
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualBasic; | ||
using NodaTime; | ||
using NodaTime.Testing; | ||
using NUnit.Framework; | ||
|
@@ -359,13 +355,10 @@ public async Task RestoreLeaderboard_OK() | |
Leaderboard deletedBoard = new() | ||
{ | ||
Name = "Super Mario World", | ||
Slug = "super-mario-world-deleted", | ||
Slug = "super-mario-world-to-restore", | ||
DeletedAt = _clock.GetCurrentInstant() | ||
}; | ||
|
||
Instant now = Instant.FromUnixTimeSeconds(1); | ||
_clock.Reset(now); | ||
|
||
context.Leaderboards.Add(deletedBoard); | ||
await context.SaveChangesAsync(); | ||
deletedBoard.Id.Should().NotBe(default); | ||
|
@@ -394,21 +387,22 @@ public async Task RestoreLeaderboard_Unauthenticated() | |
await act.Should().ThrowAsync<RequestFailureException>().Where(e => e.Response.StatusCode == HttpStatusCode.Unauthorized); | ||
} | ||
|
||
[Test] | ||
public async Task RestoreLeaderboard_Unauthorized() | ||
[TestCase("[email protected]", "RestoreBoard1", UserRole.Confirmed)] | ||
[TestCase("[email protected]", "RestoreBoard2", UserRole.Registered)] | ||
public async Task RestoreLeaderboard_Unauthorized(string email, string username, UserRole role) | ||
{ | ||
IUserService userService = _factory.Services.CreateScope().ServiceProvider.GetRequiredService<IUserService>(); | ||
UserViewModel userModel = await _apiClient.RegisterUser(username, email, "P4ssword"); | ||
|
||
RegisterRequest registerRequest = new() | ||
{ | ||
Email = "[email protected]", | ||
Password = "Passw0rd", | ||
Username = "unauthorized" | ||
}; | ||
ApplicationContext context = _factory.Services.CreateScope().ServiceProvider.GetRequiredService<ApplicationContext>(); | ||
|
||
await userService.CreateUser(registerRequest); | ||
User? user = await context.Users.FindAsync([userModel.Id]); | ||
|
||
context.Users.Update(user!); | ||
user!.Role = role; | ||
|
||
string jwt = (await _apiClient.LoginUser(registerRequest.Email, registerRequest.Password)).Token; | ||
await context.SaveChangesAsync(); | ||
|
||
string jwt = (await _apiClient.LoginUser(email, "P4ssword")).Token; | ||
|
||
Func<Task<LeaderboardViewModel>> act = async () => await _apiClient.Put<LeaderboardViewModel>($"/leaderboard/100/restore", new() | ||
{ | ||
|
@@ -421,7 +415,7 @@ public async Task RestoreLeaderboard_Unauthorized() | |
[Test] | ||
public async Task RestoreLeaderboard_NotFound() | ||
{ | ||
Func<Task<LeaderboardViewModel>> act = async () => await _apiClient.Put<LeaderboardViewModel>($"/leaderboard/100/restore", new() | ||
Func<Task<LeaderboardViewModel>> act = async () => await _apiClient.Put<LeaderboardViewModel>($"/leaderboard/{1e10}/restore", new() | ||
{ | ||
Jwt = _jwt | ||
}); | ||
|
@@ -436,8 +430,8 @@ public async Task RestoreLeaderboard_NotFound_WasNeverDeleted() | |
|
||
Leaderboard board = new() | ||
{ | ||
Name = "Super Mario World", | ||
Slug = "super-mario-world-non-deleted", | ||
Name = "Hyper Mario World", | ||
Slug = "hyper-mario-world-non-deleted", | ||
}; | ||
|
||
context.Leaderboards.Add(board); | ||
|
@@ -451,6 +445,5 @@ public async Task RestoreLeaderboard_NotFound_WasNeverDeleted() | |
|
||
await act.Should().ThrowAsync<RequestFailureException>() | ||
.Where(e => e.Response.StatusCode == HttpStatusCode.NotFound); | ||
// TODO: Don't know how to test for the response message. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters