Enhance user plan management and update related endpoints
CI / Backend (build + test) (push) Failing after 1m23s
CI / Frontend (lint + typecheck + build) (push) Successful in 34s

- 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:
Leonid Pershin
2026-07-23 22:52:20 +03:00
parent 2c5b730500
commit fad03c2834
152 changed files with 4060 additions and 2240 deletions
@@ -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
@@ -0,0 +1,31 @@
using PnvPanel.Domain.Plans;
using Xunit;
namespace PnvPanel.Domain.Tests.Plans;
public class PlanTests
{
[Fact]
public void Create_SetsFieldsAndEnablesByDefault()
{
var plan = Plan.Create("Стандарт", 3, 0);
Assert.Equal("Стандарт", plan.Name);
Assert.Equal(3, plan.ConfigCount);
Assert.Equal(0, plan.SortOrder);
Assert.True(plan.IsEnabled);
}
[Fact]
public void Update_ChangesFieldsIncludingIsEnabled()
{
var plan = Plan.Create("Стандарт", 3, 0);
plan.Update("Плюс", 6, 1, false);
Assert.Equal("Плюс", plan.Name);
Assert.Equal(6, plan.ConfigCount);
Assert.Equal(1, plan.SortOrder);
Assert.False(plan.IsEnabled);
}
}
@@ -16,33 +16,7 @@ public class SupportTicketTests
Assert.Equal(userId, ticket.UserId);
Assert.Equal(TicketType.BugReport, ticket.Type);
Assert.Equal(TicketStatus.Open, ticket.Status);
Assert.Null(ticket.RequestedRoleId);
Assert.Null(ticket.ProposedRoleName);
}
[Fact]
public void CreateRoleRequestForExistingRole_SetsRequestedRoleId()
{
var userId = Guid.NewGuid();
var roleId = Guid.NewGuid();
var ticket = SupportTicket.CreateRoleRequestForExistingRole(userId, roleId);
Assert.Equal(TicketType.RoleRequest, ticket.Type);
Assert.Equal(roleId, ticket.RequestedRoleId);
Assert.Null(ticket.ProposedRoleName);
}
[Fact]
public void CreateRoleRequestForNewRole_SetsProposedFields()
{
var ticket = SupportTicket.CreateRoleRequestForNewRole(Guid.NewGuid(), "premium", 5, 3);
Assert.Equal(TicketType.RoleRequest, ticket.Type);
Assert.Null(ticket.RequestedRoleId);
Assert.Equal("premium", ticket.ProposedRoleName);
Assert.Equal(5, ticket.ProposedMaxConfigs);
Assert.Equal(3, ticket.ProposedMaxIpLimit);
Assert.Null(ticket.RequestedDays);
}
[Fact]
@@ -56,8 +30,6 @@ public class SupportTicketTests
Assert.Equal(TicketType.ExtensionRequest, ticket.Type);
Assert.Equal(TicketStatus.Open, ticket.Status);
Assert.Equal(14, ticket.RequestedDays);
Assert.Null(ticket.RequestedRoleId);
Assert.Null(ticket.ProposedRoleName);
}
[Fact]