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:
+40
@@ -0,0 +1,40 @@
|
||||
using PnvPanel.Application.Auth;
|
||||
using PnvPanel.Application.Telegram;
|
||||
using PnvPanel.Application.Tests.TestSupport;
|
||||
using Xunit;
|
||||
|
||||
namespace PnvPanel.Application.Tests.Telegram;
|
||||
|
||||
public class CreateLinkTokenCommandHandlerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Handle_WhenAuthenticated_CreatesTokenAndAddsToDbContext()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
var userId = Guid.NewGuid();
|
||||
|
||||
var handler = new CreateLinkTokenCommandHandler(dbContext, FakeCurrentUser.Authenticated(userId));
|
||||
|
||||
var result = await handler.Handle(new CreateLinkTokenCommand(), CancellationToken.None);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.False(string.IsNullOrEmpty(result.Value.Token));
|
||||
Assert.True(result.Value.ExpiresAt > DateTimeOffset.UtcNow);
|
||||
Assert.Single(dbContext.TelegramLinkTokens.Local);
|
||||
Assert.Equal(userId, dbContext.TelegramLinkTokens.Local.Single().UserId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_WhenNotAuthenticated_ReturnsUnauthorized()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
|
||||
var handler = new CreateLinkTokenCommandHandler(dbContext, FakeCurrentUser.Anonymous());
|
||||
|
||||
var result = await handler.Handle(new CreateLinkTokenCommand(), CancellationToken.None);
|
||||
|
||||
Assert.False(result.IsSuccess);
|
||||
Assert.Equal(AuthErrors.Unauthorized, result.Error);
|
||||
Assert.Empty(dbContext.TelegramLinkTokens.Local);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user