btcpayserver/BTCPayServer.Tests/POSTests.cs

74 lines
3.1 KiB
C#
Raw Normal View History

2021-09-17 04:31:48 +02:00
using System.Threading.Tasks;
using BTCPayServer.Controllers;
using BTCPayServer.Data;
2021-09-17 04:31:48 +02:00
using BTCPayServer.Models.AppViewModels;
2022-07-18 20:51:53 +02:00
using BTCPayServer.Plugins.PointOfSale.Controllers;
using BTCPayServer.Plugins.PointOfSale.Models;
2021-09-17 04:31:48 +02:00
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
{
2021-11-23 05:57:45 +01:00
[Collection(nameof(NonParallelizableCollectionDefinition))]
2021-11-22 09:16:08 +01:00
public class POSTests : UnitTestBase
2021-09-17 04:31:48 +02:00
{
2021-11-22 09:16:08 +01:00
public POSTests(ITestOutputHelper helper) : base(helper)
2021-09-17 04:31:48 +02:00
{
}
[Fact(Timeout = LongRunningTestTimeout)]
2021-11-22 16:49:51 +01:00
[Trait("Integration", "Integration")]
2021-09-17 04:31:48 +02:00
public async Task CanUsePoSApp1()
{
2022-01-14 09:50:29 +01:00
using var tester = CreateServerTester();
await tester.StartAsync();
var user = tester.NewAccount();
await user.GrantAccessAsync();
user.RegisterDerivationScheme("BTC");
var apps = user.GetController<UIAppsController>();
2022-07-18 20:51:53 +02:00
var pos = user.GetController<UIPointOfSaleController>();
2022-01-14 09:50:29 +01:00
var vm = Assert.IsType<CreateAppViewModel>(Assert.IsType<ViewResult>(apps.CreateApp(user.StoreId)).Model);
var appType = AppType.PointOfSale.ToString();
2022-01-14 09:50:29 +01:00
vm.AppName = "test";
vm.SelectedAppType = appType;
2022-01-14 09:50:29 +01:00
Assert.IsType<RedirectToActionResult>(apps.CreateApp(user.StoreId, vm).Result);
var appList = Assert.IsType<ListAppsViewModel>(Assert.IsType<ViewResult>(apps.ListApps(user.StoreId).Result).Model);
var app = appList.Apps[0];
2022-07-18 20:51:53 +02:00
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<UpdatePointOfSaleViewModel>();
2022-01-14 09:50:29 +01:00
vmpos.Template = @"
2021-09-17 04:31:48 +02:00
apple:
price: 5.0
title: good apple
disabled: true
orange:
price: 10.0
donation:
price: 1.02
custom: true
";
2022-07-18 20:51:53 +02:00
Assert.IsType<RedirectToActionResult>(pos.UpdatePointOfSale(app.Id, vmpos).Result);
await pos.UpdatePointOfSale(app.Id).AssertViewModelAsync<UpdatePointOfSaleViewModel>();
2022-07-22 15:41:14 +02:00
var publicApps = user.GetController<UIPointOfSaleController>();
2022-06-20 06:34:25 +02:00
var vmview = await publicApps.ViewPointOfSale(app.Id, PosViewType.Cart).AssertViewModelAsync<ViewPointOfSaleViewModel>();
2021-09-17 04:31:48 +02:00
2022-01-14 09:50:29 +01:00
// 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<RedirectToActionResult>(publicApps
.ViewPointOfSale(app.Id, PosViewType.Cart, 0, null, null, null, null, "orange").Result);
// apple is not found
Assert.IsType<NotFoundResult>(publicApps
.ViewPointOfSale(app.Id, PosViewType.Cart, 0, null, null, null, null, "apple").Result);
2021-09-17 04:31:48 +02:00
}
}
}