fix(admin): filter template keys by substring

Match both channels case-insensitively while keeping API and delivery lookups exact.

Ref: IT-1627
This commit is contained in:
2026-10-31 10:14:48 +02:00
parent 343d67802c
commit ed4293d852
4 changed files with 48 additions and 4 deletions
@@ -0,0 +1,33 @@
using System.Net;
using System.Net.Http.Json;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.DAL.Abstract.Templates;
using Microsoft.Extensions.DependencyInjection;
namespace HrynCo.NotificationService.Web.IntegrationTests;
public sealed class TemplateKeyFilterTests(TemplateDatabaseFixture fixture) : IClassFixture<TemplateDatabaseFixture>
{
[Theory]
[InlineData("contact", true, false)]
[InlineData(" CONTACT ", true, false)]
[InlineData("", true, true)]
[InlineData(" ", true, true)]
[InlineData("missing", false, false)]
[InlineData("%", false, false)]
public async Task AdminFilterMatchesLiteralSubstringAcrossBothChannels(string filter, bool contacts, bool other)
{
await using var c = await DefinitionApiTestContext.CreateAsync(fixture);
await c.UpsertAsync(DefinitionApiTestContext.Body(null, "en"), "TrustedContactAdded");
await c.UpsertAsync(DefinitionApiTestContext.Body(null, "en"), "PasswordReset");
using var scope = c.App.Services.CreateScope();
var pushes = scope.ServiceProvider.GetRequiredService<IPushTemplateDefinitionRepository>();
await pushes.SaveAsync(new PushTemplateDefinition { ServiceId = c.ServiceId, Key = "TrustedContactRemoved" }, true);
var html = await c.Client.GetStringAsync($"/admin/services/{c.ServiceId}?key={Uri.EscapeDataString(filter)}");
Assert.Equal(contacts, html.Contains(">TrustedContactAdded<", StringComparison.Ordinal));
Assert.Equal(contacts, html.Contains(">TrustedContactRemoved<", StringComparison.Ordinal));
Assert.Equal(other, html.Contains(">PasswordReset<", StringComparison.Ordinal));
Assert.Contains("Clear", html);
Assert.Equal(HttpStatusCode.NotFound, (await c.Client.GetAsync(c.DefinitionUrl("contact"))).StatusCode);
}
}