- Introduced new endpoints for managing instruction intros and tabs, allowing admins to create, update, and delete instructional content. - Enhanced the FactoryResetCommandHandler to include the seeding of instruction data during a factory reset. - Updated the database schema to include InstructionIntro and InstructionTab entities, with corresponding migrations. - Improved frontend routing and components to support the new instructions section, including a dedicated page for displaying instructions and tabs. - Enhanced API documentation to reflect the new instruction management features and their expected request/response formats. - Added localization support for the new instructions functionality in both Russian and English.
50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using PnvPanel.Application.Admin.Instructions;
|
|
using PnvPanel.Application.Tests.TestSupport;
|
|
using PnvPanel.Domain.Instructions;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Application.Tests.Admin.Instructions;
|
|
|
|
public class UpdateInstructionIntroCommandHandlerTests
|
|
{
|
|
[Fact]
|
|
public async Task Handle_WhenNoIntroExists_CreatesIt()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var handler = new UpdateInstructionIntroCommandHandler(dbContext);
|
|
|
|
var result = await handler.Handle(
|
|
new UpdateInstructionIntroCommand("Новый текст"),
|
|
CancellationToken.None
|
|
);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.Equal("Новый текст", result.Value.Body);
|
|
Assert.Single(dbContext.InstructionIntros);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenIntroExists_UpdatesItInPlace()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var intro = InstructionIntro.Create("Старый текст");
|
|
dbContext.InstructionIntros.Add(intro);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new UpdateInstructionIntroCommandHandler(dbContext);
|
|
|
|
var result = await handler.Handle(
|
|
new UpdateInstructionIntroCommand("Обновлённый текст"),
|
|
CancellationToken.None
|
|
);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.Equal(intro.Id, result.Value.Id);
|
|
Assert.Equal("Обновлённый текст", result.Value.Body);
|
|
// Не создаётся вторая строка — обновляется существующая (singleton).
|
|
Assert.Single(dbContext.InstructionIntros);
|
|
}
|
|
}
|