From 1bff7bdc479df617d02079344c6fa27ffa024855 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Mon, 9 Nov 2020 23:41:29 -0600 Subject: [PATCH] Adding validation to ensure unified QR code works as expected --- BTCPayServer.Tests/UnitTest1.cs | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 4b032cc27..15a658d6a 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -1995,6 +1995,56 @@ namespace BTCPayServer.Tests } } + [Fact] + [Trait("Integration", "Integration")] + public async Task CanSetUnifiedQrCode() + { + using (var tester = ServerTester.Create()) + { + tester.ActivateLightning(); + await tester.StartAsync(); + await tester.EnsureChannelsSetup(); + var user = tester.NewAccount(); + user.GrantAccess(); + user.RegisterDerivationScheme("BTC"); + user.RegisterLightningNode("BTC", LightningConnectionType.CLightning); + + var invoice = user.BitPay.CreateInvoice( + new Invoice() + { + Price = 5.5m, + Currency = "USD", + PosData = "posData", + OrderId = "orderId", + ItemDesc = "Some description", + FullNotifications = true + }, Facade.Merchant); + + // validate that invoice data model doesn't have lightning string initially + var res = await user.GetController().Checkout(invoice.Id); + var paymentMethodFirst = Assert.IsType( + Assert.IsType(res).Model + ); + Assert.DoesNotContain("&lightning=", paymentMethodFirst.InvoiceBitcoinUrlQR); + + // enable unified QR code in settings + var vm = Assert.IsType(Assert + .IsType(user.GetController().CheckoutExperience()).Model + ); + vm.OnChainWithLnInvoiceFallback = true; + Assert.IsType( + user.GetController().CheckoutExperience(vm).Result + ); + + // validate that QR code now has both onchain and offchain payment urls + res = await user.GetController().Checkout(invoice.Id); + var paymentMethodSecond = Assert.IsType( + Assert.IsType(res).Model + ); + Assert.Contains("&lightning=", paymentMethodSecond.InvoiceBitcoinUrlQR); + } + } + [Fact(Timeout = 60 * 2 * 1000)] [Trait("Integration", "Integration")] [Trait("Lightning", "Lightning")]