Skip to content

Commit

Permalink
Update action to comply with new specs (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
zysim authored Feb 1, 2025
1 parent fd47757 commit 57de0d8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
46 changes: 44 additions & 2 deletions LeaderboardBackend.Test/Categories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,52 @@ public async Task OneTimeSetUp()
public void OneTimeTearDown() => _factory.Dispose();

[Test]
public async Task GetCategory_NotFound() =>
public async Task GetCategory_OK()
{
IServiceScope scope = _factory.Services.CreateScope();
ApplicationContext context = scope.ServiceProvider.GetRequiredService<ApplicationContext>();

Category created = new()
{
Name = "get ok",
Slug = "getcategory-ok",
LeaderboardId = _createdLeaderboard.Id,
SortDirection = SortDirection.Ascending,
Type = RunType.Score,
};

context.Add(created);
await context.SaveChangesAsync();
created.Id.Should().NotBe(default);

await _apiClient.Awaiting(
a => a.Get<CategoryViewModel>(
$"api/category/{created.Id}",
new() { }
)
).Should()
.NotThrowAsync()
.WithResult(new()
{
Id = created.Id,
Name = "get ok",
Slug = "getcategory-ok",
Info = "",
Type = RunType.Score,
SortDirection = SortDirection.Ascending,
LeaderboardId = _createdLeaderboard.Id,
CreatedAt = _clock.GetCurrentInstant(),
UpdatedAt = null,
DeletedAt = null,
});
}

[TestCase("NotANumber")]
[TestCase("69")]
public async Task GetCategory_NotFound(object id) =>
await _apiClient.Awaiting(
a => a.Get<CategoryViewModel>(
$"/api/category/69",
$"/api/category/{id}",
new() { Jwt = _jwt }
)
).Should()
Expand Down
2 changes: 1 addition & 1 deletion LeaderboardBackend/Controllers/CategoriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace LeaderboardBackend.Controllers;
public class CategoriesController(ICategoryService categoryService) : ApiController
{
[AllowAnonymous]
[HttpGet("api/category/{id}")]
[HttpGet("api/category/{id:long}")]
[SwaggerOperation("Gets a Category by its ID.", OperationId = "getCategory")]
[SwaggerResponse(200)]
[SwaggerResponse(404)]
Expand Down
5 changes: 5 additions & 0 deletions LeaderboardBackend/Models/ViewModels/CategoryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ public record CategoryViewModel
/// <example>Video proof is required.</example>
public required string? Info { get; set; }

/// <inheritdoc cref="Category.Type" />
public required RunType Type { get; set; }

/// <inheritdoc cref="Category.SortDirection" />
public required SortDirection SortDirection { get; set; }

/// <inheritdoc cref="Category.LeaderboardId" />
public required long LeaderboardId { get; set; }

/// <inheritdoc cref="Category.CreatedAt" />
public required Instant CreatedAt { get; set; }

Expand All @@ -53,6 +57,7 @@ public record CategoryViewModel
Info = category.Info,
SortDirection = category.SortDirection,
Type = category.Type,
LeaderboardId = category.LeaderboardId,
CreatedAt = category.CreatedAt,
UpdatedAt = category.UpdatedAt,
DeletedAt = category.DeletedAt
Expand Down
5 changes: 5 additions & 0 deletions LeaderboardBackend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,7 @@
"deletedAt",
"id",
"info",
"leaderboardId",
"name",
"slug",
"sortDirection",
Expand Down Expand Up @@ -1415,6 +1416,10 @@
"sortDirection": {
"$ref": "#/components/schemas/SortDirection"
},
"leaderboardId": {
"type": "integer",
"format": "int64"
},
"createdAt": {
"type": "string",
"format": "date-time",
Expand Down

0 comments on commit 57de0d8

Please sign in to comment.