From bf6e6a7973610ed403c79b20b9aff214417b01a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20Escalante=20=C3=81lvarez?= Date: Thu, 6 Feb 2025 17:50:33 +0100 Subject: [PATCH] Add general configuration tests --- playwright.config.js | 5 + tests-e2e/fixtures/pages/CheckoutPage.js | 9 + tests-e2e/fixtures/test.js | 6 +- .../specs/006-configuration-general.spec.js | 200 ++++++++++++++++++ 4 files changed, 217 insertions(+), 3 deletions(-) create mode 100644 tests-e2e/specs/006-configuration-general.spec.js diff --git a/playwright.config.js b/playwright.config.js index c2df54f..604f6fb 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -50,6 +50,11 @@ export default defineConfig({ use: { ...devices['Desktop Chrome'] }, testMatch: '004-configuration-payment-methods.spec.js', }, + { + name: 'configuration-general', + use: { ...devices['Desktop Chrome'] }, + testMatch: '006-configuration-general.spec.js', + }, ], }); diff --git a/tests-e2e/fixtures/pages/CheckoutPage.js b/tests-e2e/fixtures/pages/CheckoutPage.js index f94101b..51ae018 100644 --- a/tests-e2e/fixtures/pages/CheckoutPage.js +++ b/tests-e2e/fixtures/pages/CheckoutPage.js @@ -135,6 +135,15 @@ export default class CheckoutPage extends BaseCheckoutPage { return this.page.locator(`#sequra_${options.product} + label`).getByText(options.title); } + /** + * Provide the locator seQura payment methods + * @param {Object} options + * @returns {import("@playwright/test").Locator} + */ + paymentMethodsLocator(options) { + return this.page.locator('[id^="sequra_"]'); + } + /** * Select the payment method and place the order * @param {Object} options diff --git a/tests-e2e/fixtures/test.js b/tests-e2e/fixtures/test.js index d7fbccb..b38d0e1 100644 --- a/tests-e2e/fixtures/test.js +++ b/tests-e2e/fixtures/test.js @@ -1,18 +1,18 @@ import { test as baseTest, expect } from "@playwright/test"; -import { DataProvider, PaymentMethodsSettingsPage, OnboardingSettingsPage } from "playwright-fixture-for-plugins"; +import { DataProvider, GeneralSettingsPage, PaymentMethodsSettingsPage } from "playwright-fixture-for-plugins"; import BackOffice from "./base/BackOffice"; import SeQuraHelper from "./utils/SeQuraHelper"; import ProductPage from "./pages/ProductPage"; import CheckoutPage from "./pages/CheckoutPage"; const test = baseTest.extend({ - dataProvider: async ({ page, baseURL }, use) => await use(new DataProvider(page, baseURL, expect)), + dataProvider: async ({ page, baseURL, request }, use) => await use(new DataProvider(page, baseURL, expect, request)), backOffice: async ({ page, baseURL }, use) => await use(new BackOffice(page, baseURL, expect)), helper: async ({ page, baseURL, request }, use) => await use(new SeQuraHelper(page, baseURL, expect, request)), paymentMethodsSettingsPage: async ({ page, baseURL, request, backOffice, helper}, use) => await use(new PaymentMethodsSettingsPage(page, baseURL, expect, request, backOffice, helper)), productPage: async ({ page, baseURL, request}, use) => await use(new ProductPage(page, baseURL, expect, request)), checkoutPage: async ({ page, baseURL, request}, use) => await use(new CheckoutPage(page, baseURL, expect, request)), - onboardingSettingsPage: async ({ page, baseURL, request, backOffice, helper}, use) => await use(new OnboardingSettingsPage(page, baseURL, expect, request, backOffice, helper)), + generalSettingsPage: async ({ page, baseURL, request, backOffice, helper}, use) => await use(new GeneralSettingsPage(page, baseURL, expect, request, backOffice, helper)), }); test.afterEach(async ({ page }, testInfo) => { diff --git a/tests-e2e/specs/006-configuration-general.spec.js b/tests-e2e/specs/006-configuration-general.spec.js new file mode 100644 index 0000000..1a653e5 --- /dev/null +++ b/tests-e2e/specs/006-configuration-general.spec.js @@ -0,0 +1,200 @@ +import { test, expect } from '../fixtures/test'; + +test.describe('Configuration', () => { + + test('Change allowed IP addresses', async ({ helper, dataProvider, backOffice, page, generalSettingsPage, productPage, checkoutPage }) => { + // Setup + const { dummy_config, clear_config } = helper.webhooks; + await helper.executeWebhook({ webhook: clear_config }); // Clear the configuration. + await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products. + + const badIPAddressesMatrix = [ + ['a.b.c.d'], + ['a.b.c.d', '1.1.1.256'], + ['a.b.c.d', '1.1.1.256', 'lorem ipsum'] + ] + + const publicIP = await dataProvider.publicIP(); + const notAllowedIPAddressesMatrix = [ + ['8.8.8.8'] + ] + const allowedIPAddressesMatrix = [ + [], + [publicIP], + [publicIP, ...notAllowedIPAddressesMatrix[0]] + ] + + const fillAndAssert = async (ipAddresses, available) => { + await generalSettingsPage.fillAllowedIPAddresses(ipAddresses); + await generalSettingsPage.save({ skipIfDisabled: true }); + await backOffice.logout(); + await productPage.addToCart({ slug: 'push-it-messenger-bag', quantity: 1 }); + await checkoutPage.goto(); + await checkoutPage.fillForm(dataProvider.shopper()); + await checkoutPage.expectAnyPaymentMethod({ available }); + await generalSettingsPage.goto(); + await generalSettingsPage.expectLoadingShowAndHide(); + } + + // Execution. + await generalSettingsPage.goto(); + await generalSettingsPage.expectLoadingShowAndHide(); + + // Test cancellation of the changes + await generalSettingsPage.fillAllowedIPAddresses(notAllowedIPAddressesMatrix[0]); + await generalSettingsPage.cancel(); + await generalSettingsPage.expectAllowedIPAddressesToBeEmpty(); + + // Test with invalid IP addresses + for (const ipAddresses of badIPAddressesMatrix) { + await generalSettingsPage.fillAllowedIPAddresses(ipAddresses); + await generalSettingsPage.save({ expectLoadingShowAndHide: false }); + await expect(page.getByText('This field must contain only valid IP addresses.'), 'The error message under "Allowed IP addresses" field should be visible').toBeVisible(); + await page.reload(); + await generalSettingsPage.expectLoadingShowAndHide(); + } + + // Test with valid IP addresses + for (const ipAddresses of notAllowedIPAddressesMatrix) { + console.log('Fill not allowed IP addresses:', ipAddresses); + await fillAndAssert(ipAddresses, false); + } + + for (const ipAddresses of allowedIPAddressesMatrix) { + console.log('Fill allowed IP addresses:', ipAddresses); + await fillAndAssert(ipAddresses, true); + } + }); + + test('Change excluded categories', async ({ helper, dataProvider, backOffice, generalSettingsPage, productPage, checkoutPage }) => { + + // Setup + const { dummy_config, clear_config } = helper.webhooks; + await helper.executeWebhook({ webhook: clear_config }); // Clear the configuration. + await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products. + + const allowedCategoriesMatrix = [ + [], + ['Watches'] + ['Tops', 'Default Category'], + ]; + + const notAllowedCategoriesMatrix = [ + ['Bags'], + ['Bags', 'Video Download'], + ]; + + const fillAndAssert = async (categories, available) => { + await generalSettingsPage.selectExcludedCategories(categories); + await generalSettingsPage.save({ skipIfDisabled: true }); + await backOffice.logout(); + await productPage.addToCart({ slug: 'push-it-messenger-bag', quantity: 1 }); + await checkoutPage.goto(); + await checkoutPage.fillForm(dataProvider.shopper()); + await checkoutPage.expectAnyPaymentMethod({ available }); + await generalSettingsPage.goto(); + await generalSettingsPage.expectLoadingShowAndHide(); + } + + // Execution + await generalSettingsPage.goto(); + await generalSettingsPage.expectLoadingShowAndHide(); + + // Test cancellation of the changes + await generalSettingsPage.selectExcludedCategories(notAllowedCategoriesMatrix[0]); + await generalSettingsPage.cancel(); + await generalSettingsPage.expectExcludedCategoriesToBeEmpty(); + + // Test with categories assigned to the product + for (const categories of notAllowedCategoriesMatrix) { + await fillAndAssert(categories, false); + } + + // Test with categories not assigned to the product + for (const categories of allowedCategoriesMatrix) { + await fillAndAssert(categories, true); + } + }); + + test('Change excluded products', async ({ helper, dataProvider, backOffice, generalSettingsPage, productPage, checkoutPage }) => { + + // Setup + const { dummy_config, clear_config } = helper.webhooks; + await helper.executeWebhook({ webhook: clear_config }); // Clear the configuration. + await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products. + + const sku = '24-WB04';// The product SKU. + const allowedValuesMatrix = [ + [], + ['24-UG05'], + ['24-UG05', '24-MG02'] + ]; + const notAllowedValuesMatrix = [ + [sku], + [sku, ...allowedValuesMatrix[2]], + ]; + + const fillAndAssert = async (values, available) => { + await generalSettingsPage.fillExcludedProducts(values); + await generalSettingsPage.save({ skipIfDisabled: true }); + await backOffice.logout(); + await productPage.addToCart({ slug: 'push-it-messenger-bag', quantity: 1 }); + await checkoutPage.goto(); + await checkoutPage.fillForm(dataProvider.shopper()); + await checkoutPage.expectAnyPaymentMethod({ available }); + await generalSettingsPage.goto(); + await generalSettingsPage.expectLoadingShowAndHide(); + } + + // Execution + await generalSettingsPage.goto(); + await generalSettingsPage.expectLoadingShowAndHide(); + + // Test cancellation of the changes + await generalSettingsPage.fillExcludedProducts(notAllowedValuesMatrix[0]); + await generalSettingsPage.cancel(); + await generalSettingsPage.expectExcludedProductsToBeEmpty(); + + // Test including the product + for (const values of notAllowedValuesMatrix) { + await fillAndAssert(values, false); + } + + // Test excluding the product + for (const values of allowedValuesMatrix) { + await fillAndAssert(values, true); + } + }); + + test('Change available countries', async ({ helper, dataProvider, page, generalSettingsPage, checkoutPage }) => { + // Setup + const { dummy_config, clear_config } = helper.webhooks; + await helper.executeWebhook({ webhook: clear_config }); // Clear the configuration. + await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products. + const countries = dataProvider.countriesMerchantRefs(); + + // Execution + await generalSettingsPage.goto(); + await generalSettingsPage.expectLoadingShowAndHide(); + await generalSettingsPage.expectAvailableCountries({ countries }); + + // Test cancellation of the changes + await generalSettingsPage.fillAvailableCountries({ countries: [countries[0]] }); + await generalSettingsPage.cancel(); + await generalSettingsPage.expectAvailableCountries({ countries }); + + // Test wrong values. + await generalSettingsPage.fillAvailableCountries({ + countries: [{ ...countries[0], merchantRef: 'dummy_wrong' }] + }); + await generalSettingsPage.save({ expectLoadingShowAndHide: false }); + await generalSettingsPage.expectCountryInputErrorToBeVisible(); + + // Test valid values. + await generalSettingsPage.fillAvailableCountries({ countries }); + await generalSettingsPage.save({ expectLoadingShowAndHide: true }); + await page.reload(); + await generalSettingsPage.expectLoadingShowAndHide(); + await generalSettingsPage.expectAvailableCountries({ countries }); + }); +}); \ No newline at end of file