From 6b035fee29e20cb08c06203da7321276259ca36d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20Escalante=20=C3=81lvarez?= Date: Fri, 7 Feb 2025 15:58:38 +0100 Subject: [PATCH 1/4] Fix ID assignment in ConfigureDummyTask to use max ID from database --- .../Sequra/Helper/Model/Task/ConfigureDummyTask.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.docker/magento/HelperModule/Sequra/Helper/Model/Task/ConfigureDummyTask.php b/.docker/magento/HelperModule/Sequra/Helper/Model/Task/ConfigureDummyTask.php index a1a0911..8e03ebf 100644 --- a/.docker/magento/HelperModule/Sequra/Helper/Model/Task/ConfigureDummyTask.php +++ b/.docker/magento/HelperModule/Sequra/Helper/Model/Task/ConfigureDummyTask.php @@ -36,8 +36,11 @@ private function setDummyConfig( bool $widgets ): void { $table_name = DatabaseHandler::SEQURA_ENTITY_TABLE; $conn = $this->conn->getConnection(); + + // Get the max id from the table or set it to 1 + $id = max((int) $conn->fetchOne( "SELECT MAX(id) FROM $table_name" ), 0); $time = time(); - $id = $time; + $conn->insert( $table_name, array( From 7b94bc6486d24cc02d2f402f27f832f21ee59628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20Escalante=20=C3=81lvarez?= Date: Fri, 7 Feb 2025 15:58:47 +0100 Subject: [PATCH 2/4] Update .env.sample for automated testing configuration --- .env.sample | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.env.sample b/.env.sample index cc0f0f6..881c69d 100644 --- a/.env.sample +++ b/.env.sample @@ -109,11 +109,13 @@ M2_COMPOSER_REPO_KEY= M2_COMPOSER_REPO_SECRET= # SeQura configuration -SQ_MERCHANT_REF=dummy -SQ_USER_NAME=dummy +SQ_MERCHANT_REF=dummy_automated_tests +SQ_USER_NAME=dummy_automated_tests SQ_USER_SECRET=ZqbjrN6bhPYVIyram3wcuQgHUmP1C4 SQ_ASSETS_KEY=ADc3ZdOLh4 SQ_ENDPOINT=https://sandbox.sequrapi.com/orders +SQ_USER_SERVICES_NAME=dummy_services_automated_tests +SQ_USER_SERVICES_SECRET=FPsS9zXIbcsEDYmn5sz2KEPrTlYiWO # Set with the ngrok authtoken (get it from https://dashboard.ngrok.com/) NGROK_AUTHTOKEN= From c4e7f1b7909ec63cb05add5b5d9c31487605258f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20Escalante=20=C3=81lvarez?= Date: Fri, 7 Feb 2025 15:59:12 +0100 Subject: [PATCH 3/4] Add connection settings tests and update related configurations --- package-lock.json | 2 +- playwright.config.js | 5 ++ tests-e2e/fixtures/test.js | 4 +- .../007-configuration-connection.spec.js | 67 +++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests-e2e/specs/007-configuration-connection.spec.js diff --git a/package-lock.json b/package-lock.json index a9a8536..648c3ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -84,7 +84,7 @@ }, "node_modules/playwright-fixture-for-plugins": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/sequra/playwright-fixture-for-plugins.git#8a5b728005cf1a45ebae5f58669d6899650a2e81", + "resolved": "git+ssh://git@github.com/sequra/playwright-fixture-for-plugins.git#88eb10738a3ba07075a18cac4aa28aa030ed1e7b", "dev": true }, "node_modules/undici-types": { diff --git a/playwright.config.js b/playwright.config.js index 604f6fb..10d49a2 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -55,6 +55,11 @@ export default defineConfig({ use: { ...devices['Desktop Chrome'] }, testMatch: '006-configuration-general.spec.js', }, + { + name: 'configuration-connection', + use: { ...devices['Desktop Chrome'] }, + testMatch: '007-configuration-connection.spec.js', + }, ], }); diff --git a/tests-e2e/fixtures/test.js b/tests-e2e/fixtures/test.js index b38d0e1..a26fcf3 100644 --- a/tests-e2e/fixtures/test.js +++ b/tests-e2e/fixtures/test.js @@ -1,5 +1,5 @@ import { test as baseTest, expect } from "@playwright/test"; -import { DataProvider, GeneralSettingsPage, PaymentMethodsSettingsPage } from "playwright-fixture-for-plugins"; +import { ConnectionSettingsPage, DataProvider, GeneralSettingsPage, OnboardingSettingsPage, PaymentMethodsSettingsPage } from "playwright-fixture-for-plugins"; import BackOffice from "./base/BackOffice"; import SeQuraHelper from "./utils/SeQuraHelper"; import ProductPage from "./pages/ProductPage"; @@ -11,8 +11,10 @@ const test = baseTest.extend({ 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)), + onboardingSettingsPage: async ({ page, baseURL, request, backOffice, helper}, use) => await use(new OnboardingSettingsPage(page, baseURL, expect, request, backOffice, helper)), checkoutPage: async ({ page, baseURL, request}, use) => await use(new CheckoutPage(page, baseURL, expect, request)), generalSettingsPage: async ({ page, baseURL, request, backOffice, helper}, use) => await use(new GeneralSettingsPage(page, baseURL, expect, request, backOffice, helper)), + connectionSettingsPage: async ({ page, baseURL, request, backOffice, helper}, use) => await use(new ConnectionSettingsPage(page, baseURL, expect, request, backOffice, helper)), }); test.afterEach(async ({ page }, testInfo) => { diff --git a/tests-e2e/specs/007-configuration-connection.spec.js b/tests-e2e/specs/007-configuration-connection.spec.js new file mode 100644 index 0000000..20e3a9b --- /dev/null +++ b/tests-e2e/specs/007-configuration-connection.spec.js @@ -0,0 +1,67 @@ +import { test } from '../fixtures/test'; + +test.describe('Connection settings', () => { + + test('Disconnect', async ({ helper, connectionSettingsPage }) => { + // Setup + const { clear_config, dummy_config } = helper.webhooks; + // await helper.executeWebhook({ webhook: clear_config }); // Clear the configuration. + await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products. + + // Execution + await connectionSettingsPage.goto(); + await connectionSettingsPage.expectLoadingShowAndHide(); + await connectionSettingsPage.disconnect(); + }); + + test('Change', async ({ helper, page, connectionSettingsPage }) => { + // Setup + const { clear_config, dummy_config } = helper.webhooks; + // await helper.executeWebhook({ webhook: clear_config }); // Clear the configuration. + await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products. + + const credentials = { + username: process.env.SQ_USER_NAME, + password: process.env.SQ_USER_SECRET, + env: 'sandbox' + }; + + const credentialsForServices = { + ...credentials, + username: process.env.SQ_USER_SERVICES_NAME, + password: process.env.SQ_USER_SERVICES_SECRET + }; + + const wrongSandboxCredentials = { ...credentials, password: '1234' }; + const wrongLiveCredentials = { ...credentials, env: 'live' }; + + // Execution + await connectionSettingsPage.goto(); + await connectionSettingsPage.expectLoadingShowAndHide(); + + // Test cancellation of the changes + await connectionSettingsPage.fillForm(wrongSandboxCredentials); + await connectionSettingsPage.cancel(); + await connectionSettingsPage.expectFormToHaveValues(credentials); + + // Test wrong values keeping env in sandbox. + await connectionSettingsPage.fillForm(wrongSandboxCredentials); + await connectionSettingsPage.save(); + await connectionSettingsPage.expectCredentialsErrorToBeVisible(); + + // Test wrong values changing env to live. + await page.reload(); + await connectionSettingsPage.expectLoadingShowAndHide(); + await connectionSettingsPage.fillForm(wrongLiveCredentials); + await connectionSettingsPage.save({ expectLoadingShowAndHide: false }); + await connectionSettingsPage.confirmModal(); + await connectionSettingsPage.expectCredentialsErrorToBeVisible(); + + // Test valid values. + await page.reload(); + await connectionSettingsPage.expectLoadingShowAndHide(); + await connectionSettingsPage.fillForm(credentialsForServices); + await connectionSettingsPage.save({ expectLoadingShowAndHide: true }); + await page.waitForURL(/#onboarding-countries/); + }); +}); \ No newline at end of file From 2ef820781c8db3b5301b18986efafdd6d09bc64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20Escalante=20=C3=81lvarez?= Date: Fri, 7 Feb 2025 16:49:10 +0100 Subject: [PATCH 4/4] Refactor connection settings tests to remove unused webhook configuration --- tests-e2e/specs/007-configuration-connection.spec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests-e2e/specs/007-configuration-connection.spec.js b/tests-e2e/specs/007-configuration-connection.spec.js index 20e3a9b..e5cb2d2 100644 --- a/tests-e2e/specs/007-configuration-connection.spec.js +++ b/tests-e2e/specs/007-configuration-connection.spec.js @@ -4,8 +4,7 @@ test.describe('Connection settings', () => { test('Disconnect', async ({ helper, connectionSettingsPage }) => { // Setup - const { clear_config, dummy_config } = helper.webhooks; - // await helper.executeWebhook({ webhook: clear_config }); // Clear the configuration. + const { dummy_config } = helper.webhooks; await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products. // Execution @@ -16,8 +15,7 @@ test.describe('Connection settings', () => { test('Change', async ({ helper, page, connectionSettingsPage }) => { // Setup - const { clear_config, dummy_config } = helper.webhooks; - // await helper.executeWebhook({ webhook: clear_config }); // Clear the configuration. + const { dummy_config } = helper.webhooks; await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products. const credentials = {