diff --git a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs index 63cbea66b..c95890567 100644 --- a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs +++ b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs @@ -11,6 +11,8 @@ using BTCPayServer.Models.AppViewModels; using BTCPayServer.Models.StoreViewModels; using BTCPayServer.Models.WalletViewModels; using BTCPayServer.Payments; +using BTCPayServer.Plugins.PointOfSale.Controllers; +using BTCPayServer.Plugins.PointOfSale.Models; using BTCPayServer.Services.Apps; using Microsoft.AspNetCore.Mvc; using NBitcoin; @@ -617,6 +619,7 @@ namespace BTCPayServer.Tests user.RegisterDerivationScheme("BTC"); user.RegisterDerivationScheme("LTC"); var apps = user.GetController(); + var pos = user.GetController(); var vm = Assert.IsType(Assert.IsType(apps.CreateApp(user.StoreId)).Model); var appType = AppType.PointOfSale.ToString(); vm.AppName = "test"; @@ -624,8 +627,10 @@ namespace BTCPayServer.Tests Assert.IsType(apps.CreateApp(user.StoreId, vm).Result); var appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); var app = appList.Apps[0]; - apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }); - var vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + var appData = new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }; + apps.HttpContext.SetAppData(appData); + pos.HttpContext.SetAppData(appData); + var vmpos = await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Title = "hello"; vmpos.Currency = "CAD"; vmpos.ButtonText = "{0} Purchase"; @@ -642,8 +647,8 @@ donation: price: 1.02 custom: true "; - Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); - vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + Assert.IsType(pos.UpdatePointOfSale(app.Id, vmpos).Result); + vmpos = await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); Assert.Equal("hello", vmpos.Title); var publicApps = user.GetController(); @@ -698,7 +703,7 @@ donation: }) { TestLogs.LogInformation($"Testing for {test.Code}"); - vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + vmpos = await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Title = "hello"; vmpos.Currency = test.Item1; vmpos.ButtonText = "{0} Purchase"; @@ -714,7 +719,7 @@ donation: price: 1.02 custom: true "; - Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); + Assert.IsType(pos.UpdatePointOfSale(app.Id, vmpos).Result); publicApps = user.GetController(); vmview = await publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).AssertViewModelAsync(); Assert.Equal(test.Code, vmview.CurrencyCode); @@ -731,7 +736,7 @@ donation: } //test inventory related features - vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + vmpos = await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Title = "hello"; vmpos.Currency = "BTC"; vmpos.Template = @" @@ -741,7 +746,7 @@ inventoryitem: inventory: 1 noninventoryitem: price: 10.0"; - Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); + Assert.IsType(pos.UpdatePointOfSale(app.Id, vmpos).Result); //inventoryitem has 1 item available await tester.WaitForEvent(() => @@ -777,13 +782,13 @@ noninventoryitem: //check that item is back in stock await TestUtils.EventuallyAsync(async () => { - vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + vmpos = await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); Assert.Equal(1, appService.Parse(vmpos.Template, "BTC").Single(item => item.Id == "inventoryitem").Inventory); }, 10000); //test payment methods option - vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + vmpos = await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Title = "hello"; vmpos.Currency = "BTC"; vmpos.Template = @" @@ -794,7 +799,7 @@ btconly: - BTC normal: price: 1.0"; - Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); + Assert.IsType(pos.UpdatePointOfSale(app.Id, vmpos).Result); Assert.IsType(publicApps .ViewPointOfSale(app.Id, PosViewType.Cart, 1, null, null, null, null, "btconly").Result); Assert.IsType(publicApps @@ -838,8 +843,8 @@ g: custom: topup "; - Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); - vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + Assert.IsType(pos.UpdatePointOfSale(app.Id, vmpos).Result); + vmpos = await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); Assert.DoesNotContain("custom", vmpos.Template); var items = appService.Parse(vmpos.Template, vmpos.Currency); Assert.Contains(items, item => item.Id == "a" && item.Price.Type == ViewPointOfSaleViewModel.Item.ItemPrice.ItemPriceType.Fixed); diff --git a/BTCPayServer.Tests/CrowdfundTests.cs b/BTCPayServer.Tests/CrowdfundTests.cs index 64d8d3060..e8904ec2c 100644 --- a/BTCPayServer.Tests/CrowdfundTests.cs +++ b/BTCPayServer.Tests/CrowdfundTests.cs @@ -4,6 +4,8 @@ using BTCPayServer.Client.Models; using BTCPayServer.Controllers; using BTCPayServer.Data; using BTCPayServer.Models.AppViewModels; +using BTCPayServer.Plugins.Crowdfund.Controllers; +using BTCPayServer.Plugins.Crowdfund.Models; using BTCPayServer.Services.Apps; using BTCPayServer.Services.Invoices; using BTCPayServer.Tests.Logging; @@ -35,6 +37,7 @@ namespace BTCPayServer.Tests var stores = user.GetController(); var apps = user.GetController(); var apps2 = user2.GetController(); + var crowdfund = user.GetController(); var vm = Assert.IsType(Assert.IsType(apps.CreateApp(user.StoreId)).Model); var appType = AppType.Crowdfund.ToString(); Assert.NotNull(vm.SelectedAppType); @@ -42,10 +45,12 @@ namespace BTCPayServer.Tests vm.AppName = "test"; vm.SelectedAppType = appType; var redirectToAction = Assert.IsType(apps.CreateApp(user.StoreId, vm).Result); - Assert.Equal(nameof(apps.UpdateCrowdfund), redirectToAction.ActionName); + Assert.Equal(nameof(crowdfund.UpdateCrowdfund), redirectToAction.ActionName); var appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); var app = appList.Apps[0]; - apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType}); + var appData = new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }; + apps.HttpContext.SetAppData(appData); + crowdfund.HttpContext.SetAppData(appData); var appList2 = Assert.IsType(Assert.IsType(apps2.ListApps(user2.StoreId).Result).Model); Assert.Single(appList.Apps); @@ -72,6 +77,7 @@ namespace BTCPayServer.Tests await user.GrantAccessAsync(); user.RegisterDerivationScheme("BTC"); var apps = user.GetController(); + var crowdfund = user.GetController(); var vm = apps.CreateApp(user.StoreId).AssertViewModel(); var appType = AppType.Crowdfund.ToString(); vm.AppName = "test"; @@ -79,15 +85,17 @@ namespace BTCPayServer.Tests Assert.IsType(apps.CreateApp(user.StoreId, vm).Result); var appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); var app = appList.Apps[0]; - apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }); + var appData = new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }; + apps.HttpContext.SetAppData(appData); + crowdfund.HttpContext.SetAppData(appData); //Scenario 1: Not Enabled - Not Allowed - var crowdfundViewModel = await apps.UpdateCrowdfund(app.Id).AssertViewModelAsync(); + var crowdfundViewModel = await crowdfund.UpdateCrowdfund(app.Id).AssertViewModelAsync(); crowdfundViewModel.TargetCurrency = "BTC"; crowdfundViewModel.Enabled = false; crowdfundViewModel.EndDate = null; - Assert.IsType(apps.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); + Assert.IsType(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); var anonAppPubsController = tester.PayTester.GetController(); var publicApps = user.GetController(); @@ -112,7 +120,7 @@ namespace BTCPayServer.Tests crowdfundViewModel.StartDate = DateTime.Today.AddDays(2); crowdfundViewModel.Enabled = true; - Assert.IsType(apps.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); + Assert.IsType(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); Assert.IsType(await anonAppPubsController.ContributeToCrowdfund(app.Id, new ContributeToCrowdfund() { Amount = new decimal(0.01) @@ -123,7 +131,7 @@ namespace BTCPayServer.Tests crowdfundViewModel.EndDate = DateTime.Today.AddDays(-1); crowdfundViewModel.Enabled = true; - Assert.IsType(apps.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); + Assert.IsType(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); Assert.IsType(await anonAppPubsController.ContributeToCrowdfund(app.Id, new ContributeToCrowdfund() { Amount = new decimal(0.01) @@ -136,7 +144,7 @@ namespace BTCPayServer.Tests crowdfundViewModel.TargetAmount = 1; crowdfundViewModel.TargetCurrency = "BTC"; crowdfundViewModel.EnforceTargetAmount = true; - Assert.IsType(apps.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); + Assert.IsType(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); Assert.IsType(await anonAppPubsController.ContributeToCrowdfund(app.Id, new ContributeToCrowdfund() { Amount = new decimal(1.01) @@ -160,6 +168,7 @@ namespace BTCPayServer.Tests user.RegisterDerivationScheme("BTC"); await user.SetNetworkFeeMode(NetworkFeeMode.Never); var apps = user.GetController(); + var crowdfund = user.GetController(); var vm = Assert.IsType(Assert.IsType(apps.CreateApp(user.StoreId)).Model); var appType = AppType.Crowdfund.ToString(); vm.AppName = "test"; @@ -167,17 +176,19 @@ namespace BTCPayServer.Tests Assert.IsType(apps.CreateApp(user.StoreId, vm).Result); var appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); var app = appList.Apps[0]; - apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }); + var appData = new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }; + apps.HttpContext.SetAppData(appData); + crowdfund.HttpContext.SetAppData(appData); TestLogs.LogInformation("We create an invoice with a hardcap"); - var crowdfundViewModel = await apps.UpdateCrowdfund(app.Id).AssertViewModelAsync(); + var crowdfundViewModel = await crowdfund.UpdateCrowdfund(app.Id).AssertViewModelAsync(); crowdfundViewModel.Enabled = true; crowdfundViewModel.EndDate = null; crowdfundViewModel.TargetAmount = 100; crowdfundViewModel.TargetCurrency = "BTC"; crowdfundViewModel.UseAllStoreInvoices = true; crowdfundViewModel.EnforceTargetAmount = true; - Assert.IsType(apps.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); + Assert.IsType(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); var anonAppPubsController = tester.PayTester.GetController(); var publicApps = user.GetController(); @@ -232,7 +243,7 @@ namespace BTCPayServer.Tests Assert.Contains(AppService.GetAppInternalTag(app.Id), invoiceEntity.InternalTags); crowdfundViewModel.UseAllStoreInvoices = false; - Assert.IsType(apps.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); + Assert.IsType(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); TestLogs.LogInformation("Because UseAllStoreInvoices is false, let's make sure the invoice is not tagged"); invoice = await user.BitPay.CreateInvoiceAsync(new Invoice @@ -251,7 +262,7 @@ namespace BTCPayServer.Tests TestLogs.LogInformation("After turning setting a softcap, let's check that only actual payments are counted"); crowdfundViewModel.EnforceTargetAmount = false; crowdfundViewModel.UseAllStoreInvoices = true; - Assert.IsType(apps.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); + Assert.IsType(crowdfund.UpdateCrowdfund(app.Id, crowdfundViewModel, "save").Result); invoice = await user.BitPay.CreateInvoiceAsync(new Invoice { Buyer = new Buyer { email = "test@fwf.com" }, diff --git a/BTCPayServer.Tests/POSTests.cs b/BTCPayServer.Tests/POSTests.cs index 351221580..33f620556 100644 --- a/BTCPayServer.Tests/POSTests.cs +++ b/BTCPayServer.Tests/POSTests.cs @@ -2,6 +2,8 @@ using System.Threading.Tasks; using BTCPayServer.Controllers; using BTCPayServer.Data; using BTCPayServer.Models.AppViewModels; +using BTCPayServer.Plugins.PointOfSale.Controllers; +using BTCPayServer.Plugins.PointOfSale.Models; using BTCPayServer.Services.Apps; using BTCPayServer.Tests.Logging; using Microsoft.AspNetCore.Mvc; @@ -28,6 +30,7 @@ namespace BTCPayServer.Tests await user.GrantAccessAsync(); user.RegisterDerivationScheme("BTC"); var apps = user.GetController(); + var pos = user.GetController(); var vm = Assert.IsType(Assert.IsType(apps.CreateApp(user.StoreId)).Model); var appType = AppType.PointOfSale.ToString(); vm.AppName = "test"; @@ -35,8 +38,10 @@ namespace BTCPayServer.Tests Assert.IsType(apps.CreateApp(user.StoreId, vm).Result); var appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); var app = appList.Apps[0]; - apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }); - var vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + var appData = new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }; + apps.HttpContext.SetAppData(appData); + pos.HttpContext.SetAppData(appData); + var vmpos = await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); vmpos.Template = @" apple: price: 5.0 @@ -48,8 +53,8 @@ donation: price: 1.02 custom: true "; - Assert.IsType(apps.UpdatePointOfSale(app.Id, vmpos).Result); - vmpos = await apps.UpdatePointOfSale(app.Id).AssertViewModelAsync(); + Assert.IsType(pos.UpdatePointOfSale(app.Id, vmpos).Result); + await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync(); var publicApps = user.GetController(); var vmview = await publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).AssertViewModelAsync(); diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index b0c93b328..f19e7a11a 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -35,6 +35,7 @@ using BTCPayServer.Payments; using BTCPayServer.Payments.Bitcoin; using BTCPayServer.Payments.Lightning; using BTCPayServer.Payments.PayJoin.Sender; +using BTCPayServer.Plugins.PointOfSale.Controllers; using BTCPayServer.Security.Bitpay; using BTCPayServer.Services; using BTCPayServer.Services.Apps; @@ -1953,6 +1954,7 @@ namespace BTCPayServer.Tests var stores = user.GetController(); var apps = user.GetController(); var apps2 = user2.GetController(); + var pos = user.GetController(); var vm = Assert.IsType(Assert.IsType(apps.CreateApp(user.StoreId)).Model); var appType = AppType.PointOfSale.ToString(); Assert.NotNull(vm.SelectedAppType); @@ -1960,12 +1962,14 @@ namespace BTCPayServer.Tests vm.AppName = "test"; vm.SelectedAppType = appType; var redirectToAction = Assert.IsType(apps.CreateApp(user.StoreId, vm).Result); - Assert.Equal(nameof(apps.UpdatePointOfSale), redirectToAction.ActionName); + Assert.Equal(nameof(pos.UpdatePointOfSale), redirectToAction.ActionName); var appList = Assert.IsType(Assert.IsType(apps.ListApps(user.StoreId).Result).Model); var appList2 = Assert.IsType(Assert.IsType(apps2.ListApps(user2.StoreId).Result).Model); var app = appList.Apps[0]; - apps.HttpContext.SetAppData(new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }); + var appData = new AppData { Id = app.Id, StoreDataId = app.StoreId, Name = app.AppName, AppType = appType }; + apps.HttpContext.SetAppData(appData); + pos.HttpContext.SetAppData(appData); Assert.Single(appList.Apps); Assert.Empty(appList2.Apps); Assert.Equal("test", appList.Apps[0].AppName); diff --git a/BTCPayServer/Components/MainNav/Default.cshtml b/BTCPayServer/Components/MainNav/Default.cshtml index 0b46bb5b9..07a113357 100644 --- a/BTCPayServer/Components/MainNav/Default.cshtml +++ b/BTCPayServer/Components/MainNav/Default.cshtml @@ -100,9 +100,7 @@ {