- Added new endpoints for creating and managing extension requests, allowing users to request billing period extensions. - Implemented admin approval processes for extension requests via Telegram, including inline buttons for approval and rejection. - Introduced a gifting feature for admins to grant additional billing days directly to users without a request. - Updated the support ticket model to accommodate extension requests and their associated properties. - Enhanced the Telegram notifier to inform admins of new extension requests and notify users of approval or rejection. - Updated frontend components to support the new extension request and gifting functionalities, including user interfaces for managing these features. - Revised API documentation to reflect the new endpoints and their usage in the billing context.
74 lines
2.5 KiB
C#
74 lines
2.5 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 RejectExtensionRequestCommandHandlerTests
|
|
{
|
|
private readonly IRealtimeNotifier _notifier = Substitute.For<IRealtimeNotifier>();
|
|
private readonly ITelegramNotifier _telegramNotifier = Substitute.For<ITelegramNotifier>();
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenOpen_ClosesAndNotifiesUser()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var adminId = Guid.NewGuid();
|
|
var userId = Guid.NewGuid();
|
|
var ticket = SupportTicket.CreateExtensionRequest(userId, 5);
|
|
dbContext.SupportTickets.Add(ticket);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new RejectExtensionRequestCommandHandler(
|
|
dbContext,
|
|
_notifier,
|
|
_telegramNotifier,
|
|
FakeCurrentUser.Authenticated(adminId, "admin")
|
|
);
|
|
|
|
var result = await handler.Handle(
|
|
new RejectExtensionRequestCommand(ticket.Id, "Недостаточно оснований"),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.Equal(TicketStatus.Closed, ticket.Status);
|
|
await _telegramNotifier
|
|
.Received(1)
|
|
.NotifyUserAsync(
|
|
userId,
|
|
Arg.Any<string>(),
|
|
Arg.Any<string?>(),
|
|
Arg.Any<CancellationToken>()
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenNotExtensionRequest_ReturnsNotExtensionRequest()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var ticket = SupportTicket.CreateBugReport(Guid.NewGuid());
|
|
dbContext.SupportTickets.Add(ticket);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new RejectExtensionRequestCommandHandler(
|
|
dbContext,
|
|
_notifier,
|
|
_telegramNotifier,
|
|
FakeCurrentUser.Authenticated(Guid.NewGuid(), "admin")
|
|
);
|
|
|
|
var result = await handler.Handle(
|
|
new RejectExtensionRequestCommand(ticket.Id, null),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.False(result.IsSuccess);
|
|
Assert.Equal(SupportErrors.NotExtensionRequest, result.Error);
|
|
}
|
|
}
|