- Updated the `PaymentRequest` model to include a new `Kind` property, distinguishing between `Subscription` and `RoleChangeTopUp` requests. - Modified the `TelegramNotifier` to accommodate the new request type, ensuring accurate notifications for role change top-ups. - Enhanced the `ConfirmPaymentRequestCommandHandler` to handle role change top-ups without extending the billing period, reflecting the new payment logic. - Updated various application components and tests to support the new payment request structure and ensure proper functionality. - Revised API documentation to clarify the behavior of role change top-ups and their impact on billing.
77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
using NSubstitute;
|
|
using PnvPanel.Application.Billing;
|
|
using PnvPanel.Application.Billing.MarkPaymentSent;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using PnvPanel.Application.Tests.TestSupport;
|
|
using PnvPanel.Domain.Billing;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Application.Tests.Billing.MarkPaymentSent;
|
|
|
|
public class MarkPaymentSentCommandHandlerTests
|
|
{
|
|
private readonly IIdentityService _identityService = Substitute.For<IIdentityService>();
|
|
private readonly ITelegramNotifier _telegramNotifier = Substitute.For<ITelegramNotifier>();
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenAwaitingPayment_MovesToAwaitingConfirmationAndNotifiesAdmins()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
var request = PaymentRequest.Create(userId, PaymentPeriod.Year, 6000);
|
|
dbContext.PaymentRequests.Add(request);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new MarkPaymentSentCommandHandler(
|
|
dbContext,
|
|
_identityService,
|
|
_telegramNotifier,
|
|
FakeCurrentUser.Authenticated(userId, "alice")
|
|
);
|
|
|
|
var result = await handler.Handle(
|
|
new MarkPaymentSentCommand(request.Id),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.Equal(PaymentRequestStatus.AwaitingConfirmation, request.Status);
|
|
await _telegramNotifier
|
|
.Received(1)
|
|
.NotifyAdminsPaymentRequestedAsync(
|
|
request.Id,
|
|
Arg.Any<string>(),
|
|
PaymentRequestKind.Subscription,
|
|
PaymentPeriod.Year,
|
|
6000,
|
|
Arg.Any<CancellationToken>()
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenAlreadyAwaitingConfirmation_ReturnsNotAwaitingPayment()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
var request = PaymentRequest.Create(userId, PaymentPeriod.Year, 6000);
|
|
request.MarkPaymentSent();
|
|
dbContext.PaymentRequests.Add(request);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new MarkPaymentSentCommandHandler(
|
|
dbContext,
|
|
_identityService,
|
|
_telegramNotifier,
|
|
FakeCurrentUser.Authenticated(userId)
|
|
);
|
|
|
|
var result = await handler.Handle(
|
|
new MarkPaymentSentCommand(request.Id),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.False(result.IsSuccess);
|
|
Assert.Equal(BillingErrors.RequestNotAwaitingPayment, result.Error);
|
|
}
|
|
}
|