Aanbod: RESTful routes zonder /admin, één OfferingDto en herordenen via PUT /offerings/order
Admin en bezoeker gebruiken dezelfde resource; alleen GET is anoniem, de rest vereist AdminOnly. OfferingAdminDto vervalt (displayOrder zit nu in OfferingDto), move-up/move-down zijn vervangen door de order-route die een onbekende of onvolledige lijst met 400 afwijst. De admin-frontend en alle tests zijn mee aangepast. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,10 +24,7 @@ public class OfferingsControllerTests
|
||||
return new OfferingsController(_service) { ControllerContext = new ControllerContext { HttpContext = httpContext } };
|
||||
}
|
||||
|
||||
private static OfferingDto PublicDto() => new(
|
||||
Guid.NewGuid().ToString(), "title", "Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact", false);
|
||||
|
||||
private static OfferingAdminDto AdminDto(int displayOrder = 0) => new(
|
||||
private static OfferingDto Dto(int displayOrder = 0) => new(
|
||||
Guid.NewGuid().ToString(), "title", "Title", "Description", "€ 100", "per month", ["Feature 1"], "Contact", false, displayOrder);
|
||||
|
||||
private static CreateOfferingRequest CreateRequest() => new(
|
||||
@@ -41,35 +38,23 @@ public class OfferingsControllerTests
|
||||
[Fact]
|
||||
public async Task GetOfferings_Returns200_WithList()
|
||||
{
|
||||
_service.GetPublicOfferingsAsync().Returns([PublicDto()]);
|
||||
_service.GetOfferingsAsync().Returns([Dto()]);
|
||||
|
||||
var result = await CreateSut().GetOfferings();
|
||||
|
||||
result.Should().BeOfType<OkObjectResult>().Which.StatusCode.Should().Be(200);
|
||||
}
|
||||
|
||||
// --- GetAllForAdmin ---
|
||||
|
||||
[Fact]
|
||||
public async Task GetAllForAdmin_Returns200_WithList()
|
||||
{
|
||||
_service.GetAllForAdminAsync().Returns([AdminDto()]);
|
||||
|
||||
var result = await CreateSut().GetAllForAdmin();
|
||||
|
||||
result.Should().BeOfType<OkObjectResult>().Which.StatusCode.Should().Be(200);
|
||||
}
|
||||
|
||||
// --- Create ---
|
||||
|
||||
[Fact]
|
||||
public async Task Create_Returns201Created()
|
||||
{
|
||||
_service.CreateAsync(Arg.Any<CreateOfferingRequest>(), Arg.Any<Guid>()).Returns(AdminDto());
|
||||
_service.CreateAsync(Arg.Any<CreateOfferingRequest>(), Arg.Any<Guid>()).Returns(Dto());
|
||||
|
||||
var result = await CreateSut().Create(CreateRequest());
|
||||
|
||||
result.Should().BeOfType<CreatedAtActionResult>().Which.StatusCode.Should().Be(201);
|
||||
result.Should().BeOfType<CreatedResult>().Which.StatusCode.Should().Be(201);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -88,7 +73,7 @@ public class OfferingsControllerTests
|
||||
[Fact]
|
||||
public async Task Update_Returns200_WhenFound()
|
||||
{
|
||||
_service.UpdateAsync(Arg.Any<Guid>(), Arg.Any<UpdateOfferingRequest>(), Arg.Any<Guid>()).Returns(AdminDto());
|
||||
_service.UpdateAsync(Arg.Any<Guid>(), Arg.Any<UpdateOfferingRequest>(), Arg.Any<Guid>()).Returns(Dto());
|
||||
|
||||
var result = await CreateSut().Update(Guid.NewGuid(), UpdateRequest());
|
||||
|
||||
@@ -99,7 +84,7 @@ public class OfferingsControllerTests
|
||||
public async Task Update_Returns404_WhenNotFound()
|
||||
{
|
||||
_service.UpdateAsync(Arg.Any<Guid>(), Arg.Any<UpdateOfferingRequest>(), Arg.Any<Guid>())
|
||||
.Returns((OfferingAdminDto?)null);
|
||||
.Returns((OfferingDto?)null);
|
||||
|
||||
var result = await CreateSut().Update(Guid.NewGuid(), UpdateRequest());
|
||||
|
||||
@@ -139,29 +124,4 @@ public class OfferingsControllerTests
|
||||
result.Should().BeOfType<NotFoundResult>();
|
||||
}
|
||||
|
||||
// --- Reorder / MoveUp / MoveDown ---
|
||||
|
||||
[Fact]
|
||||
public async Task Reorder_Returns204()
|
||||
{
|
||||
var result = await CreateSut().Reorder(new ReorderOfferingsRequest([Guid.NewGuid()]));
|
||||
|
||||
result.Should().BeOfType<NoContentResult>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveUp_Returns204()
|
||||
{
|
||||
var result = await CreateSut().MoveUp(Guid.NewGuid());
|
||||
|
||||
result.Should().BeOfType<NoContentResult>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MoveDown_Returns204()
|
||||
{
|
||||
var result = await CreateSut().MoveDown(Guid.NewGuid());
|
||||
|
||||
result.Should().BeOfType<NoContentResult>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user