- Introduced billing capabilities, allowing users to request payments for subscription periods (3/6/12 months) with admin approval via Telegram. - Updated role management to include a `BillingEnabled` property, preventing billing for admin roles. - Enhanced the `CreateRoleCommand` and `UpdateRoleCommand` to accept billing parameters, ensuring proper handling during role creation and updates. - Added new endpoints for billing management and integrated billing checks into VPN config creation to enforce payment requirements. - Updated related services, models, and tests to support the new billing features, ensuring comprehensive coverage and functionality. - Enhanced documentation to reflect the new billing processes and role management changes.
80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using PnvPanel.Application.Billing;
|
|
using PnvPanel.Application.Billing.CancelPaymentRequest;
|
|
using PnvPanel.Application.Tests.TestSupport;
|
|
using PnvPanel.Domain.Billing;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Application.Tests.Billing.CancelPaymentRequest;
|
|
|
|
public class CancelPaymentRequestCommandHandlerTests
|
|
{
|
|
[Fact]
|
|
public async Task Handle_WhenAwaitingPayment_Cancels()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
var request = PaymentRequest.Create(userId, PaymentPeriod.Quarter, 1000);
|
|
dbContext.PaymentRequests.Add(request);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new CancelPaymentRequestCommandHandler(
|
|
dbContext,
|
|
FakeCurrentUser.Authenticated(userId)
|
|
);
|
|
|
|
var result = await handler.Handle(
|
|
new CancelPaymentRequestCommand(request.Id),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.Equal(PaymentRequestStatus.Cancelled, request.Status);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenAwaitingConfirmation_ReturnsNotCancellable()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
var request = PaymentRequest.Create(userId, PaymentPeriod.Quarter, 1000);
|
|
request.MarkPaymentSent();
|
|
dbContext.PaymentRequests.Add(request);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new CancelPaymentRequestCommandHandler(
|
|
dbContext,
|
|
FakeCurrentUser.Authenticated(userId)
|
|
);
|
|
|
|
var result = await handler.Handle(
|
|
new CancelPaymentRequestCommand(request.Id),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.False(result.IsSuccess);
|
|
Assert.Equal(BillingErrors.RequestNotCancellable, result.Error);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenOwnedByAnotherUser_ReturnsNotFound()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var request = PaymentRequest.Create(Guid.NewGuid(), PaymentPeriod.Quarter, 1000);
|
|
dbContext.PaymentRequests.Add(request);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
var handler = new CancelPaymentRequestCommandHandler(
|
|
dbContext,
|
|
FakeCurrentUser.Authenticated(Guid.NewGuid())
|
|
);
|
|
|
|
var result = await handler.Handle(
|
|
new CancelPaymentRequestCommand(request.Id),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.False(result.IsSuccess);
|
|
Assert.Equal(BillingErrors.RequestNotFound, result.Error);
|
|
}
|
|
}
|