Enhance show deletion functionality to support media removal option
Updated the DeleteShowCommand and its handler to include an optional parameter for media deletion, allowing users to remove associated media files when deleting a show. Refactored related components and API calls to accommodate this new feature, ensuring a seamless user experience. Additionally, updated localization strings to reflect the new functionality and adjusted tests to verify the correct behavior of the deletion process with and without media.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NSubstitute;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Application.Library;
|
||||
@@ -27,6 +28,9 @@ public class DeleteGuardsTests
|
||||
private static GroupMembershipCleaner GroupCleaner(IAppDbContext db) =>
|
||||
new(db, GroupServices.Stats(db));
|
||||
|
||||
private static ShowMediaEraser Eraser(IAppDbContext db) =>
|
||||
new(db, Substitute.For<IMediaStorage>());
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteShow_InFutureSchedule_Fails()
|
||||
{
|
||||
@@ -53,7 +57,7 @@ public class DeleteGuardsTests
|
||||
}
|
||||
|
||||
await using var db = fixture.New();
|
||||
var result = await new DeleteShowCommandHandler(db, GroupCleaner(db)).Handle(
|
||||
var result = await new DeleteShowCommandHandler(db, GroupCleaner(db), Eraser(db)).Handle(
|
||||
new DeleteShowCommand(show.Id),
|
||||
CancellationToken.None
|
||||
);
|
||||
@@ -62,6 +66,41 @@ public class DeleteGuardsTests
|
||||
Assert.Equal(ShowErrors.InFutureSchedule, result.Error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Без флага медиа переживает шоу: серия — это ссылка на ассет по значению, внешнего ключа
|
||||
/// между ними нет, и каскад БД до файлов не доходит.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DeleteShow_KeepsMedia_ByDefault()
|
||||
{
|
||||
var fixture = new TestDb();
|
||||
var show = Show.Create("A", ShowKind.Single);
|
||||
var asset = MediaAsset.Register("a.mkv", ".mkv", MediaSource.Upload);
|
||||
show.AddEpisode(asset.Id);
|
||||
|
||||
await using (var seed = fixture.New())
|
||||
{
|
||||
seed.Shows.Add(show);
|
||||
seed.MediaAssets.Add(asset);
|
||||
await seed.SaveChangesAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
await using (var db = fixture.New())
|
||||
{
|
||||
var result = await new DeleteShowCommandHandler(
|
||||
db,
|
||||
GroupCleaner(db),
|
||||
Eraser(db)
|
||||
).Handle(new DeleteShowCommand(show.Id), CancellationToken.None);
|
||||
Assert.True(result.IsSuccess);
|
||||
await db.SaveChangesAsync(CancellationToken.None);
|
||||
}
|
||||
|
||||
await using var check = fixture.New();
|
||||
Assert.Empty(await check.Shows.ToListAsync(CancellationToken.None));
|
||||
Assert.Single(await check.MediaAssets.ToListAsync(CancellationToken.None));
|
||||
}
|
||||
|
||||
/// <summary>Отыгранный эфир шоу не держит: иначе его нельзя было бы удалить никогда.</summary>
|
||||
[Fact]
|
||||
public async Task DeleteShow_OnlyPastSchedule_Succeeds()
|
||||
@@ -81,7 +120,7 @@ public class DeleteGuardsTests
|
||||
}
|
||||
|
||||
await using var db = fixture.New();
|
||||
var result = await new DeleteShowCommandHandler(db, GroupCleaner(db)).Handle(
|
||||
var result = await new DeleteShowCommandHandler(db, GroupCleaner(db), Eraser(db)).Handle(
|
||||
new DeleteShowCommand(show.Id),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user