Add Telegram bot integration and enhance user management features
- Introduced Telegram.Bot package for bot functionality. - Updated user management to include Telegram linking and blocking features. - Enhanced activation request handling with notifications via Telegram. - Added new database entities for Telegram link tokens and login requests. - Implemented traffic synchronization for client stats in the XuiPanelGateway. - Updated application structure to support new test projects and improved dependency injection for Telegram services.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using PnvPanel.Application.Common.Interfaces;
|
||||
using Testcontainers.PostgreSql;
|
||||
using Xunit;
|
||||
|
||||
namespace PnvPanel.IntegrationTests.TestSupport;
|
||||
|
||||
/// <summary>
|
||||
/// Реальный Postgres через Testcontainers (не InMemory/Sqlite — нужно проверить Postgres-специфичное
|
||||
/// поведение: pg_advisory_xact_lock для квоты конфигов, uuid[]/jsonb колонки). Program.cs сам
|
||||
/// применяет миграции и сидит роли/админа при старте хоста — свежий контейнер становится полностью
|
||||
/// готовой БД без ручных шагов.
|
||||
/// </summary>
|
||||
public sealed class PnvPanelWebApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime
|
||||
{
|
||||
public const string AdminUserName = "test-admin";
|
||||
public const string AdminPassword = "TestAdmin123!";
|
||||
|
||||
private readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder()
|
||||
.WithImage("postgres:17-alpine")
|
||||
.WithDatabase("pnvpanel")
|
||||
.WithUsername("pnvpanel")
|
||||
.WithPassword("pnvpanel")
|
||||
.Build();
|
||||
|
||||
public async Task InitializeAsync() => await _postgres.StartAsync();
|
||||
|
||||
async Task IAsyncLifetime.DisposeAsync()
|
||||
{
|
||||
await _postgres.StopAsync();
|
||||
await base.DisposeAsync();
|
||||
}
|
||||
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.UseEnvironment("Development");
|
||||
|
||||
builder.ConfigureAppConfiguration((_, config) =>
|
||||
{
|
||||
config.AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["ConnectionStrings:Default"] = _postgres.GetConnectionString(),
|
||||
["AdminSeed:Username"] = AdminUserName,
|
||||
["AdminSeed:Password"] = AdminPassword,
|
||||
// Пусто — TelegramBotHostedService при пустом токене не стартует (см. Api/Telegram/TelegramBotHostedService.cs).
|
||||
["Telegram:BotToken"] = "",
|
||||
});
|
||||
});
|
||||
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
// Реальной панели 3x-ui в тестах нет — подменяем гейтвей заглушкой.
|
||||
services.RemoveAll<IXuiPanelGateway>();
|
||||
services.AddSingleton<IXuiPanelGateway, FakeXuiPanelGateway>();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user