Implement discount tiers for pricing settings and enhance related functionalities
- Introduced a new `DiscountTierDto` to represent volume discount tiers, allowing roles with a config quota at or above specified thresholds to receive discounts on pricing. - Updated the `PricingSettingsDto` to include a list of discount tiers, enhancing the pricing model to support more flexible pricing strategies. - Modified the `GetPricingSettingsQueryHandler` and `UpdatePricingSettingsCommandHandler` to handle discount tiers, ensuring they are correctly retrieved and updated in the database. - Enhanced validation in `UpdatePricingSettingsCommandValidator` to enforce uniqueness and progressive discount tiers, preventing invalid configurations. - Updated frontend components to support the new discount tier functionality, including forms for adding and managing discount tiers in the admin interface. - Revised API documentation to reflect the new discount tier features and their usage in pricing settings.
This commit is contained in:
+32
@@ -65,6 +65,38 @@ public class CreatePaymentRequestCommandHandlerTests
|
||||
Assert.Equal(PaymentRequestStatus.AwaitingPayment, result.Value.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WithApplicableDiscountTier_AppliesDiscountToAmount()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
var userId = Guid.NewGuid();
|
||||
var pricing = PricingSettings.CreateDefault();
|
||||
pricing.Update(500, 450, 400);
|
||||
dbContext.PricingSettings.Add(pricing);
|
||||
dbContext.PricingDiscountTiers.Add(PricingDiscountTier.Create(pricing.Id, minConfigs: 3, discountPercent: 10));
|
||||
dbContext.PricingDiscountTiers.Add(PricingDiscountTier.Create(pricing.Id, minConfigs: 6, discountPercent: 20));
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
_identityService
|
||||
.GetProfileAsync(userId, Arg.Any<CancellationToken>())
|
||||
.Returns(Profile(userId, maxConfigs: 5));
|
||||
|
||||
var handler = new CreatePaymentRequestCommandHandler(
|
||||
dbContext,
|
||||
_identityService,
|
||||
FakeCurrentUser.Authenticated(userId)
|
||||
);
|
||||
|
||||
var result = await handler.Handle(
|
||||
new CreatePaymentRequestCommand(PaymentPeriod.Quarter),
|
||||
CancellationToken.None
|
||||
);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
// 500 * 5 * 3 = 7500, скидка 10% (порог 6 не достигнут при 5 конфигах) → 6750.
|
||||
Assert.Equal(6750, result.Value.AmountSnapshot);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenBillingNotEnabled_ReturnsNotEnabled()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user