- 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.
82 lines
3.0 KiB
C#
82 lines
3.0 KiB
C#
using NSubstitute;
|
|
using PnvPanel.Application.Admin.Billing;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using PnvPanel.Application.Tests.TestSupport;
|
|
using PnvPanel.Domain.Billing;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Application.Tests.Admin.Billing;
|
|
|
|
public class ListPaymentRequestsQueryHandlerTests
|
|
{
|
|
private readonly IIdentityService _identityService = Substitute.For<IIdentityService>();
|
|
|
|
[Fact]
|
|
public async Task Handle_FiltersByKind()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
var subscription = PaymentRequest.Create(userId, PaymentPeriod.Quarter, 1500);
|
|
var topUp = PaymentRequest.CreatePlanChangeTopUp(userId, 500);
|
|
dbContext.PaymentRequests.AddRange(subscription, topUp);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
_identityService
|
|
.GetUserNamesAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
|
.Returns(new Dictionary<Guid, string> { [userId] = "alice" });
|
|
|
|
var handler = new ListPaymentRequestsQueryHandler(dbContext, _identityService);
|
|
|
|
var result = await handler.Handle(
|
|
new ListPaymentRequestsQuery(
|
|
StatusFilter: null,
|
|
KindFilter: PaymentRequestKind.PlanChangeTopUp,
|
|
Search: null,
|
|
Page: 1,
|
|
PageSize: 20
|
|
),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
var item = Assert.Single(result.Value.Items);
|
|
Assert.Equal(topUp.Id, item.Id);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_FiltersBySearch_ResolvesUserIdsBeforePagination()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var aliceId = Guid.NewGuid();
|
|
var bobId = Guid.NewGuid();
|
|
var aliceRequest = PaymentRequest.Create(aliceId, PaymentPeriod.Quarter, 1500);
|
|
var bobRequest = PaymentRequest.Create(bobId, PaymentPeriod.Quarter, 1500);
|
|
dbContext.PaymentRequests.AddRange(aliceRequest, bobRequest);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
_identityService
|
|
.FindUserIdsByUserNameAsync("alice", Arg.Any<CancellationToken>())
|
|
.Returns([aliceId]);
|
|
_identityService
|
|
.GetUserNamesAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
|
|
.Returns(new Dictionary<Guid, string> { [aliceId] = "alice" });
|
|
|
|
var handler = new ListPaymentRequestsQueryHandler(dbContext, _identityService);
|
|
|
|
var result = await handler.Handle(
|
|
new ListPaymentRequestsQuery(
|
|
StatusFilter: null,
|
|
KindFilter: null,
|
|
Search: "alice",
|
|
Page: 1,
|
|
PageSize: 20
|
|
),
|
|
CancellationToken.None
|
|
);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
var item = Assert.Single(result.Value.Items);
|
|
Assert.Equal(aliceRequest.Id, item.Id);
|
|
}
|
|
}
|