OpenApiSpecTests.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.IO;
  2. using System.Reflection;
  3. using System.Text.Json;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Model.Branding;
  6. using Xunit;
  7. using Xunit.Abstractions;
  8. namespace Jellyfin.Server.Integration.Tests
  9. {
  10. public sealed class OpenApiSpecTests : IClassFixture<JellyfinApplicationFactory>
  11. {
  12. private readonly JellyfinApplicationFactory _factory;
  13. private readonly ITestOutputHelper _outputHelper;
  14. public OpenApiSpecTests(JellyfinApplicationFactory factory, ITestOutputHelper outputHelper)
  15. {
  16. _factory = factory;
  17. _outputHelper = outputHelper;
  18. }
  19. [Fact]
  20. public async Task GetSpec_ReturnsCorrectResponse()
  21. {
  22. // Arrange
  23. var client = _factory.CreateClient();
  24. // Act
  25. var response = await client.GetAsync("/api-docs/openapi.json");
  26. // Assert
  27. response.EnsureSuccessStatusCode();
  28. Assert.Equal("application/json; charset=utf-8", response.Content.Headers.ContentType?.ToString());
  29. // Write out for publishing
  30. var responseBody = await response.Content.ReadAsStringAsync();
  31. string outputPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ".", "openapi.json"));
  32. _outputHelper.WriteLine("Writing OpenAPI Spec JSON to '{0}'.", outputPath);
  33. File.WriteAllText(outputPath, responseBody);
  34. }
  35. }
  36. }