- 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.5 KiB
C#
82 lines
3.5 KiB
C#
using NSubstitute;
|
|
using PnvPanel.Application.Admin.Users;
|
|
using PnvPanel.Application.Common.Interfaces;
|
|
using PnvPanel.Application.Common.Models;
|
|
using PnvPanel.Application.Tests.TestSupport;
|
|
using PnvPanel.Domain.Billing;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Application.Tests.Admin.Users;
|
|
|
|
public class ListUsersQueryHandlerTests
|
|
{
|
|
private readonly IIdentityService _identityService = Substitute.For<IIdentityService>();
|
|
|
|
private static UserSummaryDto Summary(Guid id) =>
|
|
new(id, "alice", "premium", true, false, DateTimeOffset.UtcNow, true, DateTimeOffset.UtcNow.AddDays(-1));
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenUserHasAwaitingConfirmationSubscriptionRequest_SetsBillingPendingReview()
|
|
{
|
|
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);
|
|
|
|
_identityService
|
|
.ListUsersAsync(1, 20, null, null, null, null, null, Arg.Any<CancellationToken>())
|
|
.Returns(new PagedList<UserSummaryDto>([Summary(userId)], 1, 1, 20));
|
|
|
|
var handler = new ListUsersQueryHandler(_identityService, dbContext);
|
|
|
|
var result = await handler.Handle(new ListUsersQuery(1, 20, null, null, null, null, null), CancellationToken.None);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.True(result.Value.Items.Single().BillingPendingReview);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenNoPendingRequest_LeavesBillingPendingReviewFalse()
|
|
{
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
|
|
_identityService
|
|
.ListUsersAsync(1, 20, null, null, null, null, null, Arg.Any<CancellationToken>())
|
|
.Returns(new PagedList<UserSummaryDto>([Summary(userId)], 1, 1, 20));
|
|
|
|
var handler = new ListUsersQueryHandler(_identityService, dbContext);
|
|
|
|
var result = await handler.Handle(new ListUsersQuery(1, 20, null, null, null, null, null), CancellationToken.None);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.False(result.Value.Items.Single().BillingPendingReview);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handle_WhenPendingRequestIsRoleChangeTopUp_LeavesBillingPendingReviewFalse()
|
|
{
|
|
// RoleChangeTopUp — доплата за смену роли, не подписка; не должна показывать пользователя
|
|
// как "оплата на проверке" в админке (см. CLAUDE.md про Kind).
|
|
using var dbContext = InMemoryDbContextFactory.Create();
|
|
var userId = Guid.NewGuid();
|
|
var request = PaymentRequest.CreateRoleChangeTopUp(userId, 500);
|
|
request.MarkPaymentSent();
|
|
dbContext.PaymentRequests.Add(request);
|
|
await dbContext.SaveChangesAsync(CancellationToken.None);
|
|
|
|
_identityService
|
|
.ListUsersAsync(1, 20, null, null, null, null, null, Arg.Any<CancellationToken>())
|
|
.Returns(new PagedList<UserSummaryDto>([Summary(userId)], 1, 1, 20));
|
|
|
|
var handler = new ListUsersQueryHandler(_identityService, dbContext);
|
|
|
|
var result = await handler.Handle(new ListUsersQuery(1, 20, null, null, null, null, null), CancellationToken.None);
|
|
|
|
Assert.True(result.IsSuccess);
|
|
Assert.False(result.Value.Items.Single().BillingPendingReview);
|
|
}
|
|
}
|