69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using System.Text.Json;
|
|
|
|
namespace FinalFactory.Rendezvous.Tests.Contracts;
|
|
|
|
public sealed class OpenApiCompatibilityTests
|
|
{
|
|
private static readonly string[] ExpectedPaths =
|
|
[
|
|
"/health/live",
|
|
"/health/ready",
|
|
"/v1/join-attempts",
|
|
"/v1/join-attempts/{attemptId}/outcome",
|
|
"/v1/sessions",
|
|
"/v1/sessions/{listingId}",
|
|
"/v1/sessions/{listingId}/join-attempts",
|
|
"/v1/sessions/{listingId}/renew",
|
|
];
|
|
|
|
private static readonly string[] ExpectedListingProperties =
|
|
[
|
|
"buildVersion",
|
|
"capacity",
|
|
"contractVersion",
|
|
"displayName",
|
|
"environmentId",
|
|
"gameId",
|
|
"listingId",
|
|
"metadata",
|
|
"protocolVersion",
|
|
"publisherTrustMode",
|
|
"regionId",
|
|
"visibility",
|
|
];
|
|
|
|
[Fact]
|
|
public void GeneratedOpenApiContainsTheFrozenV1Surface()
|
|
{
|
|
string path = Path.Combine(
|
|
ContractTestFiles.Directory,
|
|
"../../../../../docs/api/rendezvous-v1.json");
|
|
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(Path.GetFullPath(path)));
|
|
JsonElement root = document.RootElement;
|
|
|
|
Assert.Equal("3.1.1", root.GetProperty("openapi").GetString());
|
|
string[] paths = root.GetProperty("paths")
|
|
.EnumerateObject()
|
|
.Select(static item => item.Name)
|
|
.Order(StringComparer.Ordinal)
|
|
.ToArray();
|
|
Assert.Equal(ExpectedPaths, paths);
|
|
|
|
JsonElement schemas = root.GetProperty("components").GetProperty("schemas");
|
|
Assert.Equal("string", schemas.GetProperty("GameId").GetProperty("type").GetString());
|
|
Assert.Equal("uuid", schemas.GetProperty("SessionListingId").GetProperty("format").GetString());
|
|
|
|
string[] listingProperties = schemas.GetProperty("SessionListing")
|
|
.GetProperty("properties")
|
|
.EnumerateObject()
|
|
.Select(static item => item.Name)
|
|
.Order(StringComparer.Ordinal)
|
|
.ToArray();
|
|
Assert.Equal(ExpectedListingProperties, listingProperties);
|
|
Assert.DoesNotContain(listingProperties, static property =>
|
|
property.Contains("token", StringComparison.OrdinalIgnoreCase)
|
|
|| property.Contains("endpoint", StringComparison.OrdinalIgnoreCase)
|
|
|| property.Contains("playerId", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
}
|