up
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
This commit is contained in:
@@ -1,86 +1,86 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
|
||||
namespace StellaOps.Notify.WebService.Tests;
|
||||
|
||||
public sealed class NormalizeEndpointsTests : IClassFixture<WebApplicationFactory<Program>>, IAsyncLifetime
|
||||
{
|
||||
private readonly WebApplicationFactory<Program> _factory;
|
||||
|
||||
public NormalizeEndpointsTests(WebApplicationFactory<Program> factory)
|
||||
{
|
||||
_factory = factory.WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.UseSetting("notify:storage:driver", "memory");
|
||||
builder.UseSetting("notify:authority:enabled", "false");
|
||||
builder.UseSetting("notify:authority:developmentSigningKey", "normalize-tests-signing-key-1234567890");
|
||||
builder.UseSetting("notify:authority:issuer", "test-issuer");
|
||||
builder.UseSetting("notify:authority:audiences:0", "notify");
|
||||
builder.UseSetting("notify:telemetry:enableRequestLogging", "false");
|
||||
});
|
||||
}
|
||||
|
||||
public Task InitializeAsync() => Task.CompletedTask;
|
||||
|
||||
public Task DisposeAsync() => Task.CompletedTask;
|
||||
|
||||
[Fact]
|
||||
public async Task RuleNormalizeAddsSchemaVersion()
|
||||
{
|
||||
var client = _factory.CreateClient();
|
||||
var payload = LoadSampleNode("notify-rule@1.sample.json");
|
||||
payload!.AsObject().Remove("schemaVersion");
|
||||
|
||||
var response = await client.PostAsJsonAsync("/internal/notify/rules/normalize", payload);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var normalized = JsonNode.Parse(content);
|
||||
|
||||
Assert.Equal("notify.rule@1", normalized?["schemaVersion"]?.GetValue<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ChannelNormalizeAddsSchemaVersion()
|
||||
{
|
||||
var client = _factory.CreateClient();
|
||||
var payload = LoadSampleNode("notify-channel@1.sample.json");
|
||||
payload!.AsObject().Remove("schemaVersion");
|
||||
|
||||
var response = await client.PostAsJsonAsync("/internal/notify/channels/normalize", payload);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var normalized = JsonNode.Parse(content);
|
||||
|
||||
Assert.Equal("notify.channel@1", normalized?["schemaVersion"]?.GetValue<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TemplateNormalizeAddsSchemaVersion()
|
||||
{
|
||||
var client = _factory.CreateClient();
|
||||
var payload = LoadSampleNode("notify-template@1.sample.json");
|
||||
payload!.AsObject().Remove("schemaVersion");
|
||||
|
||||
var response = await client.PostAsJsonAsync("/internal/notify/templates/normalize", payload);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var normalized = JsonNode.Parse(content);
|
||||
|
||||
Assert.Equal("notify.template@1", normalized?["schemaVersion"]?.GetValue<string>());
|
||||
}
|
||||
|
||||
private static JsonNode? LoadSampleNode(string fileName)
|
||||
{
|
||||
var path = Path.Combine(AppContext.BaseDirectory, fileName);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new FileNotFoundException($"Unable to load sample '{fileName}'.", path);
|
||||
}
|
||||
|
||||
return JsonNode.Parse(File.ReadAllText(path));
|
||||
}
|
||||
}
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
|
||||
namespace StellaOps.Notify.WebService.Tests;
|
||||
|
||||
public sealed class NormalizeEndpointsTests : IClassFixture<WebApplicationFactory<Program>>, IAsyncLifetime
|
||||
{
|
||||
private readonly WebApplicationFactory<Program> _factory;
|
||||
|
||||
public NormalizeEndpointsTests(WebApplicationFactory<Program> factory)
|
||||
{
|
||||
_factory = factory.WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.UseSetting("notify:storage:driver", "memory");
|
||||
builder.UseSetting("notify:authority:enabled", "false");
|
||||
builder.UseSetting("notify:authority:developmentSigningKey", "normalize-tests-signing-key-1234567890");
|
||||
builder.UseSetting("notify:authority:issuer", "test-issuer");
|
||||
builder.UseSetting("notify:authority:audiences:0", "notify");
|
||||
builder.UseSetting("notify:telemetry:enableRequestLogging", "false");
|
||||
});
|
||||
}
|
||||
|
||||
public Task InitializeAsync() => Task.CompletedTask;
|
||||
|
||||
public Task DisposeAsync() => Task.CompletedTask;
|
||||
|
||||
[Fact]
|
||||
public async Task RuleNormalizeAddsSchemaVersion()
|
||||
{
|
||||
var client = _factory.CreateClient();
|
||||
var payload = LoadSampleNode("notify-rule@1.sample.json");
|
||||
payload!.AsObject().Remove("schemaVersion");
|
||||
|
||||
var response = await client.PostAsJsonAsync("/internal/notify/rules/normalize", payload);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var normalized = JsonNode.Parse(content);
|
||||
|
||||
Assert.Equal("notify.rule@1", normalized?["schemaVersion"]?.GetValue<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ChannelNormalizeAddsSchemaVersion()
|
||||
{
|
||||
var client = _factory.CreateClient();
|
||||
var payload = LoadSampleNode("notify-channel@1.sample.json");
|
||||
payload!.AsObject().Remove("schemaVersion");
|
||||
|
||||
var response = await client.PostAsJsonAsync("/internal/notify/channels/normalize", payload);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var normalized = JsonNode.Parse(content);
|
||||
|
||||
Assert.Equal("notify.channel@1", normalized?["schemaVersion"]?.GetValue<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TemplateNormalizeAddsSchemaVersion()
|
||||
{
|
||||
var client = _factory.CreateClient();
|
||||
var payload = LoadSampleNode("notify-template@1.sample.json");
|
||||
payload!.AsObject().Remove("schemaVersion");
|
||||
|
||||
var response = await client.PostAsJsonAsync("/internal/notify/templates/normalize", payload);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
var normalized = JsonNode.Parse(content);
|
||||
|
||||
Assert.Equal("notify.template@1", normalized?["schemaVersion"]?.GetValue<string>());
|
||||
}
|
||||
|
||||
private static JsonNode? LoadSampleNode(string fileName)
|
||||
{
|
||||
var path = Path.Combine(AppContext.BaseDirectory, fileName);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new FileNotFoundException($"Unable to load sample '{fileName}'.", path);
|
||||
}
|
||||
|
||||
return JsonNode.Parse(File.ReadAllText(path));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user