2020-09-03 19:51:38 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Text.Json;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using MediaBrowser.Model.Branding;
|
|
|
|
using Xunit;
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
2021-03-01 18:35:58 +00:00
|
|
|
namespace Jellyfin.Server.Integration.Tests
|
2020-09-03 19:51:38 +00:00
|
|
|
{
|
|
|
|
public sealed class OpenApiSpecTests : IClassFixture<JellyfinApplicationFactory>
|
|
|
|
{
|
|
|
|
private readonly JellyfinApplicationFactory _factory;
|
|
|
|
private readonly ITestOutputHelper _outputHelper;
|
|
|
|
|
|
|
|
public OpenApiSpecTests(JellyfinApplicationFactory factory, ITestOutputHelper outputHelper)
|
|
|
|
{
|
|
|
|
_factory = factory;
|
|
|
|
_outputHelper = outputHelper;
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public async Task GetSpec_ReturnsCorrectResponse()
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.GetAsync("/api-docs/openapi.json");
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
response.EnsureSuccessStatusCode();
|
2020-11-13 16:21:22 +00:00
|
|
|
Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType?.ToString());
|
2020-09-03 19:51:38 +00:00
|
|
|
|
|
|
|
// Write out for publishing
|
|
|
|
var responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
string outputPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ".", "openapi.json"));
|
|
|
|
_outputHelper.WriteLine("Writing OpenAPI Spec JSON to '{0}'.", outputPath);
|
|
|
|
File.WriteAllText(outputPath, responseBody);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|