- Extend /api/library/browse to episodes, music videos, songs, other videos,
images and remote streams (new LibraryBrowseMediaType values + hydrators);
add optional Subtitle to LibraryBrowseItemResponseModel for leaf-item context
- Add GET /api/search: grouped per-kind results reusing the browse query/shape;
empty query -> 422
- Add DELETE /api/media-items: body { ids }, empty -> 422, success -> 204
- Tests: SearchController, MediaItemsController, security + OpenAPI contract entries
- Regenerate openapi v1.json + web v1.d.ts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System.Reflection;
|
|
using ErsatzTV.Controllers.Api;
|
|
using ErsatzTV.Controllers.Api.Requests;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Application.Maintenance;
|
|
using LanguageExt;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
using static LanguageExt.Prelude;
|
|
|
|
namespace ErsatzTV.Tests.Controllers;
|
|
|
|
[TestFixture]
|
|
public class MediaItemsControllerTests
|
|
{
|
|
private MediaItemsController _controller = null!;
|
|
private IMediator _mediator = null!;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_mediator = Substitute.For<IMediator>();
|
|
_controller = new MediaItemsController(_mediator);
|
|
}
|
|
|
|
[Test]
|
|
public void Controller_Should_Expose_Delete_Route_With_Stable_Operation_Name()
|
|
{
|
|
MethodInfo action = typeof(MediaItemsController).GetMethod(nameof(MediaItemsController.Delete))
|
|
?? throw new AssertionException($"Missing action {nameof(MediaItemsController.Delete)}");
|
|
|
|
var attribute = action.GetCustomAttributes<HttpDeleteAttribute>().Single();
|
|
attribute.Template.ShouldBe("/api/media-items");
|
|
attribute.Name.ShouldBe("DeleteMediaItems");
|
|
}
|
|
|
|
[Test]
|
|
public async Task Delete_Should_Return_422_For_Empty_Ids()
|
|
{
|
|
IActionResult result = await _controller.Delete(new DeleteMediaItemsRequest([]), CancellationToken.None);
|
|
|
|
var unprocessable = result.ShouldBeOfType<UnprocessableEntityObjectResult>();
|
|
unprocessable.StatusCode.ShouldBe(422);
|
|
await _mediator.DidNotReceive().Send(Arg.Any<DeleteItemsFromDatabase>(), Arg.Any<CancellationToken>());
|
|
}
|
|
|
|
[Test]
|
|
public async Task Delete_Should_Return_204_On_Success()
|
|
{
|
|
_mediator.Send(Arg.Any<DeleteItemsFromDatabase>(), Arg.Any<CancellationToken>())
|
|
.Returns(Right<BaseError, LanguageExt.Unit>(LanguageExt.Unit.Default));
|
|
|
|
IActionResult result = await _controller.Delete(
|
|
new DeleteMediaItemsRequest([1, 2, 3]),
|
|
CancellationToken.None);
|
|
|
|
result.ShouldBeOfType<NoContentResult>();
|
|
await _mediator.Received(1).Send(
|
|
Arg.Is<DeleteItemsFromDatabase>(c => c.MediaItemIds.SequenceEqual(new[] { 1, 2, 3 })),
|
|
Arg.Any<CancellationToken>());
|
|
}
|
|
}
|