Skip to content

Commit

Permalink
Add general configuration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mescalantea committed Feb 6, 2025
1 parent 7447490 commit bf6e6a7
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 3 deletions.
5 changes: 5 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
});

9 changes: 9 additions & 0 deletions tests-e2e/fixtures/pages/CheckoutPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests-e2e/fixtures/test.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
200 changes: 200 additions & 0 deletions tests-e2e/specs/006-configuration-general.spec.js
Original file line number Diff line number Diff line change
@@ -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 });
});
});

0 comments on commit bf6e6a7

Please sign in to comment.