Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E tests for connection settings #44

Merged
merged 4 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
});

4 changes: 3 additions & 1 deletion tests-e2e/fixtures/test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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) => {
Expand Down
65 changes: 65 additions & 0 deletions tests-e2e/specs/007-configuration-connection.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { test } from '../fixtures/test';

test.describe('Connection settings', () => {

test('Disconnect', async ({ helper, connectionSettingsPage }) => {
// Setup
const { dummy_config } = helper.webhooks;
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 { dummy_config } = helper.webhooks;
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/);
});
});
Loading