Mint ChannelDetailResponseModel (faithful detail DTO exposing the raw editable field set the channel editor reads: raw FFmpegProfileId/WatermarkId/FallbackFillerId ids, the mode enums, logo, playoutCount, id) and route GetById/Create/Update through it, replacing the lean list ChannelResponseModel that resolved the profile to a name and dropped the editable ids (a functional regression for draftFromChannel). The lean ChannelResponseModel stays unchanged for GET /api/channels. webEncodedName dropped (SPA never reads it). Logo is mirrored as a Core ChannelLogoResponseModel since the Application ArtworkContentTypeModel can't be referenced from Core. Repoint the hand-written SPA client aliases now that the VMs are gone from the schema: Channel -> ChannelDetailResponseModel, MediaCollection/SmartCollection -> *ResponseModel, ProgramSchedule -> ProgramScheduleResponseModel. Fix #288 honest-nullability test fallout in search.test.ts (null -> [] for now-non-null id arrays). Include the already-on-disk playouts.ts WithDayNames removal and regenerate v1.json + v1.d.ts + endpoint-index.md (authoritative final regen; the reset endpoint's {channelNumber}->{id} re-key surfaces in the generated docs and the OpenApi error-contract test). Refs #288 #197 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
324 lines
16 KiB
C#
324 lines
16 KiB
C#
using System.Text.Json;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Controllers;
|
|
|
|
[TestFixture]
|
|
public class OpenApiErrorResponseContractTests
|
|
{
|
|
[Test]
|
|
public void Static_OpenApi_Should_Document_Schedule_Item_Discriminator_As_String_Enum()
|
|
{
|
|
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(FindOpenApiDocument()));
|
|
|
|
JsonElement playoutMode = document.RootElement
|
|
.GetProperty("components")
|
|
.GetProperty("schemas")
|
|
.GetProperty("PlayoutMode");
|
|
|
|
playoutMode.GetProperty("type").GetString().ShouldBe("string");
|
|
playoutMode.GetProperty("enum").EnumerateArray()
|
|
.Select(e => e.GetString())
|
|
.ShouldContain("One");
|
|
}
|
|
|
|
[Test]
|
|
public void Static_OpenApi_Should_Document_Channel_List_Management_Fields()
|
|
{
|
|
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(FindOpenApiDocument()));
|
|
|
|
JsonElement schema = document.RootElement
|
|
.GetProperty("components")
|
|
.GetProperty("schemas")
|
|
.GetProperty("ChannelResponseModel")
|
|
.GetProperty("properties");
|
|
|
|
schema.TryGetProperty("group", out _).ShouldBeTrue();
|
|
schema.TryGetProperty("isEnabled", out _).ShouldBeTrue();
|
|
schema.TryGetProperty("showInEpg", out _).ShouldBeTrue();
|
|
schema.TryGetProperty("sortNumber", out _).ShouldBeTrue();
|
|
schema.TryGetProperty("categories", out _).ShouldBeTrue();
|
|
}
|
|
|
|
[Test]
|
|
public void Static_OpenApi_Should_Document_Channel_State_Response()
|
|
{
|
|
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(FindOpenApiDocument()));
|
|
|
|
JsonElement getState = document.RootElement
|
|
.GetProperty("paths")
|
|
.GetProperty("/api/channels/state")
|
|
.GetProperty("get");
|
|
|
|
JsonElement schema = getState
|
|
.GetProperty("responses")
|
|
.GetProperty("200")
|
|
.GetProperty("content")
|
|
.GetProperty("application/json")
|
|
.GetProperty("schema");
|
|
|
|
schema.GetProperty("type").GetString().ShouldBe("array");
|
|
schema.GetProperty("items").GetProperty("$ref").GetString()
|
|
.ShouldBe("#/components/schemas/ChannelStateResponseModel");
|
|
|
|
JsonElement stateProperties = document.RootElement
|
|
.GetProperty("components")
|
|
.GetProperty("schemas")
|
|
.GetProperty("ChannelStateResponseModel")
|
|
.GetProperty("properties");
|
|
|
|
stateProperties.TryGetProperty("channelId", out _).ShouldBeTrue();
|
|
stateProperties.TryGetProperty("channelNumber", out _).ShouldBeTrue();
|
|
stateProperties.TryGetProperty("onAir", out _).ShouldBeTrue();
|
|
stateProperties.TryGetProperty("nowPlaying", out JsonElement nowPlaying).ShouldBeTrue();
|
|
|
|
JsonElement nowPlayingOneOf = nowPlaying.GetProperty("oneOf");
|
|
nowPlayingOneOf.EnumerateArray().Count().ShouldBe(2);
|
|
nowPlayingOneOf.EnumerateArray()
|
|
.Any(s => s.TryGetProperty("type", out JsonElement type) && type.GetString() == "null")
|
|
.ShouldBeTrue();
|
|
nowPlayingOneOf.EnumerateArray()
|
|
.Any(s => s.TryGetProperty("$ref", out JsonElement schemaRef) &&
|
|
schemaRef.GetString() == "#/components/schemas/ChannelNowPlayingResponseModel")
|
|
.ShouldBeTrue();
|
|
|
|
JsonElement nowPlayingProperties = document.RootElement
|
|
.GetProperty("components")
|
|
.GetProperty("schemas")
|
|
.GetProperty("ChannelNowPlayingResponseModel")
|
|
.GetProperty("properties");
|
|
|
|
nowPlayingProperties.TryGetProperty("title", out _).ShouldBeTrue();
|
|
nowPlayingProperties.TryGetProperty("startUtc", out JsonElement startUtc).ShouldBeTrue();
|
|
nowPlayingProperties.TryGetProperty("finishUtc", out JsonElement finishUtc).ShouldBeTrue();
|
|
|
|
startUtc.GetProperty("type").GetString().ShouldBe("string");
|
|
startUtc.GetProperty("format").GetString().ShouldBe("date-time");
|
|
finishUtc.GetProperty("type").GetString().ShouldBe("string");
|
|
finishUtc.GetProperty("format").GetString().ShouldBe("date-time");
|
|
}
|
|
|
|
[TestCase("/api/channels/{id}", "get", "404")]
|
|
[TestCase("/api/channels", "post", "404")]
|
|
[TestCase("/api/channels", "post", "422")]
|
|
[TestCase("/api/channels/from-lineup", "post", "404")]
|
|
[TestCase("/api/channels/from-lineup", "post", "422")]
|
|
[TestCase("/api/channels/{id}", "put", "404")]
|
|
[TestCase("/api/channels/{id}", "put", "422")]
|
|
[TestCase("/api/channels/{id}", "delete", "404")]
|
|
[TestCase("/api/channels/{id}", "delete", "422")]
|
|
[TestCase("/api/channels/bulk/renumber", "post", "404")]
|
|
[TestCase("/api/channels/bulk/renumber", "post", "422")]
|
|
[TestCase("/api/channels/bulk/group", "post", "404")]
|
|
[TestCase("/api/channels/bulk/group", "post", "422")]
|
|
[TestCase("/api/channels/bulk/delete", "post", "404")]
|
|
[TestCase("/api/channels/bulk/delete", "post", "422")]
|
|
[TestCase("/api/channels/{id}/playout/reset", "post", "404")]
|
|
[TestCase("/api/channels/{id}/playout/reset", "post", "409")]
|
|
[TestCase("/api/channel-templates/default", "get", "404")]
|
|
[TestCase("/api/channel-templates/default/{id}", "put", "404")]
|
|
[TestCase("/api/channel-templates/default/{id}", "put", "422")]
|
|
[TestCase("/api/channel-templates/{id}", "get", "404")]
|
|
[TestCase("/api/channel-templates", "post", "404")]
|
|
[TestCase("/api/channel-templates", "post", "422")]
|
|
[TestCase("/api/channel-templates/{id}", "put", "404")]
|
|
[TestCase("/api/channel-templates/{id}", "put", "422")]
|
|
[TestCase("/api/channel-templates/{id}", "delete", "404")]
|
|
[TestCase("/api/channel-templates/{id}", "delete", "422")]
|
|
[TestCase("/api/collections/{id}", "get", "404")]
|
|
[TestCase("/api/collections/{id}/items", "get", "404")]
|
|
[TestCase("/api/collections", "post", "404")]
|
|
[TestCase("/api/collections", "post", "422")]
|
|
[TestCase("/api/collections/{id}", "put", "404")]
|
|
[TestCase("/api/collections/{id}", "put", "422")]
|
|
[TestCase("/api/collections/{id}", "delete", "404")]
|
|
[TestCase("/api/collections/{id}", "delete", "422")]
|
|
[TestCase("/api/collections/{id}/items", "post", "404")]
|
|
[TestCase("/api/collections/{id}/items", "post", "422")]
|
|
[TestCase("/api/collections/{id}/items/{mediaItemId}", "delete", "404")]
|
|
[TestCase("/api/collections/{id}/items/{mediaItemId}", "delete", "422")]
|
|
[TestCase("/api/smart-collections/{id}", "get", "404")]
|
|
[TestCase("/api/smart-collections", "post", "404")]
|
|
[TestCase("/api/smart-collections", "post", "422")]
|
|
[TestCase("/api/smart-collections/{id}", "put", "404")]
|
|
[TestCase("/api/smart-collections/{id}", "put", "422")]
|
|
[TestCase("/api/smart-collections/{id}", "delete", "404")]
|
|
[TestCase("/api/smart-collections/{id}", "delete", "422")]
|
|
[TestCase("/api/multi-collections/{id}", "get", "404")]
|
|
[TestCase("/api/multi-collections", "post", "404")]
|
|
[TestCase("/api/multi-collections", "post", "422")]
|
|
[TestCase("/api/multi-collections/{id}", "put", "404")]
|
|
[TestCase("/api/multi-collections/{id}", "put", "422")]
|
|
[TestCase("/api/multi-collections/{id}", "delete", "404")]
|
|
[TestCase("/api/multi-collections/{id}", "delete", "422")]
|
|
[TestCase("/api/playlists/groups", "post", "422")]
|
|
[TestCase("/api/playlists/groups/{id}", "put", "404")]
|
|
[TestCase("/api/playlists/groups/{id}", "put", "422")]
|
|
[TestCase("/api/playlists/groups/{id}", "delete", "404")]
|
|
[TestCase("/api/playlists/groups/{id}", "delete", "422")]
|
|
[TestCase("/api/playlists/{id}", "get", "404")]
|
|
[TestCase("/api/playlists/{id}/items", "get", "404")]
|
|
[TestCase("/api/playlists", "post", "422")]
|
|
[TestCase("/api/playlists/{id}", "put", "404")]
|
|
[TestCase("/api/playlists/{id}", "put", "422")]
|
|
[TestCase("/api/playlists/{id}", "delete", "404")]
|
|
[TestCase("/api/playlists/{id}", "delete", "422")]
|
|
[TestCase("/api/playlists/preview", "post", "422")]
|
|
[TestCase("/api/rerun-collections/{id}", "get", "404")]
|
|
[TestCase("/api/rerun-collections", "post", "404")]
|
|
[TestCase("/api/rerun-collections", "post", "422")]
|
|
[TestCase("/api/rerun-collections/{id}", "put", "404")]
|
|
[TestCase("/api/rerun-collections/{id}", "put", "422")]
|
|
[TestCase("/api/rerun-collections/{id}", "delete", "404")]
|
|
[TestCase("/api/rerun-collections/{id}", "delete", "422")]
|
|
[TestCase("/api/schedules/{id}", "get", "404")]
|
|
[TestCase("/api/schedules", "post", "404")]
|
|
[TestCase("/api/schedules", "post", "422")]
|
|
[TestCase("/api/schedules/{id}", "put", "404")]
|
|
[TestCase("/api/schedules/{id}", "put", "422")]
|
|
[TestCase("/api/schedules/{id}", "delete", "404")]
|
|
[TestCase("/api/schedules/{id}", "delete", "422")]
|
|
[TestCase("/api/schedules/{id}/items", "get", "404")]
|
|
[TestCase("/api/schedules/{id}/items", "post", "404")]
|
|
[TestCase("/api/schedules/{id}/items", "post", "422")]
|
|
[TestCase("/api/schedules/{id}/items", "put", "404")]
|
|
[TestCase("/api/schedules/{id}/items", "put", "422")]
|
|
[TestCase("/api/schedules/{id}/items/{itemId}", "delete", "404")]
|
|
[TestCase("/api/schedules/{id}/items/{itemId}", "delete", "422")]
|
|
[TestCase("/api/playouts/{id}", "get", "404")]
|
|
[TestCase("/api/playouts", "post", "404")]
|
|
[TestCase("/api/playouts", "post", "422")]
|
|
[TestCase("/api/playouts/{id}", "put", "404")]
|
|
[TestCase("/api/playouts/{id}", "put", "409")]
|
|
[TestCase("/api/playouts/{id}", "put", "422")]
|
|
[TestCase("/api/playouts/{id}", "delete", "404")]
|
|
[TestCase("/api/playouts/{id}", "delete", "409")]
|
|
[TestCase("/api/playouts/{id}", "delete", "422")]
|
|
[TestCase("/api/playouts/{id}/deco", "put", "409")]
|
|
[TestCase("/api/playouts/{id}/alternate-schedules", "put", "409")]
|
|
[TestCase("/api/playouts/{id}/templates", "put", "409")]
|
|
[TestCase("/api/playouts/{id}/items", "get", "404")]
|
|
[TestCase("/api/playouts/{id}/erase-items", "post", "404")]
|
|
[TestCase("/api/playouts/{id}/erase-items", "post", "409")]
|
|
[TestCase("/api/playouts/{id}/erase-items", "post", "422")]
|
|
[TestCase("/api/playouts/{id}/erase-items-and-history", "post", "404")]
|
|
[TestCase("/api/playouts/{id}/erase-items-and-history", "post", "409")]
|
|
[TestCase("/api/playouts/{id}/erase-items-and-history", "post", "422")]
|
|
[TestCase("/api/playouts/items/{id}/scheduling-context", "get", "404")]
|
|
[TestCase("/api/collections/{id}/custom-order", "put", "404")]
|
|
[TestCase("/api/collections/{id}/custom-order", "put", "422")]
|
|
[TestCase("/api/artwork/uploads", "post", "422")]
|
|
[TestCase("/api/ffmpeg/profiles/{id}", "get", "404")]
|
|
[TestCase("/api/ffmpeg/profiles", "post", "404")]
|
|
[TestCase("/api/ffmpeg/profiles", "post", "401")]
|
|
[TestCase("/api/ffmpeg/profiles", "post", "422")]
|
|
[TestCase("/api/ffmpeg/profiles/{id}", "put", "404")]
|
|
[TestCase("/api/ffmpeg/profiles/{id}", "put", "401")]
|
|
[TestCase("/api/ffmpeg/profiles/{id}", "put", "422")]
|
|
[TestCase("/api/ffmpeg/profiles/{id}", "delete", "404")]
|
|
[TestCase("/api/ffmpeg/profiles/{id}", "delete", "401")]
|
|
[TestCase("/api/ffmpeg/profiles/{id}", "delete", "422")]
|
|
[TestCase("/api/filler-presets/{id}", "get", "404")]
|
|
[TestCase("/api/filler-presets", "post", "401")]
|
|
[TestCase("/api/filler-presets", "post", "404")]
|
|
[TestCase("/api/filler-presets", "post", "422")]
|
|
[TestCase("/api/filler-presets/{id}", "put", "401")]
|
|
[TestCase("/api/filler-presets/{id}", "put", "404")]
|
|
[TestCase("/api/filler-presets/{id}", "put", "422")]
|
|
[TestCase("/api/filler-presets/{id}", "delete", "401")]
|
|
[TestCase("/api/filler-presets/{id}", "delete", "404")]
|
|
[TestCase("/api/filler-presets/{id}", "delete", "422")]
|
|
[TestCase("/api/watermarks/{id}", "get", "404")]
|
|
[TestCase("/api/watermarks", "post", "401")]
|
|
[TestCase("/api/watermarks", "post", "404")]
|
|
[TestCase("/api/watermarks", "post", "422")]
|
|
[TestCase("/api/watermarks/{id}", "put", "401")]
|
|
[TestCase("/api/watermarks/{id}", "put", "404")]
|
|
[TestCase("/api/watermarks/{id}", "put", "422")]
|
|
[TestCase("/api/watermarks/{id}", "delete", "401")]
|
|
[TestCase("/api/watermarks/{id}", "delete", "404")]
|
|
[TestCase("/api/watermarks/{id}", "delete", "422")]
|
|
[TestCase("/api/settings/ffmpeg", "put", "401")]
|
|
[TestCase("/api/settings/ffmpeg", "put", "422")]
|
|
[TestCase("/api/settings/playout", "put", "401")]
|
|
[TestCase("/api/settings/playout", "put", "422")]
|
|
[TestCase("/api/settings/xmltv", "put", "401")]
|
|
[TestCase("/api/settings/xmltv", "put", "422")]
|
|
[TestCase("/api/settings/scanner", "put", "401")]
|
|
[TestCase("/api/settings/scanner", "put", "422")]
|
|
[TestCase("/api/settings/logging", "put", "401")]
|
|
[TestCase("/api/settings/logging", "put", "422")]
|
|
[TestCase("/api/settings/ui", "put", "401")]
|
|
[TestCase("/api/settings/ui", "put", "422")]
|
|
[TestCase("/api/settings/hdhr", "put", "401")]
|
|
[TestCase("/api/settings/hdhr", "put", "422")]
|
|
[TestCase("/api/settings/resolutions", "post", "401")]
|
|
[TestCase("/api/settings/resolutions", "post", "422")]
|
|
[TestCase("/api/settings/resolutions/{id}", "delete", "401")]
|
|
[TestCase("/api/settings/resolutions/{id}", "delete", "404")]
|
|
[TestCase("/api/settings/resolutions/{id}", "delete", "422")]
|
|
[TestCase("/api/search", "get", "422")]
|
|
[TestCase("/api/media-items", "delete", "422")]
|
|
[TestCase("/api/trakt/lists/{id}", "get", "404")]
|
|
[TestCase("/api/trakt/lists", "post", "422")]
|
|
[TestCase("/api/trakt/lists", "post", "409")]
|
|
[TestCase("/api/trakt/lists/{id}/match", "post", "404")]
|
|
[TestCase("/api/trakt/lists/{id}/match", "post", "409")]
|
|
[TestCase("/api/trakt/lists/{id}", "delete", "404")]
|
|
[TestCase("/api/trakt/lists/{id}", "delete", "409")]
|
|
[TestCase("/api/trakt/lists/{id}", "put", "404")]
|
|
[TestCase("/api/trakt/lists/{id}", "put", "422")]
|
|
[TestCase("/api/troubleshoot/playback/subtitles/{mediaItemId}", "get", "404")]
|
|
[TestCase("/api/troubleshoot/playback.m3u8", "get", "409")]
|
|
[TestCase("/api/troubleshoot/playback.m3u8", "head", "409")]
|
|
[TestCase("/api/libraries/{id}/scan-show", "post", "404")]
|
|
[TestCase("/api/libraries/{id}/scan", "post", "404")]
|
|
[TestCase("/api/libraries/{id}/scan", "post", "409")]
|
|
[TestCase("/api/libraries/{id}/scan", "post", "422")]
|
|
public void Static_OpenApi_Should_Document_ProblemDetails_For_Api_Error_Responses(
|
|
string path,
|
|
string method,
|
|
string statusCode)
|
|
{
|
|
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(FindOpenApiDocument()));
|
|
|
|
JsonElement response = document.RootElement
|
|
.GetProperty("paths")
|
|
.GetProperty(path)
|
|
.GetProperty(method)
|
|
.GetProperty("responses")
|
|
.GetProperty(statusCode);
|
|
|
|
JsonElement content = response.GetProperty("content");
|
|
content.EnumerateObject().ShouldNotBeEmpty();
|
|
|
|
foreach (JsonProperty mediaType in content.EnumerateObject())
|
|
{
|
|
string? schemaRef = mediaType.Value
|
|
.GetProperty("schema")
|
|
.GetProperty("$ref")
|
|
.GetString();
|
|
|
|
schemaRef.ShouldBe("#/components/schemas/ProblemDetails", mediaType.Name);
|
|
}
|
|
}
|
|
|
|
private static string FindOpenApiDocument()
|
|
{
|
|
DirectoryInfo? directory = new(TestContext.CurrentContext.TestDirectory);
|
|
while (directory is not null)
|
|
{
|
|
string candidate = Path.Combine(directory.FullName, "ErsatzTV", "wwwroot", "openapi", "v1.json");
|
|
if (File.Exists(candidate))
|
|
{
|
|
return candidate;
|
|
}
|
|
|
|
directory = directory.Parent;
|
|
}
|
|
|
|
throw new FileNotFoundException("Could not find ErsatzTV/wwwroot/openapi/v1.json");
|
|
}
|
|
}
|