-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert and fix update endpoint specs to meet current task
- Loading branch information
1 parent
2a5e391
commit 9ffee77
Showing
3 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,5 +41,6 @@ | |
|
||
// Admin Endpoints | ||
app.AddAdminEvents(); | ||
app.AddUpdateAdminEvents(); | ||
|
||
await app.RunAsync(); |
166 changes: 166 additions & 0 deletions
166
test/AzureOpenAIProxy.AppHost.Tests/ApiApp/Endpoints/AdminUpdateEventDetailsOpenApiTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
using System.Text.Json; | ||
|
||
using FluentAssertions; | ||
|
||
using AzureOpenAIProxy.AppHost.Tests.Fixtures; | ||
|
||
namespace AzureOpenAIProxy.AppHost.Tests.ApiApp.Endpoints; | ||
|
||
public class AdminUpdateEventDetailsOpenApiTests(AspireAppHostFixture host) : IClassFixture<AspireAppHostFixture> | ||
{ | ||
[Fact] | ||
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Path() | ||
{ | ||
// Arrange | ||
using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|
||
// Act | ||
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|
||
// Assert | ||
var result = openapi!.RootElement.GetProperty("paths") | ||
.TryGetProperty("/admin/events/{eventId}", out var property) ? property : default; | ||
result.ValueKind.Should().Be(JsonValueKind.Object); | ||
} | ||
|
||
[Fact] | ||
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Verb() | ||
{ | ||
// Arrange | ||
using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|
||
// Act | ||
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|
||
// Assert | ||
var result = openapi!.RootElement.GetProperty("paths") | ||
.GetProperty("/admin/events/{eventId}") | ||
.TryGetProperty("put", out var property) ? property : default; | ||
result.ValueKind.Should().Be(JsonValueKind.Object); | ||
} | ||
|
||
[Theory] | ||
[InlineData("admin")] | ||
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Tags(string tag) | ||
{ | ||
// Arrange | ||
using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|
||
// Act | ||
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|
||
// Assert | ||
var result = openapi!.RootElement.GetProperty("paths") | ||
.GetProperty("/admin/events/{eventId}") | ||
.GetProperty("put") | ||
.TryGetProperty("tags", out var property) ? property : default; | ||
result.ValueKind.Should().Be(JsonValueKind.Array); | ||
result.EnumerateArray().Select(p => p.GetString()).Should().Contain(tag); | ||
} | ||
|
||
[Theory] | ||
[InlineData("summary")] | ||
[InlineData("description")] | ||
[InlineData("operationId")] | ||
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Value(string attribute) | ||
{ | ||
// Arrange | ||
using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|
||
// Act | ||
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|
||
// Assert | ||
var result = openapi!.RootElement.GetProperty("paths") | ||
.GetProperty("/admin/events/{eventId}") | ||
.GetProperty("put") | ||
.TryGetProperty(attribute, out var property) ? property : default; | ||
result.ValueKind.Should().Be(JsonValueKind.String); | ||
} | ||
|
||
[Theory] | ||
[InlineData("parameters")] | ||
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Array(string attribute) | ||
{ | ||
// Arrange | ||
using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|
||
// Act | ||
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|
||
// Assert | ||
var result = openapi!.RootElement.GetProperty("paths") | ||
.GetProperty("/admin/events/{eventId}") | ||
.GetProperty("put") | ||
.TryGetProperty(attribute, out var property) ? property : default; | ||
result.ValueKind.Should().Be(JsonValueKind.Array); | ||
} | ||
|
||
[Theory] | ||
[InlineData("eventId")] | ||
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Path_Parameter(string name) | ||
{ | ||
// Arrange | ||
using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|
||
// Act | ||
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|
||
// Assert | ||
var result = openapi!.RootElement.GetProperty("paths") | ||
.GetProperty("/admin/events/{eventId}") | ||
.GetProperty("put") | ||
.GetProperty("parameters") | ||
.EnumerateArray() | ||
.Where(p => p.GetProperty("in").GetString() == "path") | ||
.Select(p => p.GetProperty("name").ToString()); | ||
result.Should().Contain(name); | ||
} | ||
|
||
[Theory] | ||
[InlineData("responses")] | ||
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Object(string attribute) | ||
{ | ||
// Arrange | ||
using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|
||
// Act | ||
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|
||
// Assert | ||
var result = openapi!.RootElement.GetProperty("paths") | ||
.GetProperty("/admin/events/{eventId}") | ||
.GetProperty("put") | ||
.TryGetProperty(attribute, out var property) ? property : default; | ||
result.ValueKind.Should().Be(JsonValueKind.Object); | ||
} | ||
|
||
[Theory] | ||
[InlineData("200")] | ||
[InlineData("401")] | ||
[InlineData("500")] | ||
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Response(string attribute) | ||
{ | ||
// Arrange | ||
using var httpClient = host.App!.CreateHttpClient("apiapp"); | ||
|
||
// Act | ||
var json = await httpClient.GetStringAsync("/swagger/v1.0.0/swagger.json"); | ||
var openapi = JsonSerializer.Deserialize<JsonDocument>(json); | ||
|
||
// Assert | ||
var result = openapi!.RootElement.GetProperty("paths") | ||
.GetProperty("/admin/events/{eventId}") | ||
.GetProperty("put") | ||
.GetProperty("responses") | ||
.TryGetProperty(attribute, out var property) ? property : default; | ||
result.ValueKind.Should().Be(JsonValueKind.Object); | ||
} | ||
} |