Enhance admin maintenance functionality with new endpoints and response types
- Added new DELETE endpoints for managing audit logs and disabled apps in the admin maintenance section. - Updated existing endpoint for closed tickets to use a unified response type, `MaintenanceCleanupResponseDto`. - Enhanced API documentation to reflect the new operations and their expected request/response formats. - Improved frontend integration with new functions for deleting old audit logs and disabled apps, including user confirmation prompts. - Added localization support for new maintenance actions in both Russian and English.
This commit is contained in:
+82
@@ -0,0 +1,82 @@
|
||||
using PnvPanel.Application.Admin.Maintenance;
|
||||
using PnvPanel.Application.Tests.TestSupport;
|
||||
using PnvPanel.Domain.Apps;
|
||||
using Xunit;
|
||||
|
||||
namespace PnvPanel.Application.Tests.Admin.Maintenance;
|
||||
|
||||
public class DeleteDisabledAppsCommandHandlerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Handle_DeletesDisabledApps_KeepsEnabled()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
|
||||
var disabledApp = ClientApp.Create(
|
||||
"Old Client",
|
||||
new Uri("https://example.com/old"),
|
||||
OsPlatform.Android,
|
||||
null,
|
||||
null,
|
||||
0
|
||||
);
|
||||
disabledApp.Update(
|
||||
disabledApp.Name,
|
||||
disabledApp.DownloadUrl,
|
||||
disabledApp.OperatingSystem,
|
||||
null,
|
||||
null,
|
||||
0,
|
||||
isEnabled: false
|
||||
);
|
||||
|
||||
var enabledApp = ClientApp.Create(
|
||||
"Active Client",
|
||||
new Uri("https://example.com/active"),
|
||||
OsPlatform.IOS,
|
||||
null,
|
||||
null,
|
||||
0
|
||||
);
|
||||
|
||||
dbContext.ClientApps.AddRange(disabledApp, enabledApp);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid(), "admin");
|
||||
var handler = new DeleteDisabledAppsCommandHandler(dbContext, currentUser);
|
||||
|
||||
var result = await handler.Handle(new DeleteDisabledAppsCommand(), CancellationToken.None);
|
||||
// Хендлер не коммитит сам (в проде это делает UnitOfWorkBehavior после диспетчера) — коммитим явно.
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal(1, result.Value);
|
||||
Assert.False(dbContext.ClientApps.Any(a => a.Id == disabledApp.Id));
|
||||
Assert.True(dbContext.ClientApps.Any(a => a.Id == enabledApp.Id));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenNoDisabledApps_ReturnsZero()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
var enabledApp = ClientApp.Create(
|
||||
"Active Client",
|
||||
new Uri("https://example.com/active"),
|
||||
OsPlatform.IOS,
|
||||
null,
|
||||
null,
|
||||
0
|
||||
);
|
||||
dbContext.ClientApps.Add(enabledApp);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid(), "admin");
|
||||
var handler = new DeleteDisabledAppsCommandHandler(dbContext, currentUser);
|
||||
|
||||
var result = await handler.Handle(new DeleteDisabledAppsCommand(), CancellationToken.None);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal(0, result.Value);
|
||||
Assert.True(dbContext.ClientApps.Any(a => a.Id == enabledApp.Id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user