using System.IO; using Paca.Mobile.Core; using Xunit; namespace Paca.Tests.Mobile; public class MobileQrPairingUiGateTests { private static readonly string SolutionRoot = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "..")); [Fact] public void Gate_QrPayloadCodec_Roundtrip_EnsuresIntegrity() { var original = new P2pQrPayload { Host = "192.168.1.100", Port = 52100, Token = "secret-token-xyz-12345", DeviceName = "MyDesktop-PC", Fingerprint = "fp-abc" }; var encoded = P2pQrPayloadCodec.Encode(original); Assert.NotNull(encoded); Assert.StartsWith("paca://pair?", encoded); var decoded = P2pQrPayloadCodec.Decode(encoded); Assert.NotNull(decoded); Assert.Equal(original.Host, decoded.Host); Assert.Equal(original.Port, decoded.Port); Assert.Equal(original.Token, decoded.Token); Assert.Equal(original.DeviceName, decoded.DeviceName); } [Fact] public void Gate_QrPayloadCodec_RejectsCorruptOrInvalidQr() { Assert.Throws(() => P2pQrPayloadCodec.Decode("")); Assert.Throws(() => P2pQrPayloadCodec.Decode("INVALID_QR_FORMAT")); Assert.Throws(() => P2pQrPayloadCodec.Decode("paca://pair?h=127.0.0.1&p=5000&t=tok&sig=wrong")); } [Fact] public void Gate_SyncSettingsPage_Contains_QrScanButton_And_CodecWiring() { var syncPagePath = Path.Combine(SolutionRoot, "src", "Paca.Mobile", "SyncSettingsPage.cs"); Assert.True(File.Exists(syncPagePath), $"SyncSettingsPage.cs not found at {syncPagePath}"); var code = File.ReadAllText(syncPagePath); Assert.True(code.Contains("P2pQrPayloadCodec.Decode") || code.Contains("P2pQrPayloadCodec"), "SyncSettingsPage.cs must wire P2pQrPayloadCodec to decode QR scan results"); Assert.True(code.Contains("QR") || code.Contains("Qr"), "SyncSettingsPage.cs must provide a QR Scan pairing interaction element"); } }