- Added 'IsRecommended' property to app-related data models, allowing apps to be marked as recommended. - Updated API endpoints for creating and updating apps to include 'IsRecommended' in request bodies. - Modified database schema to accommodate the new 'IsRecommended' field. - Enhanced frontend components to display recommended apps with a star icon and updated forms to manage this property. - Improved sorting logic in app listings to prioritize recommended apps. - Updated documentation to reflect changes in API and data models.
87 lines
2.9 KiB
C#
87 lines
2.9 KiB
C#
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,
|
|
isRecommended: false
|
|
);
|
|
disabledApp.Update(
|
|
disabledApp.Name,
|
|
disabledApp.DownloadUrl,
|
|
disabledApp.OperatingSystem,
|
|
null,
|
|
null,
|
|
0,
|
|
isEnabled: false,
|
|
isRecommended: false
|
|
);
|
|
|
|
var enabledApp = ClientApp.Create(
|
|
"Active Client",
|
|
new Uri("https://example.com/active"),
|
|
OsPlatform.IOS,
|
|
null,
|
|
null,
|
|
0,
|
|
isRecommended: false
|
|
);
|
|
|
|
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,
|
|
isRecommended: false
|
|
);
|
|
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));
|
|
}
|
|
}
|