Skip to content

Commit

Permalink
Add Test for Filtered Index (#246)
Browse files Browse the repository at this point in the history
* Make sure deleted boards don't consume slugs.

* Use a different game name/slug.

* Ensure that Leaderboard is created and returned.
  • Loading branch information
TheTedder committed Sep 23, 2024
1 parent 4021aff commit 5166337
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions LeaderboardBackend.Test/Leaderboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,53 @@ public async Task GetLeaderboards_Deleted_BySlug_NotFound()
{
Name = "Should 404",
Slug = "should-404",
UpdatedAt = _clock.GetCurrentInstant() + Duration.FromMinutes(1),
DeletedAt = _clock.GetCurrentInstant() + Duration.FromMinutes(1),
UpdatedAt = _clock.GetCurrentInstant() - Duration.FromMinutes(1),
DeletedAt = _clock.GetCurrentInstant() - Duration.FromMinutes(1),
};

context.Leaderboards.Add(board);
await context.SaveChangesAsync();
_clock.AdvanceMinutes(2);

Func<Task<LeaderboardViewModel>> act = async () => await _apiClient.Get<LeaderboardViewModel>($"/api/leaderboard?slug={board.Slug}", new());
await act.Should().ThrowAsync<RequestFailureException>().Where(e => e.Response.StatusCode == HttpStatusCode.NotFound);
}

[Test]
public async Task DeletedBoardsDontConsumeSlugs()
{
ApplicationContext context = _factory.Services.CreateScope().ServiceProvider.GetRequiredService<ApplicationContext>();

Leaderboard deletedBoard = new()
{
Name = "Super Mario World (OLD)",
Slug = "super-mario-world",
DeletedAt = _clock.GetCurrentInstant()
};

context.Leaderboards.Add(deletedBoard);
await context.SaveChangesAsync();
deletedBoard.Id.Should().NotBe(default);

CreateLeaderboardRequest lbRequest = new()
{
Name = "Super Mario World",
Info = "new and improved",
Slug = "super-mario-world"
};

#pragma warning disable IDE0008 // Use explicit type
var res = await FluentActions.Awaiting(() => _apiClient.Post<LeaderboardViewModel>("/leaderboards/create", new()
{
Body = lbRequest,
Jwt = _jwt
})).Should().NotThrowAsync();
#pragma warning restore IDE0008 // Use explicit type

Leaderboard? created = await context.Leaderboards.FindAsync(res.Subject.Id);
created.Should().NotBeNull().And.BeEquivalentTo(lbRequest);
created!.CreatedAt.Should().Be(_clock.GetCurrentInstant());
}

private static string ListToQueryString<T>(IEnumerable<T> list, string key)
{
IEnumerable<string> queryList = list.Select(l => $"{key}={l}");
Expand Down

0 comments on commit 5166337

Please sign in to comment.