Files
PnvPanel/backend/tests/PnvPanel.Application.Tests/Admin/Support/ResolveTicketCommandHandlerTests.cs
T
Leonid Pershin fad03c2834
CI / Backend (build + test) (push) Failing after 1m23s
CI / Frontend (lint + typecheck + build) (push) Successful in 34s
Enhance user plan management and update related endpoints
- Added new configuration options for user plans in `.env.example`, including `Plans__MaxCustomConfigCount` and `Plans__MinCustomConfigCount`.
- Introduced `MapPlanEndpoints` in `Program.cs` to handle plan-related API routes.
- Implemented `SetUserPlan` endpoint in `RoleEndpoints` to allow admins to assign plans to users.
- Removed deprecated role request approval endpoints from `AdminSupportEndpoints`.
- Updated `ITelegramNotifier` and related classes to reflect changes in role request handling and payment notifications.
- Refactored role management commands to remove `MaxConfigs` and focus on `MaxIpLimit` and billing settings.
- Enhanced billing request handling to accommodate plan changes instead of role changes.
- Updated various interfaces and command handlers to support new plan management features.
2026-07-23 22:52:20 +03:00

99 lines
3.6 KiB
C#

using NSubstitute;
using PnvPanel.Application.Admin.Support;
using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Support;
using PnvPanel.Application.Tests.TestSupport;
using PnvPanel.Domain.Support;
using Xunit;
namespace PnvPanel.Application.Tests.Admin.Support;
public class ResolveTicketCommandHandlerTests
{
private readonly IRealtimeNotifier _notifier = Substitute.For<IRealtimeNotifier>();
private readonly ITelegramNotifier _telegramNotifier = Substitute.For<ITelegramNotifier>();
[Fact]
public async Task Handle_ResolvesOpenTicket()
{
using var dbContext = InMemoryDbContextFactory.Create();
var userId = Guid.NewGuid();
var ticket = SupportTicket.CreateBugReport(userId);
dbContext.SupportTickets.Add(ticket);
await dbContext.SaveChangesAsync(CancellationToken.None);
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid(), "admin");
var handler = new ResolveTicketCommandHandler(
dbContext,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(
new ResolveTicketCommand(ticket.Id),
CancellationToken.None
);
Assert.True(result.IsSuccess);
Assert.Equal(TicketStatus.Resolved, ticket.Status);
}
[Fact]
public async Task Handle_WhenTicketIsOwnedByAdmin_StillResolves()
{
// Решить свой же тикет можно — Resolve не меняет роль, риска нет (иначе тикет одинокого
// админа навсегда застревал бы в Open).
using var dbContext = InMemoryDbContextFactory.Create();
var adminId = Guid.NewGuid();
var ticket = SupportTicket.CreateBugReport(adminId);
dbContext.SupportTickets.Add(ticket);
await dbContext.SaveChangesAsync(CancellationToken.None);
var currentUser = FakeCurrentUser.Authenticated(adminId, "admin");
var handler = new ResolveTicketCommandHandler(
dbContext,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(
new ResolveTicketCommand(ticket.Id),
CancellationToken.None
);
Assert.True(result.IsSuccess);
Assert.Equal(TicketStatus.Resolved, ticket.Status);
}
[Fact]
public async Task Handle_WhenExtensionRequest_ReturnsOnlyBugReportCanBeResolvedDirectly()
{
// Заявку на продление можно решить только через Approve/Reject — Resolve обходил бы
// одобрение (дни так и не начислились бы), см. CLAUDE.md.
using var dbContext = InMemoryDbContextFactory.Create();
var userId = Guid.NewGuid();
var ticket = SupportTicket.CreateExtensionRequest(userId, 14);
dbContext.SupportTickets.Add(ticket);
await dbContext.SaveChangesAsync(CancellationToken.None);
var currentUser = FakeCurrentUser.Authenticated(Guid.NewGuid(), "admin");
var handler = new ResolveTicketCommandHandler(
dbContext,
_notifier,
_telegramNotifier,
currentUser
);
var result = await handler.Handle(
new ResolveTicketCommand(ticket.Id),
CancellationToken.None
);
Assert.False(result.IsSuccess);
Assert.Equal(SupportErrors.OnlyBugReportCanBeResolvedDirectly, result.Error);
Assert.Equal(TicketStatus.Open, ticket.Status);
}
}