Files
PnvPanel/backend/tests/PnvPanel.Domain.Tests/Inbounds/InboundTests.cs
T
Leonid Pershin b980dc6cef
CI / Backend (build + test) (push) Successful in 1m19s
CI / Frontend (lint + typecheck + build) (push) Successful in 35s
Add IsAvailable property to Inbound and update related logic
- Introduced a new boolean property, `IsAvailable`, to the `Inbound` entity to track the availability status of inbounds based on synchronization results.
- Updated the `SyncNodeCommandHandler` to mark inbounds as unavailable if they are not present in the latest synchronization but have existing configurations, preventing their deletion.
- Enhanced the `MarkUnavailable` method to set both `IsAvailable` and `IsPublished` to false, reflecting the new status accurately.
- Modified the frontend components to display the availability status of inbounds, ensuring users are informed of their current state.
- Updated tests to cover the new behavior regarding inbound availability and its impact on revocation processes.
2026-07-19 00:13:30 +03:00

84 lines
2.5 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);
}
[Fact]
public void FromRemote_CreatesAvailableInbound()
{
var inbound = Inbound.FromRemote(Guid.NewGuid(), "12", VpnProtocol.Vless, "Germany", 443);
Assert.True(inbound.IsAvailable);
}
[Fact]
public void MarkUnavailable_SetsIsAvailableAndIsPublishedFalse()
{
var inbound = Inbound.FromRemote(Guid.NewGuid(), "12", VpnProtocol.Vless, "Germany", 443);
inbound.Publish("Germany", [Guid.NewGuid()]);
inbound.MarkUnavailable();
Assert.False(inbound.IsAvailable);
Assert.False(inbound.IsPublished);
}
}