- 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.
108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
using PnvPanel.Domain.Billing;
|
|
using PnvPanel.Domain.Pricing;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Domain.Tests.Billing;
|
|
|
|
public class PlanChangeTopUpTests
|
|
{
|
|
private static readonly DateTimeOffset Now = new(2026, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
|
|
|
[Fact]
|
|
public void Compute_WhenNewPlanCheaper_ReturnsNull()
|
|
{
|
|
var amount = PlanChangeTopUp.Compute(
|
|
pricePerConfigPerMonth: 200,
|
|
oldConfigCount: 10,
|
|
newConfigCount: 3,
|
|
discountTiers: [],
|
|
paidUntil: Now.AddDays(30),
|
|
now: Now
|
|
);
|
|
|
|
Assert.Null(amount);
|
|
}
|
|
|
|
[Fact]
|
|
public void Compute_WhenPaidUntilAlreadyExpired_ReturnsNull()
|
|
{
|
|
var amount = PlanChangeTopUp.Compute(
|
|
pricePerConfigPerMonth: 200,
|
|
oldConfigCount: 3,
|
|
newConfigCount: 10,
|
|
discountTiers: [],
|
|
paidUntil: Now.AddDays(-1),
|
|
now: Now
|
|
);
|
|
|
|
Assert.Null(amount);
|
|
}
|
|
|
|
[Fact]
|
|
public void Compute_WhenEitherCountUnlimited_ReturnsNull()
|
|
{
|
|
var amount = PlanChangeTopUp.Compute(
|
|
pricePerConfigPerMonth: 200,
|
|
oldConfigCount: 3,
|
|
newConfigCount: -1,
|
|
discountTiers: [],
|
|
paidUntil: Now.AddDays(30),
|
|
now: Now
|
|
);
|
|
|
|
Assert.Null(amount);
|
|
}
|
|
|
|
[Fact]
|
|
public void Compute_WhenUpgrading_ReturnsProratedDifference()
|
|
{
|
|
// Старый тариф: 200 * 3 = 600 ₽/мес. Новый: 200 * 10 = 2000 ₽/мес. Разница 1400 ₽/мес,
|
|
// за 30 дней (ровно месяц) — 1400 ₽.
|
|
var amount = PlanChangeTopUp.Compute(
|
|
pricePerConfigPerMonth: 200,
|
|
oldConfigCount: 3,
|
|
newConfigCount: 10,
|
|
discountTiers: [],
|
|
paidUntil: Now.AddDays(30),
|
|
now: Now
|
|
);
|
|
|
|
Assert.Equal(1400, amount);
|
|
}
|
|
|
|
[Fact]
|
|
public void Compute_ProratesToRemainingDaysOnly()
|
|
{
|
|
// Та же разница 1400 ₽/мес, но остаётся только 15 из 30 дней — половина.
|
|
var amount = PlanChangeTopUp.Compute(
|
|
pricePerConfigPerMonth: 200,
|
|
oldConfigCount: 3,
|
|
newConfigCount: 10,
|
|
discountTiers: [],
|
|
paidUntil: Now.AddDays(15),
|
|
now: Now
|
|
);
|
|
|
|
Assert.Equal(700, amount);
|
|
}
|
|
|
|
[Fact]
|
|
public void Compute_AppliesDiscountTiersToBothCounts()
|
|
{
|
|
var tiers = new[] { PricingDiscountTier.Create(Guid.NewGuid(), minConfigs: 10, discountPercent: 10) };
|
|
|
|
// Старый тариф (3 конфига, без скидки): 200*3 = 600. Новый (10 конфигов, порог скидки достигнут):
|
|
// 200*10 = 2000, -10% = 1800. Разница 1200 ₽/мес, за 30 дней — 1200 ₽.
|
|
var amount = PlanChangeTopUp.Compute(
|
|
pricePerConfigPerMonth: 200,
|
|
oldConfigCount: 3,
|
|
newConfigCount: 10,
|
|
discountTiers: tiers,
|
|
paidUntil: Now.AddDays(30),
|
|
now: Now
|
|
);
|
|
|
|
Assert.Equal(1200, amount);
|
|
}
|
|
}
|