btcpayserver/BTCPayServer.Tests/CoinSwitchTests.cs

92 lines
3.3 KiB
C#
Raw Normal View History

2020-06-28 17:55:27 +09:00
using System.Threading.Tasks;
2018-12-11 12:47:38 +01:00
using BTCPayServer.Controllers;
2020-06-28 17:55:27 +09:00
using BTCPayServer.Data;
2018-12-11 12:47:38 +01:00
using BTCPayServer.Models.StoreViewModels;
using BTCPayServer.Payments.CoinSwitch;
using BTCPayServer.Tests.Logging;
using Microsoft.AspNetCore.Mvc;
using Xunit;
using Xunit.Abstractions;
namespace BTCPayServer.Tests
{
public class CoinSwitchTests
{
public CoinSwitchTests(ITestOutputHelper helper)
{
2020-06-28 17:55:27 +09:00
Logs.Tester = new XUnitLog(helper) { Name = "Tests" };
2018-12-11 12:47:38 +01:00
Logs.LogProvider = new XUnitLogProvider(helper);
}
[Fact]
[Trait("Integration", "Integration")]
2019-10-07 16:04:25 +09:00
public async Task CanSetCoinSwitchPaymentMethod()
2018-12-11 12:47:38 +01:00
{
using (var tester = ServerTester.Create())
{
2019-10-07 16:04:25 +09:00
await tester.StartAsync();
2018-12-11 12:47:38 +01:00
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<StoresController>(user.UserId, user.StoreId);
2019-10-12 20:35:30 +09:00
var storeBlob = controller.CurrentStore.GetStoreBlob();
2018-12-11 12:47:38 +01:00
Assert.Null(storeBlob.CoinSwitchSettings);
var updateModel = new UpdateCoinSwitchSettingsViewModel()
{
MerchantId = "aaa",
};
Assert.Equal("UpdateStore", Assert.IsType<RedirectToActionResult>(
await controller.UpdateCoinSwitchSettings(user.StoreId, updateModel, "save")).ActionName);
var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId);
2019-10-12 20:35:30 +09:00
storeBlob = controller.CurrentStore.GetStoreBlob();
2018-12-11 12:47:38 +01:00
Assert.NotNull(storeBlob.CoinSwitchSettings);
Assert.NotNull(storeBlob.CoinSwitchSettings);
Assert.IsType<CoinSwitchSettings>(storeBlob.CoinSwitchSettings);
Assert.Equal(storeBlob.CoinSwitchSettings.MerchantId,
updateModel.MerchantId);
}
}
[Fact]
[Trait("Integration", "Integration")]
2019-10-07 16:04:25 +09:00
public async Task CanToggleCoinSwitchPaymentMethod()
2018-12-11 12:47:38 +01:00
{
using (var tester = ServerTester.Create())
{
2019-10-07 16:04:25 +09:00
await tester.StartAsync();
2018-12-11 12:47:38 +01:00
var user = tester.NewAccount();
user.GrantAccess();
var controller = tester.PayTester.GetController<StoresController>(user.UserId, user.StoreId);
var updateModel = new UpdateCoinSwitchSettingsViewModel()
{
MerchantId = "aaa",
Enabled = true
};
Assert.Equal("UpdateStore", Assert.IsType<RedirectToActionResult>(
await controller.UpdateCoinSwitchSettings(user.StoreId, updateModel, "save")).ActionName);
var store = await tester.PayTester.StoreRepository.FindStore(user.StoreId);
Assert.True(store.GetStoreBlob().CoinSwitchSettings.Enabled);
updateModel.Enabled = false;
Assert.Equal("UpdateStore", Assert.IsType<RedirectToActionResult>(
await controller.UpdateCoinSwitchSettings(user.StoreId, updateModel, "save")).ActionName);
store = await tester.PayTester.StoreRepository.FindStore(user.StoreId);
Assert.False(store.GetStoreBlob().CoinSwitchSettings.Enabled);
}
}
2020-06-28 17:55:27 +09:00
2018-12-11 12:47:38 +01:00
}
}