diff --git a/BTCPayServer.Tests/CheckoutUITests.cs b/BTCPayServer.Tests/CheckoutUITests.cs index 18bfd3c2b..63dd18652 100644 --- a/BTCPayServer.Tests/CheckoutUITests.cs +++ b/BTCPayServer.Tests/CheckoutUITests.cs @@ -103,6 +103,28 @@ namespace BTCPayServer.Tests } } + [Fact(Timeout = TestTimeout)] + [Trait("Lightning", "Lightning")] + public async Task CanSetDefaultPaymentMethod() + { + using (var s = SeleniumTester.Create()) + { + s.Server.ActivateLightning(); + await s.StartAsync(); + s.GoToRegister(); + s.RegisterNewUser(true); + var store = s.CreateNewStore(); + s.AddLightningNode(); + s.AddDerivationScheme("BTC"); + + var invoiceId = s.CreateInvoice(store.storeName, defaultPaymentMethod: "BTC_LightningLike"); + s.GoToInvoiceCheckout(invoiceId); + + Assert.Equal("Bitcoin (Lightning) (BTC)", s.Driver.FindElement(By.ClassName("payment__currencies")).Text); + s.Driver.Quit(); + } + } + [Fact(Timeout = TestTimeout)] [Trait("Lightning", "Lightning")] public async Task CanUseLightningSatsFeature() diff --git a/BTCPayServer.Tests/GreenfieldAPITests.cs b/BTCPayServer.Tests/GreenfieldAPITests.cs index 18e51ba6f..33bc8b93c 100644 --- a/BTCPayServer.Tests/GreenfieldAPITests.cs +++ b/BTCPayServer.Tests/GreenfieldAPITests.cs @@ -1289,6 +1289,32 @@ namespace BTCPayServer.Tests paymentMethods = await client.GetInvoicePaymentMethods(store.Id, invoice.Id); Assert.Single(paymentMethods); Assert.True(paymentMethods.First().Activated); + + var invoiceWithdefaultPaymentMethodLN = await client.CreateInvoice(user.StoreId, + new CreateInvoiceRequest() + { + Currency = "USD", + Amount = 100, + Checkout = new CreateInvoiceRequest.CheckoutOptions() + { + PaymentMethods = new[] { "BTC", "BTC-LightningNetwork" }, + DefaultPaymentMethod = "BTC_LightningLike" + } + }); + Assert.Equal("BTC_LightningLike", invoiceWithdefaultPaymentMethodLN.Checkout.DefaultPaymentMethod); + + var invoiceWithdefaultPaymentMethodOnChain = await client.CreateInvoice(user.StoreId, + new CreateInvoiceRequest() + { + Currency = "USD", + Amount = 100, + Checkout = new CreateInvoiceRequest.CheckoutOptions() + { + PaymentMethods = new[] { "BTC", "BTC-LightningNetwork" }, + DefaultPaymentMethod = "BTC" + } + }); + Assert.Equal("BTC", invoiceWithdefaultPaymentMethodOnChain.Checkout.DefaultPaymentMethod); } } diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index 354ce7123..2bd76d84d 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -332,7 +332,13 @@ namespace BTCPayServer.Tests Driver.Navigate().GoToUrl(new Uri(Server.PayTester.ServerUri, "/login")); } - public string CreateInvoice(string storeName, decimal? amount = 100, string currency = "USD", string refundEmail = "") + public string CreateInvoice( + string storeName, + decimal? amount = 100, + string currency = "USD", + string refundEmail = "", + string defaultPaymentMethod = "BTC" + ) { GoToInvoices(); Driver.FindElement(By.Id("CreateNewInvoice")).Click(); @@ -343,6 +349,7 @@ namespace BTCPayServer.Tests currencyEl.SendKeys(currency); Driver.FindElement(By.Id("BuyerEmail")).SendKeys(refundEmail); Driver.FindElement(By.Name("StoreId")).SendKeys(storeName); + Driver.FindElement(By.Name("DefaultPaymentMethod")).SendKeys(defaultPaymentMethod); Driver.FindElement(By.Id("Create")).Click(); var statusElement = FindAlertMessage();