Add CreateTemplate endpoint and related functionality for channels without grids
Implement a new API endpoint to create a template for channels lacking a grid, enhancing the template management capabilities. Update frontend components to support the creation of templates directly from the channel detail view, including user feedback and translations for improved clarity. Add integration tests to ensure the new functionality works as expected.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TeleWave.Application.Programming.Templates;
|
||||
using TeleWave.Application.Programming.Templates.CopyTemplate;
|
||||
using TeleWave.Application.Programming.Templates.CreateTemplate;
|
||||
using TeleWave.Application.Programming.Templates.Validate;
|
||||
using TeleWave.Domain.Broadcast;
|
||||
using TeleWave.Domain.Programming;
|
||||
@@ -91,6 +92,44 @@ public sealed class TemplateOperationsIntegrationTests(PostgresFixture fixture)
|
||||
Assert.Contains(result.Value, i => i.Kind == TemplateIssueKind.GridGap);
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public async Task CreateTemplate_ForChannelWithoutGrid_LinksItAndIsIdempotent()
|
||||
{
|
||||
Skip.IfNot(fixture.Available, "Docker недоступен");
|
||||
|
||||
// Канал из старой ротации: сетки нет, ссылки на неё тоже.
|
||||
await using var seedDb = fixture.CreateContext();
|
||||
var suffix = Guid.NewGuid().ToString("N")[..8];
|
||||
var channel = Channel.Create($"Без сетки {suffix}", $"nogrid-{suffix}", DateTimeOffset.UtcNow);
|
||||
seedDb.Channels.Add(channel);
|
||||
await seedDb.SaveChangesAsync();
|
||||
|
||||
await using var db = fixture.CreateContext();
|
||||
var created = await new CreateChannelTemplateCommandHandler(db).Handle(
|
||||
new CreateChannelTemplateCommand(channel.Id),
|
||||
default
|
||||
);
|
||||
Assert.True(created.IsSuccess);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await using var again = fixture.CreateContext();
|
||||
var second = await new CreateChannelTemplateCommandHandler(again).Handle(
|
||||
new CreateChannelTemplateCommand(channel.Id),
|
||||
default
|
||||
);
|
||||
await again.SaveChangesAsync();
|
||||
|
||||
// Повторный вызов возвращает ту же сетку: одна на канал, второй не появляется.
|
||||
Assert.True(second.IsSuccess);
|
||||
Assert.Equal(created.Value, second.Value);
|
||||
|
||||
await using var verify = fixture.CreateContext();
|
||||
var template = verify.ScheduleTemplates.Single(t => t.ChannelId == channel.Id);
|
||||
Assert.Equal(template.Id, verify.Channels.Single(c => c.Id == channel.Id).TemplateId);
|
||||
// Фоновый слой заводится сразу — без него первую же дыру в сетке нечем закрыть.
|
||||
Assert.Single(verify.GridLayers.Where(l => l.TemplateId == template.Id && l.IsBackground));
|
||||
}
|
||||
|
||||
/// <summary>Два канала: у источника слой со слотом, группой и стыком; у приёмника — пустая сетка.</summary>
|
||||
private static async Task<(Guid Source, Guid Target, Guid GroupId)> SeedPairAsync(AppDbContext db)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user