using System.Threading.Tasks; using BTCPayServer.Controllers; using BTCPayServer.Models.AppViewModels; using BTCPayServer.Services.Apps; using BTCPayServer.Tests.Logging; using Microsoft.AspNetCore.Mvc; using Xunit; using Xunit.Abstractions; using static BTCPayServer.Tests.UnitTest1; namespace BTCPayServer.Tests { public class POSTests { public POSTests(ITestOutputHelper helper) { Logs.Tester = new XUnitLog(helper) { Name = "Tests" }; Logs.LogProvider = new XUnitLogProvider(helper); } [Fact(Timeout = LongRunningTestTimeout)] public async Task CanUsePoSApp1() { using (var tester = ServerTester.Create()) { await tester.StartAsync(); var user = tester.NewAccount(); user.GrantAccess(); user.RegisterDerivationScheme("BTC"); var apps = user.GetController(); var vm = Assert.IsType(Assert.IsType(apps.CreateApp().Result).Model); vm.Name = "test"; vm.SelectedAppType = AppType.PointOfSale.ToString(); Assert.IsType(apps.CreateApp(vm).Result); var appId = Assert.IsType(Assert.IsType(apps.ListApps().Result).Model) .Apps[0].Id; var vmpos = Assert.IsType(Assert .IsType(apps.UpdatePointOfSale(appId).Result).Model); vmpos.Template = @" apple: price: 5.0 title: good apple disabled: true orange: price: 10.0 donation: price: 1.02 custom: true "; Assert.IsType(apps.UpdatePointOfSale(appId, vmpos).Result); vmpos = Assert.IsType(Assert .IsType(apps.UpdatePointOfSale(appId).Result).Model); var publicApps = user.GetController(); var vmview = Assert.IsType(Assert .IsType(publicApps.ViewPointOfSale(appId, PosViewType.Cart).Result).Model); // apple shouldn't be available since we it's set to "disabled: true" above Assert.Equal(2, vmview.Items.Length); Assert.Equal("orange", vmview.Items[0].Title); Assert.Equal("donation", vmview.Items[1].Title); // orange is available Assert.IsType(publicApps .ViewPointOfSale(appId, PosViewType.Cart, 0, null, null, null, null, "orange").Result); // apple is not found Assert.IsType(publicApps .ViewPointOfSale(appId, PosViewType.Cart, 0, null, null, null, null, "apple").Result); } } } }