From d4bf0af29c8915423c27c5df1c7ca7e6cb4b5c91 Mon Sep 17 00:00:00 2001 From: Ted Wollman <25165500+TheTedder@users.noreply.github.com> Date: Sun, 22 Sep 2024 17:34:24 -0400 Subject: [PATCH 1/3] Make sure deleted boards don't consume slugs. --- LeaderboardBackend.Test/Leaderboards.cs | 36 ++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/LeaderboardBackend.Test/Leaderboards.cs b/LeaderboardBackend.Test/Leaderboards.cs index dbb288fd..1cd67b6a 100644 --- a/LeaderboardBackend.Test/Leaderboards.cs +++ b/LeaderboardBackend.Test/Leaderboards.cs @@ -165,18 +165,48 @@ 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> act = async () => await _apiClient.Get($"/api/leaderboard?slug={board.Slug}", new()); await act.Should().ThrowAsync().Where(e => e.Response.StatusCode == HttpStatusCode.NotFound); } + [Test] + public async Task DeletedBoardsDontConsumeSlugs() + { + ApplicationContext context = _factory.Services.CreateScope().ServiceProvider.GetRequiredService(); + + Leaderboard deletedBoard = new() + { + Name = "Super Mario 64 (OLD)", + Slug = "super-mario-64", + DeletedAt = _clock.GetCurrentInstant() + }; + + context.Leaderboards.Add(deletedBoard); + await context.SaveChangesAsync(); + deletedBoard.Id.Should().NotBe(default); + context.ChangeTracker.Clear(); + Leaderboard? retrieved = await context.Leaderboards.FindAsync(deletedBoard.Id); + retrieved.Should().NotBeNull(); + + await FluentActions.Awaiting(() => _apiClient.Post("/leaderboards/create", new() + { + Body = new CreateLeaderboardRequest() + { + Name = "Super Mario 64", + Info = "new and improved", + Slug = "super-mario-64" + }, + Jwt = _jwt + })).Should().NotThrowAsync(); + } + private static string ListToQueryString(IEnumerable list, string key) { IEnumerable queryList = list.Select(l => $"{key}={l}"); From 279e66cc0997a5a22c2a9a1e74c80b4c8617d298 Mon Sep 17 00:00:00 2001 From: Ted Wollman <25165500+TheTedder@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:21:35 -0400 Subject: [PATCH 2/3] Use a different game name/slug. --- LeaderboardBackend.Test/Leaderboards.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LeaderboardBackend.Test/Leaderboards.cs b/LeaderboardBackend.Test/Leaderboards.cs index 1cd67b6a..a0631ccd 100644 --- a/LeaderboardBackend.Test/Leaderboards.cs +++ b/LeaderboardBackend.Test/Leaderboards.cs @@ -183,8 +183,8 @@ public async Task DeletedBoardsDontConsumeSlugs() Leaderboard deletedBoard = new() { - Name = "Super Mario 64 (OLD)", - Slug = "super-mario-64", + Name = "Super Mario World (OLD)", + Slug = "super-mario-world", DeletedAt = _clock.GetCurrentInstant() }; @@ -199,9 +199,9 @@ public async Task DeletedBoardsDontConsumeSlugs() { Body = new CreateLeaderboardRequest() { - Name = "Super Mario 64", + Name = "Super Mario World", Info = "new and improved", - Slug = "super-mario-64" + Slug = "super-mario-world" }, Jwt = _jwt })).Should().NotThrowAsync(); From 35a1e525f8d50576f7899bb010ab1abf55496ed2 Mon Sep 17 00:00:00 2001 From: Ted Wollman <25165500+TheTedder@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:41:37 -0400 Subject: [PATCH 3/3] Ensure that Leaderboard is created and returned. --- LeaderboardBackend.Test/Leaderboards.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/LeaderboardBackend.Test/Leaderboards.cs b/LeaderboardBackend.Test/Leaderboards.cs index a0631ccd..be4e9075 100644 --- a/LeaderboardBackend.Test/Leaderboards.cs +++ b/LeaderboardBackend.Test/Leaderboards.cs @@ -191,20 +191,25 @@ public async Task DeletedBoardsDontConsumeSlugs() context.Leaderboards.Add(deletedBoard); await context.SaveChangesAsync(); deletedBoard.Id.Should().NotBe(default); - context.ChangeTracker.Clear(); - Leaderboard? retrieved = await context.Leaderboards.FindAsync(deletedBoard.Id); - retrieved.Should().NotBeNull(); - await FluentActions.Awaiting(() => _apiClient.Post("/leaderboards/create", new() + CreateLeaderboardRequest lbRequest = new() { - Body = new CreateLeaderboardRequest() - { - Name = "Super Mario World", - Info = "new and improved", - Slug = "super-mario-world" - }, + 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("/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(IEnumerable list, string key)