|
| 1 | +using System.Threading.Tasks; |
| 2 | +using BTCPayServer.Tests; |
| 3 | +using Microsoft.Playwright; |
| 4 | +using Xunit; |
| 5 | +using Xunit.Abstractions; |
| 6 | + |
| 7 | +namespace BTCPayServer.Plugins.Depix.Tests; |
| 8 | + |
| 9 | +[Collection(SharedPluginTestCollection.CollectionName)] |
| 10 | +public class PixSettingsTests : PlaywrightBaseTest |
| 11 | +{ |
| 12 | + public PixSettingsTests(SharedPluginTestFixture fixture, ITestOutputHelper output) |
| 13 | + : base(fixture, output) |
| 14 | + { |
| 15 | + } |
| 16 | + |
| 17 | + [Fact(Timeout = TestUtils.TestTimeout)] |
| 18 | + [Trait("Category", "PlaywrightUITest")] |
| 19 | + public async Task CanOpenPixSettingsWhenPluginLoaded() |
| 20 | + { |
| 21 | + await InitializeStoreOwnerAsync(); |
| 22 | + await GoToPixSettingsAsync(); |
| 23 | + |
| 24 | + await Page.GetByRole(AriaRole.Heading, new() { Name = "Pix Settings" }).WaitForAsync(); |
| 25 | + await Page.Locator("#ApiKey").WaitForAsync(); |
| 26 | + await Page.GetByText("DePix is not configured.", new() { Exact = false }).WaitForAsync(); |
| 27 | + |
| 28 | + Assert.Contains($"/stores/{Tester.StoreId}/pix/settings", Page.Url); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact(Timeout = TestUtils.TestTimeout)] |
| 32 | + [Trait("Category", "PlaywrightUITest")] |
| 33 | + public async Task CanSaveAndPersistPixStoreSettings() |
| 34 | + { |
| 35 | + await InitializeStoreOwnerAsync(); |
| 36 | + await SeedValidStorePixConfigAsync(); |
| 37 | + await GoToPixSettingsAsync(); |
| 38 | + |
| 39 | + await Page.Locator("#IsEnabled").SetCheckedAsync(true); |
| 40 | + await Page.Locator("#PassFeeToCustomer").SetCheckedAsync(true); |
| 41 | + await Page.Locator("#UseWhitelist").SetCheckedAsync(true); |
| 42 | + await Page.GetByRole(AriaRole.Button, new() { Name = "Save" }).ClickAsync(); |
| 43 | + |
| 44 | + await Tester.FindAlertMessage(partialText: "Pix configuration applied"); |
| 45 | + |
| 46 | + Assert.True(await Page.Locator("#IsEnabled").IsCheckedAsync()); |
| 47 | + Assert.True(await Page.Locator("#PassFeeToCustomer").IsCheckedAsync()); |
| 48 | + Assert.True(await Page.Locator("#UseWhitelist").IsCheckedAsync()); |
| 49 | + } |
| 50 | + |
| 51 | + [Fact(Timeout = TestUtils.TestTimeout)] |
| 52 | + [Trait("Category", "PlaywrightUITest")] |
| 53 | + public async Task CanEnablePixUsingServerLevelConfiguration() |
| 54 | + { |
| 55 | + await InitializeStoreOwnerAsync(); |
| 56 | + await SeedValidServerPixConfigAsync(); |
| 57 | + await GoToPixSettingsAsync(); |
| 58 | + |
| 59 | + await Page.GetByText("server-level DePix Api Key configuration", new() { Exact = false }).WaitForAsync(); |
| 60 | + Assert.Equal(0, await Page.Locator("#PassFeeToCustomer").CountAsync()); |
| 61 | + Assert.Equal(0, await Page.Locator("#UseWhitelist").CountAsync()); |
| 62 | + |
| 63 | + await Page.Locator("#IsEnabled").SetCheckedAsync(true); |
| 64 | + await Page.GetByRole(AriaRole.Button, new() { Name = "Save" }).ClickAsync(); |
| 65 | + |
| 66 | + await Tester.FindAlertMessage(partialText: "Pix configuration applied"); |
| 67 | + Assert.True(await Page.Locator("#IsEnabled").IsCheckedAsync()); |
| 68 | + |
| 69 | + var storeConfig = await GetStorePixConfigAsync(); |
| 70 | + Assert.NotNull(storeConfig); |
| 71 | + Assert.True(storeConfig!.IsEnabled); |
| 72 | + Assert.Null(storeConfig.EncryptedApiKey); |
| 73 | + Assert.Null(storeConfig.WebhookSecretHashHex); |
| 74 | + } |
| 75 | +} |
0 commit comments