Add GET /api/logs (thin wrapper over GetRecentLogEntries; paged, filtered,
clamped pageSize like LibraryBrowseController) and GET /api/troubleshoot/info
(wraps GetTroubleshootingInfo; General section serialized to the same JSON
shape the legacy Blazor Troubleshooting page renders, plus per-platform
capability dumps). Also adds [EndpointGroupName("general")] to the existing
troubleshoot playback endpoints so they surface in the OpenAPI spec (#158
item 3).
90 lines
2.9 KiB
C#
90 lines
2.9 KiB
C#
using System.Reflection;
|
|
using ErsatzTV.Application.Logs;
|
|
using ErsatzTV.Controllers.Api;
|
|
using ErsatzTV.Core.Api.Logs;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Serilog.Events;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Controllers;
|
|
|
|
[TestFixture]
|
|
public class LogsControllerTests
|
|
{
|
|
private LogsController _controller = null!;
|
|
private IMediator _mediator = null!;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_mediator = Substitute.For<IMediator>();
|
|
_controller = new LogsController(_mediator);
|
|
}
|
|
|
|
[Test]
|
|
public void Controller_Should_Expose_Idiomatic_Rest_Route()
|
|
{
|
|
MethodInfo action = typeof(LogsController).GetMethod(nameof(LogsController.GetLogs))
|
|
?? throw new AssertionException("Missing action GetLogs");
|
|
|
|
HttpMethodAttribute attribute = action.GetCustomAttributes<HttpMethodAttribute>(inherit: true).Single();
|
|
attribute.HttpMethods.ShouldContain("GET");
|
|
attribute.Template.ShouldBe("/api/logs");
|
|
attribute.Name.ShouldBe("GetLogs");
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetLogs_Should_Clamp_Paging_And_Send_Query()
|
|
{
|
|
_mediator.Send(Arg.Any<GetRecentLogEntries>(), Arg.Any<CancellationToken>())
|
|
.Returns(new PagedLogEntriesViewModel(0, []));
|
|
|
|
await _controller.GetLogs(-1, 500, "boom", CancellationToken.None);
|
|
|
|
await _mediator.Received(1).Send(
|
|
Arg.Is<GetRecentLogEntries>(q =>
|
|
q.PageNum == 0 &&
|
|
q.PageSize == 100 &&
|
|
q.Filter == "boom"),
|
|
Arg.Any<CancellationToken>());
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetLogs_Should_Map_Entries_To_Response_Model()
|
|
{
|
|
var entries = new List<LogEntryViewModel>
|
|
{
|
|
new(DateTimeOffset.UnixEpoch, LogEventLevel.Warning, "uh oh"),
|
|
new(DateTimeOffset.UnixEpoch.AddMinutes(1), LogEventLevel.Information, "all good")
|
|
};
|
|
_mediator.Send(Arg.Any<GetRecentLogEntries>(), Arg.Any<CancellationToken>())
|
|
.Returns(new PagedLogEntriesViewModel(2, entries));
|
|
|
|
PagedLogEntriesResponseModel result = await _controller.GetLogs(
|
|
cancellationToken: CancellationToken.None);
|
|
|
|
result.TotalCount.ShouldBe(2);
|
|
result.Page.ShouldBe(
|
|
[
|
|
new LogEntryResponseModel(DateTimeOffset.UnixEpoch, "Warning", "uh oh"),
|
|
new LogEntryResponseModel(DateTimeOffset.UnixEpoch.AddMinutes(1), "Information", "all good")
|
|
]);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetLogs_Should_Return_Empty_Page_When_None_Exist()
|
|
{
|
|
_mediator.Send(Arg.Any<GetRecentLogEntries>(), Arg.Any<CancellationToken>())
|
|
.Returns(new PagedLogEntriesViewModel(0, []));
|
|
|
|
PagedLogEntriesResponseModel result = await _controller.GetLogs(
|
|
cancellationToken: CancellationToken.None);
|
|
|
|
result.TotalCount.ShouldBe(0);
|
|
result.Page.ShouldBeEmpty();
|
|
}
|
|
}
|