- Removed the MaxClients property from Inbound-related data models, including InboundDto and PublishInboundCommand. - Updated related methods and handlers to reflect the removal of MaxClients, ensuring consistent behavior across the application. - Adjusted API documentation and frontend components to remove references to MaxClients, streamlining the inbound publishing process. - Enhanced logging in command handlers to handle node unavailability scenarios during user actions. - Improved database schema and migrations to align with the updated data model.
64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using PnvPanel.Domain.Inbounds;
|
|
using Xunit;
|
|
|
|
namespace PnvPanel.Domain.Tests.Inbounds;
|
|
|
|
public class InboundTests
|
|
{
|
|
[Fact]
|
|
public void FromRemote_CreatesUnpublishedInbound()
|
|
{
|
|
var nodeId = Guid.NewGuid();
|
|
|
|
var inbound = Inbound.FromRemote(nodeId, "12", VpnProtocol.Vless, "Germany", 443);
|
|
|
|
Assert.Equal(nodeId, inbound.NodeId);
|
|
Assert.Equal("12", inbound.RemoteInboundId);
|
|
Assert.Equal(VpnProtocol.Vless, inbound.Protocol);
|
|
Assert.Equal(443, inbound.Port);
|
|
Assert.False(inbound.IsPublished);
|
|
Assert.Empty(inbound.AllowedRoleIds);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateFromRemote_UpdatesFieldsAndLastSyncAt()
|
|
{
|
|
var inbound = Inbound.FromRemote(Guid.NewGuid(), "12", VpnProtocol.Vless, "Old", 443);
|
|
var before = inbound.LastSyncAt;
|
|
|
|
inbound.UpdateFromRemote(VpnProtocol.Trojan, "New", 8443);
|
|
|
|
Assert.Equal(VpnProtocol.Trojan, inbound.Protocol);
|
|
Assert.Equal("New", inbound.Remark);
|
|
Assert.Equal(8443, inbound.Port);
|
|
Assert.NotNull(inbound.LastSyncAt);
|
|
}
|
|
|
|
[Fact]
|
|
public void Publish_SetsDisplayNameAndRoles()
|
|
{
|
|
var inbound = Inbound.FromRemote(Guid.NewGuid(), "12", VpnProtocol.Vless, "Germany", 443);
|
|
var roleId = Guid.NewGuid();
|
|
|
|
inbound.Publish("Germany (VLESS)", [roleId, roleId]);
|
|
|
|
Assert.True(inbound.IsPublished);
|
|
Assert.Equal("Germany (VLESS)", inbound.DisplayName);
|
|
Assert.Single(inbound.AllowedRoleIds);
|
|
Assert.Contains(roleId, inbound.AllowedRoleIds);
|
|
}
|
|
|
|
[Fact]
|
|
public void Unpublish_SetsIsPublishedFalseButKeepsRoles()
|
|
{
|
|
var inbound = Inbound.FromRemote(Guid.NewGuid(), "12", VpnProtocol.Vless, "Germany", 443);
|
|
var roleId = Guid.NewGuid();
|
|
inbound.Publish("Germany", [roleId]);
|
|
|
|
inbound.Unpublish();
|
|
|
|
Assert.False(inbound.IsPublished);
|
|
Assert.Contains(roleId, inbound.AllowedRoleIds);
|
|
}
|
|
}
|