Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions docs/sdd/sdd-005-api-konvence.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Tvary API a klienta.
- Přihlášení nese cookie, nebo API token v hlavičce `Authorization: Bearer` (SDD-006). OpenAPI
dokument deklaruje schéma Bearer.
- Založení odpovídá 201 s hlavičkou `Location` na detail nového záznamu; u souboru a verze míří na
stažení obsahu, detail souboru není. Založení API tokenu odpovídá 201 bez `Location`, protože
token nemá detail. Upload, který nic neuloží, protože se obsah shoduje s aktuální verzí,
odpovídá 200. Komentář odpovídá 204 i na založení. Editace a smazání odpovídají 204.
stažení obsahu, detail souboru není. Založení záznamu, který nemá detail, odpovídá 201 bez
`Location`: API token a štítek. Upload, který nic neuloží, protože se obsah shoduje s aktuální
verzí, odpovídá 200. Komentář odpovídá 204 i na založení. Editace a smazání odpovídají 204.
- V těle jde hodnota výčtu jako název; číslo ani neznámý název se nepřijme (400). V query
stringu ji váže framework, který číslo bere.
- Každý výpis bere stránku, směr řazení, svůj řadicí klíč a hledaný text; k tomu zúžení své
Expand Down
2 changes: 1 addition & 1 deletion src/Api/EvilCase.Api/Controllers/LabelsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<ActionResult<LabelItem>> CreateLabel([FromServices] ILabelWrit

return result.Outcome switch
{
LabelCreateOutcome.Created => this.CreatedAtAction(nameof(this.ListLabels), routeValues: null, result.Label),
LabelCreateOutcome.Created => this.StatusCode(StatusCodes.Status201Created, result.Label),
LabelCreateOutcome.NameTaken => this.NameTakenProblem(),
_ => throw new UnreachableException(),
};
Expand Down
36 changes: 36 additions & 0 deletions src/Tests/EvilCase.Tests/Hosting/CreateLocationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
using System.Net.Http.Json;
using EvilBrains.EvilCase.Api.Contract.Cases;
using EvilBrains.EvilCase.Api.Contract.Contacts;
using EvilBrains.EvilCase.Api.Contract.Labels;
using EvilBrains.EvilCase.Business.Cases;
using EvilBrains.EvilCase.Business.Contacts;
using EvilBrains.EvilCase.Business.Labels;
using EvilBrains.EvilCase.Domain.Cases;
using EvilBrains.EvilCase.Domain.Contacts;
using EvilBrains.EvilCase.Domain.Labels;
using Microsoft.Extensions.DependencyInjection;

namespace EvilBrains.EvilCase.Tests.Hosting;
Expand Down Expand Up @@ -56,6 +59,21 @@ public void SetUp()
Name = call.Arg<ContactEditRequest>().Name,
});
services.AddSingleton(contactWriter);

var labelWriter = Substitute.For<ILabelWriter>();
labelWriter
.CreateLabel(Arg.Any<LabelEditRequest>(), Arg.Any<CancellationToken>())
.Returns(static call => new LabelCreateResult
{
Outcome = LabelCreateOutcome.Created,
Label = new LabelItem
{
LabelId = Guid.CreateVersion7(),
Name = call.Arg<LabelEditRequest>().Name,
Color = call.Arg<LabelEditRequest>().Color,
},
});
services.AddSingleton(labelWriter);
});
this.client = this.host.CreateClient();
}
Expand Down Expand Up @@ -108,4 +126,22 @@ public async Task AFiledContactCarriesTheLocationOfItsDetail()
"the Location names the detail route of the contact that was filed");
}
}

[Test]
public async Task ACreatedLabelCarriesNoLocation()
{
using var request = new HttpRequestMessage(HttpMethod.Post, new Uri("/api/labels", UriKind.Relative))
{
Headers = { Authorization = TestTokens.BearerFrom(this.host) },
Content = JsonContent.Create(new LabelEditRequest { Name = "Nový štítek", Color = LabelColor.Blue }),
};

using var response = await this.client.SendAsync(request);

using (Assert.EnterMultipleScope())
{
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created));
Assert.That(response.Headers.Location, Is.Null, "a label has no detail route for a Location to name");
}
}
}
Loading