- Updated `ListPaymentRequestsQuery` to include `Kind` and `Search` parameters for better filtering of payment requests. - Enhanced `ListAuditLogsQuery` to support additional filters: `Source`, `TargetType`, and `Action`, improving audit log retrieval. - Modified `ListUsersQuery` to accept new filters: `RoleId`, `IsActivated`, `IsBlocked`, and `BillingExpired`, allowing for more granular user management. - Introduced `DeleteInbound` endpoint to allow deletion of inbounds that are not currently available, enhancing inbound management capabilities. - Updated frontend API calls to reflect new query parameters and support for additional filtering options in the admin interface. - Revised API documentation to include new parameters and endpoint functionalities for better clarity and usage guidance.
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.CreateRoleChangeTopUp(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.RoleChangeTopUp,
|
|
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);
|
|
}
|
|
}
|