Files
PnvPanel/backend/tests/PnvPanel.Application.Tests/Admin/Inbounds/PublishInboundCommandHandlerTests.cs
T
mrleo1nidandClaude Opus 5.5 bb5e59904f
CI / Backend (build + test) (push) Failing after 1m36s
CI / Frontend (lint + typecheck + build) (push) Successful in 41s
Add inbound country flags and node load in location picker
- Inbound.CountryCode (ISO alpha-2), set on publish; flag shown before
  the location name (SVG via country-flag-icons on the site, emoji in bot)
- Node.Capacity (optional, not a limit); available inbounds report load
  percent of capacity or active config count, sorted least loaded first

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:45:17 +03:00

72 lines
2.6 KiB
C#

using NSubstitute;
using PnvPanel.Application.Admin.Inbounds;
using PnvPanel.Application.Common.Interfaces;
using PnvPanel.Application.Tests.TestSupport;
using PnvPanel.Domain.Inbounds;
using Xunit;
namespace PnvPanel.Application.Tests.Admin.Inbounds;
public class PublishInboundCommandHandlerTests
{
private readonly ICurrentUser _currentUser = Substitute.For<ICurrentUser>();
[Fact]
public async Task Handle_WhenPublishingExistingInbound_UpdatesPublishState()
{
using var dbContext = InMemoryDbContextFactory.Create();
var inbound = Inbound.FromRemote(Guid.NewGuid(), "1", VpnProtocol.Vless, "remark", 443);
dbContext.Inbounds.Add(inbound);
await dbContext.SaveChangesAsync(CancellationToken.None);
var roleId = Guid.NewGuid();
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
var command = new PublishInboundCommand(inbound.Id, true, "EU Fast", "de", [roleId]);
var result = await handler.Handle(command, CancellationToken.None);
Assert.True(result.IsSuccess);
Assert.True(inbound.IsPublished);
Assert.Equal("EU Fast", inbound.DisplayName);
Assert.Contains(roleId, inbound.AllowedRoleIds);
Assert.Equal("EU Fast", result.Value.DisplayName);
Assert.Equal("DE", inbound.CountryCode);
Assert.Equal("DE", result.Value.CountryCode);
}
[Fact]
public async Task Handle_WhenUnpublishing_ClearsPublishedFlag()
{
using var dbContext = InMemoryDbContextFactory.Create();
var inbound = Inbound.FromRemote(Guid.NewGuid(), "1", VpnProtocol.Vless, "remark", 443);
inbound.Publish("EU Fast", null, [Guid.NewGuid()]);
dbContext.Inbounds.Add(inbound);
await dbContext.SaveChangesAsync(CancellationToken.None);
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
var command = new PublishInboundCommand(inbound.Id, false, null, null, []);
var result = await handler.Handle(command, CancellationToken.None);
Assert.True(result.IsSuccess);
Assert.False(inbound.IsPublished);
}
[Fact]
public async Task Handle_WhenInboundNotFound_ReturnsNotFound()
{
using var dbContext = InMemoryDbContextFactory.Create();
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
var command = new PublishInboundCommand(Guid.NewGuid(), true, "EU Fast", null, []);
var result = await handler.Handle(command, CancellationToken.None);
Assert.False(result.IsSuccess);
Assert.Equal(InboundErrors.NotFound, result.Error);
}
}