Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test for Filtered Index #246

Merged
merged 3 commits into from
Sep 23, 2024
Merged
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
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);
TheTedder marked this conversation as resolved.
Show resolved Hide resolved

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