Files
hrynco-notification-service/HrynCo.NotificationService.Web.IntegrationTests/AdminNavigationTests.cs
agrynco 8e81572386 feat(notification): add admin rest management and deletion
Add revision-safe service and template APIs, channel mapping, and validated admin controls.

Ref: IT-1601
2026-10-17 22:51:01 +03:00

61 lines
3.2 KiB
C#

using System.Net;
using System.Text.RegularExpressions;
using HrynCo.NotificationService.DAL.Abstract.Providers;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.DAL.EF;
using Microsoft.Extensions.DependencyInjection;
namespace HrynCo.NotificationService.Web.IntegrationTests;
public sealed class AdminNavigationTests(TemplateDatabaseFixture fixture) : IClassFixture<TemplateDatabaseFixture>
{
[Fact]
public async Task LayoutLinksToApiDocumentationInNewTab_AndScalarIsAvailable()
{
await using var context = await DefinitionApiTestContext.CreateAsync(fixture);
var pages = new[] { "/admin/services", "/admin/channels", "/admin/services/create", "/admin/channels/create" };
foreach (var page in pages)
{
var html = await context.Client.GetStringAsync(page);
Assert.Single(Regex.Matches(html, "class=\"admin-api-documentation\""));
Assert.Contains("href=\"/scalar/v1\" target=\"_blank\" rel=\"noopener noreferrer\"", html);
Assert.Contains("aria-label=\"API documentation (opens in a new tab)\">API documentation</a>", html);
}
Assert.Equal(HttpStatusCode.OK, (await context.Client.GetAsync("/scalar/v1")).StatusCode);
}
[Fact]
public async Task BothListTablesHaveScopedGridBorders_AndRetainTemplateHeaderOnFilterMiss()
{
await using var context = await DefinitionApiTestContext.CreateAsync(fixture);
var services = await context.Client.GetStringAsync("/admin/services");
Assert.Contains("table table-hover admin-data-table", services);
var templates = await context.Client.GetStringAsync($"/admin/services/{context.ServiceId}?key=Missing");
Assert.Contains("table table-hover admin-data-table service-template-grid", templates);
Assert.Contains("class=\"template-actions\"", templates);
Assert.Contains("No templates match this key.", templates);
Assert.Contains("class=\"template-key-filter\"", templates);
}
[Fact]
public async Task AllFourDataTablesShareTheGridClassAndScopedColumnHeaders()
{
await using var context = await DefinitionApiTestContext.CreateAsync(fixture);
using var scope = context.App.Services.CreateScope();
await scope.ServiceProvider.GetRequiredService<IEmailChannelRepository>().AddAsync(new EmailChannel
{
ServiceName = "TestService", EmailChannelType = EmailChannelType.Smtp,
Settings = new SmtpChannelSettings { Host = "localhost", FromEmail = "test@example.invalid" }
});
await scope.ServiceProvider.GetRequiredService<NotificationDbContext>().SaveChangesAsync();
var pages = new[] { "/admin/services", $"/admin/services/{context.ServiceId}", "/admin/channels", $"/admin/services/{context.ServiceId}/edit" };
foreach (var page in pages)
{
var html = await context.Client.GetStringAsync(page);
Assert.Single(Regex.Matches(html, "<table[^>]+admin-data-table"));
Assert.Equal(Regex.Matches(html, "<th[ >]").Count, Regex.Matches(html, "<th scope=\"col\"").Count);
Assert.DoesNotContain("<thead class=\"table-dark\">", html);
}
}
}