Voeg leesbare slug toe aan Offering naast het GUID-ID
Continuous Integration / config (pull_request) Successful in 12s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / frontend-prepare (pull_request) Skipped
Continuous Integration / frontend-build (pull_request) Skipped
Continuous Integration / frontend-test (pull_request) Skipped
Continuous Integration / frontend-lint (pull_request) Skipped
Continuous Integration / backend-build (pull_request) Successful in 4m31s
Continuous Integration / vulnerability-scan (pull_request) Successful in 3m57s
Continuous Integration / backend-test (pull_request) Successful in 6m11s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 5m51s
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / config (pull_request) Successful in 12s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / frontend-prepare (pull_request) Skipped
Continuous Integration / frontend-build (pull_request) Skipped
Continuous Integration / frontend-test (pull_request) Skipped
Continuous Integration / frontend-lint (pull_request) Skipped
Continuous Integration / backend-build (pull_request) Successful in 4m31s
Continuous Integration / vulnerability-scan (pull_request) Successful in 3m57s
Continuous Integration / backend-test (pull_request) Successful in 6m11s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 5m51s
Continuous Integration / deploy-test (pull_request) Skipped
Het Offering-ID is een GUID en niet geschikt om aan gebruikers te tonen. Voeg een op de titel gebaseerde, unieke slug toe die via de public en admin API wordt meegegeven, zodat de frontend iets leesbaars kan tonen in plaats van het ruwe ID. Het ID blijft ongewijzigd de echte identifier. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,7 @@ public class OfferingsServiceTests
|
||||
private static Offering ExistingOffering(bool featured = false, int displayOrder = 0) => new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Slug = "existing",
|
||||
Title = "Existing",
|
||||
Description = "Description",
|
||||
Price = "€ 100",
|
||||
@@ -91,6 +92,57 @@ public class OfferingsServiceTests
|
||||
await _repo.DidNotReceive().BeginTransactionAsync();
|
||||
}
|
||||
|
||||
// --- Slug generation ---
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAsync_GeneratesSlugFromTitle()
|
||||
{
|
||||
_repo.GetMaxDisplayOrderAsync().Returns(-1);
|
||||
|
||||
var dto = await CreateSut().CreateAsync(CreateRequest(), Guid.NewGuid());
|
||||
|
||||
dto.Slug.Should().Be("title");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateAsync_AppendsSuffix_WhenSlugAlreadyTaken()
|
||||
{
|
||||
_repo.GetMaxDisplayOrderAsync().Returns(-1);
|
||||
_repo.ExistsBySlugAsync("title", null).Returns(true);
|
||||
_repo.ExistsBySlugAsync("title-2", null).Returns(true);
|
||||
_repo.ExistsBySlugAsync("title-3", null).Returns(false);
|
||||
|
||||
var dto = await CreateSut().CreateAsync(CreateRequest(), Guid.NewGuid());
|
||||
|
||||
dto.Slug.Should().Be("title-3");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_RegeneratesSlug_WhenTitleChanges()
|
||||
{
|
||||
var target = ExistingOffering();
|
||||
_repo.GetByIdAsync(target.Id).Returns(target);
|
||||
_repo.ExistsBySlugAsync("new-title", target.Id).Returns(false);
|
||||
|
||||
var request = new UpdateOfferingRequest("New Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact");
|
||||
var dto = await CreateSut().UpdateAsync(target.Id, request, Guid.NewGuid());
|
||||
|
||||
dto!.Slug.Should().Be("new-title");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_KeepsExistingSlug_WhenTitleUnchanged()
|
||||
{
|
||||
var target = ExistingOffering();
|
||||
_repo.GetByIdAsync(target.Id).Returns(target);
|
||||
|
||||
var request = new UpdateOfferingRequest(target.Title, "Description", "€ 100", "per month", ["Feature 1"], "Contact");
|
||||
var dto = await CreateSut().UpdateAsync(target.Id, request, Guid.NewGuid());
|
||||
|
||||
dto!.Slug.Should().Be("existing");
|
||||
await _repo.DidNotReceive().ExistsBySlugAsync(Arg.Any<string>(), Arg.Any<Guid?>());
|
||||
}
|
||||
|
||||
// --- UpdateAsync ---
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user