Enhance user plan management and update related endpoints
- 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.
This commit is contained in:
+24
-24
@@ -4,17 +4,17 @@ using Xunit;
|
||||
|
||||
namespace PnvPanel.Domain.Tests.Billing;
|
||||
|
||||
public class RoleChangeTopUpTests
|
||||
public class PlanChangeTopUpTests
|
||||
{
|
||||
private static readonly DateTimeOffset Now = new(2026, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
|
||||
[Fact]
|
||||
public void Compute_WhenNewRoleCheaper_ReturnsNull()
|
||||
public void Compute_WhenNewPlanCheaper_ReturnsNull()
|
||||
{
|
||||
var amount = RoleChangeTopUp.Compute(
|
||||
var amount = PlanChangeTopUp.Compute(
|
||||
pricePerConfigPerMonth: 200,
|
||||
oldMaxConfigs: 10,
|
||||
newMaxConfigs: 3,
|
||||
oldConfigCount: 10,
|
||||
newConfigCount: 3,
|
||||
discountTiers: [],
|
||||
paidUntil: Now.AddDays(30),
|
||||
now: Now
|
||||
@@ -26,10 +26,10 @@ public class RoleChangeTopUpTests
|
||||
[Fact]
|
||||
public void Compute_WhenPaidUntilAlreadyExpired_ReturnsNull()
|
||||
{
|
||||
var amount = RoleChangeTopUp.Compute(
|
||||
var amount = PlanChangeTopUp.Compute(
|
||||
pricePerConfigPerMonth: 200,
|
||||
oldMaxConfigs: 3,
|
||||
newMaxConfigs: 10,
|
||||
oldConfigCount: 3,
|
||||
newConfigCount: 10,
|
||||
discountTiers: [],
|
||||
paidUntil: Now.AddDays(-1),
|
||||
now: Now
|
||||
@@ -39,12 +39,12 @@ public class RoleChangeTopUpTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Compute_WhenEitherRoleUnlimited_ReturnsNull()
|
||||
public void Compute_WhenEitherCountUnlimited_ReturnsNull()
|
||||
{
|
||||
var amount = RoleChangeTopUp.Compute(
|
||||
var amount = PlanChangeTopUp.Compute(
|
||||
pricePerConfigPerMonth: 200,
|
||||
oldMaxConfigs: 3,
|
||||
newMaxConfigs: -1,
|
||||
oldConfigCount: 3,
|
||||
newConfigCount: -1,
|
||||
discountTiers: [],
|
||||
paidUntil: Now.AddDays(30),
|
||||
now: Now
|
||||
@@ -56,12 +56,12 @@ public class RoleChangeTopUpTests
|
||||
[Fact]
|
||||
public void Compute_WhenUpgrading_ReturnsProratedDifference()
|
||||
{
|
||||
// Старая роль: 200 * 3 = 600 ₽/мес. Новая: 200 * 10 = 2000 ₽/мес. Разница 1400 ₽/мес,
|
||||
// Старый тариф: 200 * 3 = 600 ₽/мес. Новый: 200 * 10 = 2000 ₽/мес. Разница 1400 ₽/мес,
|
||||
// за 30 дней (ровно месяц) — 1400 ₽.
|
||||
var amount = RoleChangeTopUp.Compute(
|
||||
var amount = PlanChangeTopUp.Compute(
|
||||
pricePerConfigPerMonth: 200,
|
||||
oldMaxConfigs: 3,
|
||||
newMaxConfigs: 10,
|
||||
oldConfigCount: 3,
|
||||
newConfigCount: 10,
|
||||
discountTiers: [],
|
||||
paidUntil: Now.AddDays(30),
|
||||
now: Now
|
||||
@@ -74,10 +74,10 @@ public class RoleChangeTopUpTests
|
||||
public void Compute_ProratesToRemainingDaysOnly()
|
||||
{
|
||||
// Та же разница 1400 ₽/мес, но остаётся только 15 из 30 дней — половина.
|
||||
var amount = RoleChangeTopUp.Compute(
|
||||
var amount = PlanChangeTopUp.Compute(
|
||||
pricePerConfigPerMonth: 200,
|
||||
oldMaxConfigs: 3,
|
||||
newMaxConfigs: 10,
|
||||
oldConfigCount: 3,
|
||||
newConfigCount: 10,
|
||||
discountTiers: [],
|
||||
paidUntil: Now.AddDays(15),
|
||||
now: Now
|
||||
@@ -87,16 +87,16 @@ public class RoleChangeTopUpTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Compute_AppliesDiscountTiersToBothRoles()
|
||||
public void Compute_AppliesDiscountTiersToBothCounts()
|
||||
{
|
||||
var tiers = new[] { PricingDiscountTier.Create(Guid.NewGuid(), minConfigs: 10, discountPercent: 10) };
|
||||
|
||||
// Старая роль (3 конфига, без скидки): 200*3 = 600. Новая (10 конфигов, порог скидки достигнут):
|
||||
// Старый тариф (3 конфига, без скидки): 200*3 = 600. Новый (10 конфигов, порог скидки достигнут):
|
||||
// 200*10 = 2000, -10% = 1800. Разница 1200 ₽/мес, за 30 дней — 1200 ₽.
|
||||
var amount = RoleChangeTopUp.Compute(
|
||||
var amount = PlanChangeTopUp.Compute(
|
||||
pricePerConfigPerMonth: 200,
|
||||
oldMaxConfigs: 3,
|
||||
newMaxConfigs: 10,
|
||||
oldConfigCount: 3,
|
||||
newConfigCount: 10,
|
||||
discountTiers: tiers,
|
||||
paidUntil: Now.AddDays(30),
|
||||
now: Now
|
||||
Reference in New Issue
Block a user