diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 612452a3..50133450 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,11 +12,11 @@ jobs: permissions: contents: "read" strategy: - max-parallel: 2 + max-parallel: 1 fail-fast: false matrix: magento-versions: - ["2.3.3ce", "2.3.5ce", "2.4.0ce", "2.4.2ce", "2.4.4ce", "2.4.6ce"] + ["2.3.5ce", "2.4.0ce", "2.4.2ce", "2.4.4ce", "2.4.6ce"] steps: - name: Extract branch name shell: bash @@ -48,6 +48,13 @@ jobs: sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update sudo apt-get install docker-compose-plugin -y + - name: Build mage_node image + shell: bash + run: | + cd magento2-extension/dev + docker build -f testv2/tools/docker/Dockerfile-mage-node --build-arg NPM_TOKEN=$NPM_TOKEN -t "mage_node" . + env: + NPM_TOKEN: ${{ secrets.GITLAB_TOKEN }} - name: Run unittest shell: bash run: | @@ -55,17 +62,17 @@ jobs: bash dev/testv2/tools/scripts/run-unit.sh env: VERSION: ${{ matrix.magento-versions }} - NPM_TOKEN: ${{ secrets.NPM_DEPLOYER_TOKEN }} + NPM_TOKEN: ${{ secrets.GITLAB_TOKEN }} e2e-tests: runs-on: github-actions-runner-emarsys permissions: contents: "read" strategy: - max-parallel: 2 + max-parallel: 1 fail-fast: false matrix: magento-versions: - ["2.3.3ce", "2.3.5ce", "2.4.0ce", "2.4.2ce", "2.4.4ce", "2.4.6ce"] + ["2.3.5ce", "2.4.0ce", "2.4.2ce", "2.4.4ce", "2.4.6ce"] steps: - name: Extract branch name shell: bash @@ -97,6 +104,13 @@ jobs: sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update sudo apt-get install docker-compose-plugin -y + - name: Build mage_node image + shell: bash + run: | + cd magento2-extension/dev + docker build -f testv2/tools/docker/Dockerfile-mage-node --build-arg NPM_TOKEN=$NPM_TOKEN -t "mage_node" . + env: + NPM_TOKEN: ${{ secrets.GITLAB_TOKEN }} - name: Run e2stest shell: bash run: | @@ -104,4 +118,4 @@ jobs: bash dev/testv2/tools/scripts/run-e2e.sh env: VERSION: ${{ matrix.magento-versions }} - NPM_TOKEN: ${{ secrets.NPM_DEPLOYER_TOKEN }} + NPM_TOKEN: ${{ secrets.GITLAB_TOKEN }} diff --git a/dev/README.md b/dev/README.md index f8412f40..4fa7bc0e 100644 --- a/dev/README.md +++ b/dev/README.md @@ -203,3 +203,4 @@ git push -f --tags ## Update Cypress * Update the version in `package.json` * Run `make build-cypress VERSION=new-version` from project root + diff --git a/dev/testv2/.npmrc b/dev/testv2/.npmrc new file mode 100644 index 00000000..23715a6a --- /dev/null +++ b/dev/testv2/.npmrc @@ -0,0 +1,3 @@ +always-auth=true +@itg-commerce:registry=https://gitlab.itg.cloud/api/v4/projects/295/packages/npm/ +//gitlab.itg.cloud/api/v4/projects/295/packages/npm/:_authToken=${NPM_TOKEN} diff --git a/dev/testv2/attributes/index.spec.js b/dev/testv2/attributes/index.spec.js index f57f5bc5..a761dd10 100644 --- a/dev/testv2/attributes/index.spec.js +++ b/dev/testv2/attributes/index.spec.js @@ -6,13 +6,13 @@ const websiteId = 1; const mapAttributes = attributes => attributes.map(attribute => ({ code: attribute.code, name: attribute.name })); -describe('Attributes endpoint', function() { - afterEach(async function() {}); +describe('Attributes endpoint', function () { + afterEach(async function () {}); - after(async function() {}); + after(async function () {}); - describe('get', function() { - it('should fetch attributes including extra fields for customer', async function() { + describe('get', function () { + it('should fetch attributes including extra fields for customer', async function () { const { attributes } = await this.magentoApi.execute('attributes', 'get', { type: 'customer' }); const mappedAttributes = mapAttributes(attributes); @@ -29,7 +29,7 @@ describe('Attributes endpoint', function() { } }); - it('should fetch attributes including extra fields for customer_address', async function() { + it('should fetch attributes including extra fields for customer_address', async function () { const { attributes } = await this.magentoApi.execute('attributes', 'get', { type: 'customer_address' }); const mappedAttributes = mapAttributes(attributes); @@ -40,7 +40,7 @@ describe('Attributes endpoint', function() { } }); - it('should fetch attributes including extra fields for products', async function() { + it('should fetch attributes including extra fields for products', async function () { const { attributes } = await this.magentoApi.execute('attributes', 'get', { type: 'product' }); const mappedAttributes = attributes.map(attribute => { return { code: attribute.code, name: attribute.name }; @@ -58,8 +58,8 @@ describe('Attributes endpoint', function() { }); }); - describe('set', function() { - it('should modify customer attribute config for website', async function() { + describe('set', function () { + it('should modify customer attribute config for website', async function () { await this.magentoApi.execute('attributes', 'set', { websiteId, type: 'customer', @@ -76,7 +76,7 @@ describe('Attributes endpoint', function() { expect(config.value).to.equal(JSON.stringify(['hello_attribute'])); }); - it('should modify customer_address attribute config for website', async function() { + it('should modify customer_address attribute config for website', async function () { await this.magentoApi.execute('attributes', 'set', { websiteId, type: 'customer_address', @@ -93,7 +93,7 @@ describe('Attributes endpoint', function() { expect(config.value).to.equal(JSON.stringify(['hello_attribute'])); }); - it('should modify product attribute config for website', async function() { + it('should modify product attribute config for website', async function () { await this.magentoApi.execute('attributes', 'set', { websiteId: 0, type: 'product', diff --git a/dev/testv2/config/index.spec.js b/dev/testv2/config/index.spec.js index 942ef1e9..50bc9405 100644 --- a/dev/testv2/config/index.spec.js +++ b/dev/testv2/config/index.spec.js @@ -21,21 +21,21 @@ const dbKeys = { }; const websiteId = 1; -describe('Config endpoint', function() { - before(async function() { +describe('Config endpoint', function () { + before(async function () { await this.turnOffEverySetting(1); }); - afterEach(async function() { + afterEach(async function () { await this.turnOffEverySetting(1); }); - after(async function() { + after(async function () { await this.setDefaultStoreSettings(); }); - describe('set', function() { - it('should modify config values for website', async function() { + describe('set', function () { + it('should modify config values for website', async function () { await this.magentoApi.execute('config', 'set', { websiteId, config: fullConfig diff --git a/dev/testv2/customers/list.spec.js b/dev/testv2/customers/list.spec.js index 71e73853..a57ff7d8 100644 --- a/dev/testv2/customers/list.spec.js +++ b/dev/testv2/customers/list.spec.js @@ -23,8 +23,8 @@ const customers = [ } ]; -describe('Customers endpoint', function() { - before(async function() { +describe('Customers endpoint', function () { + before(async function () { await this.magentoApi.execute('attributes', 'set', { websiteId: 1, type: 'customer', @@ -35,7 +35,7 @@ describe('Customers endpoint', function() { } }); - after(async function() { + after(async function () { await this.magentoApi.execute('attributes', 'set', { websiteId: 1, type: 'customer', @@ -44,7 +44,7 @@ describe('Customers endpoint', function() { await this.db.raw(`DELETE FROM ${this.getTableName('customer_entity')} where email like "%@customer.net"`); }); - it('returns customers according to page and page_size inlcuding last_page', async function() { + it('returns customers according to page and page_size inlcuding last_page', async function () { const page = 1; const limit = 2; @@ -66,7 +66,7 @@ describe('Customers endpoint', function() { expect(customer).to.have.property('shipping_address'); }); - it('returns extra_fields for customers', async function() { + it('returns extra_fields for customers', async function () { const page = 1; const limit = 1; diff --git a/dev/testv2/cypress.config.js b/dev/testv2/cypress.config.js index 5ac964ca..26d5d25c 100644 --- a/dev/testv2/cypress.config.js +++ b/dev/testv2/cypress.config.js @@ -3,9 +3,9 @@ const { defineConfig } = require('cypress'); module.exports = defineConfig({ video: false, trashAssetsBeforeRuns: false, - requestTimeout: 30000, - defaultCommandTimeout: 30000, - pageLoadTimeout: 30000, + requestTimeout: 120000, + defaultCommandTimeout: 120000, + pageLoadTimeout: 120000, blockHosts: ['*snippet.url.com', '*scarabresearch.com'], env: { snippetUrl: 'http://snippet.url.com/main.js' diff --git a/dev/testv2/cypress/integration/default-behaviour.spec.js b/dev/testv2/cypress/integration/default-behaviour.spec.js index 9ecd3568..ac79406c 100644 --- a/dev/testv2/cypress/integration/default-behaviour.spec.js +++ b/dev/testv2/cypress/integration/default-behaviour.spec.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Default behaviour with everything turned off', function() { +describe('Default behaviour with everything turned off', function () { before(() => { cy.task('setConfig', {}); }); @@ -14,13 +14,13 @@ describe('Default behaviour with everything turned off', function() { cy.task('clearMails'); }); - context('MarketingEvents - Customer', function() { + context('MarketingEvents - Customer', function () { afterEach(() => { cy.task('clearEvents'); cy.logout(); }); - it('should not create customer_password_reset event', function() { + it('should not create customer_password_reset event', function () { const newPassword = 'newPassword1'; cy.loginWithCustomer(this.defaultCustomer); @@ -36,7 +36,7 @@ describe('Default behaviour with everything turned off', function() { }); }); - it('should not create customer_email_changed event', function() { + it('should not create customer_email_changed event', function () { const oldEmail = this.defaultCustomer.email; const newEmail = 'cypress2@default.com'; @@ -52,7 +52,7 @@ describe('Default behaviour with everything turned off', function() { }); }); - it('should not create customer_email_and_password_changed event', function() { + it('should not create customer_email_and_password_changed event', function () { const newEmail = 'cypress5@default.com'; const newPassword = 'newPassword4'; @@ -70,7 +70,7 @@ describe('Default behaviour with everything turned off', function() { }); }); - context('MarketingEvents - Subscription', function() { + context('MarketingEvents - Subscription', function () { const unsubscribe = email => { cy.task('getSubscription', email).then(subscription => { cy.visit(`/newsletter/subscriber/unsubscribe?id=${subscription.subscriber_id}\ @@ -84,8 +84,8 @@ describe('Default behaviour with everything turned off', function() { cy.get('.action.subscribe.primary[type="submit"]').click(); }; - context('guest with double optin off', function() { - it('should not create subscription events', function() { + context('guest with double optin off', function () { + it('should not create subscription events', function () { const guestEmail = 'no-event.doptin-off@guest-cypress.com'; subscribe(guestEmail); @@ -110,7 +110,7 @@ describe('Default behaviour with everything turned off', function() { }); }); - context('guest with double optin on', function() { + context('guest with double optin on', function () { before(() => { cy.task('setDoubleOptin', true); cy.task('flushMagentoCache'); @@ -120,7 +120,7 @@ describe('Default behaviour with everything turned off', function() { cy.task('setDoubleOptin', false); }); - it('should not create subscription events', function() { + it('should not create subscription events', function () { const guestEmail = 'no-event.doptin-on@guest-cypress.com'; subscribe(guestEmail); diff --git a/dev/testv2/cypress/integration/marketing-events-customer.spec.js b/dev/testv2/cypress/integration/marketing-events-customer.spec.js index 75c15864..e4b7c420 100644 --- a/dev/testv2/cypress/integration/marketing-events-customer.spec.js +++ b/dev/testv2/cypress/integration/marketing-events-customer.spec.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Marketing Events', function() { +describe('Marketing Events', function () { beforeEach(() => { cy.task('clearMails'); cy.task('getDefaultCustomer').as('defaultCustomer'); @@ -10,7 +10,7 @@ describe('Marketing Events', function() { cy.logout(); }); - context('magentoSendEmails config is disabled', function() { + context('magentoSendEmails config is disabled', function () { before(() => { cy.task('setConfig', { collectMarketingEvents: 'enabled', @@ -19,7 +19,7 @@ describe('Marketing Events', function() { cy.task('clearEvents'); }); - it('should create customer_password_reset event', function() { + it('should create customer_password_reset event', function () { const newPassword = 'newPassword2'; cy.loginWithCustomer(this.defaultCustomer); @@ -36,7 +36,7 @@ describe('Marketing Events', function() { }); }); - it('should create customer_email_changed event', function() { + it('should create customer_email_changed event', function () { const newEmail = 'cypress3@default.com'; cy.loginWithCustomer(this.defaultCustomer); @@ -53,7 +53,7 @@ describe('Marketing Events', function() { }); }); - it('should create customer_email_and_password_changed event', function() { + it('should create customer_email_and_password_changed event', function () { const newEmail = 'cypress4@default.com'; const newPassword = 'newPassword3'; @@ -72,7 +72,7 @@ describe('Marketing Events', function() { }); }); - context('magentoSendEmails config is enabled', function() { + context('magentoSendEmails config is enabled', function () { before(() => { cy.task('setConfig', { collectMarketingEvents: 'enabled', @@ -81,7 +81,7 @@ describe('Marketing Events', function() { cy.task('clearEvents'); }); - it('should create customer_password_reset event', function() { + it('should create customer_password_reset event', function () { const newPassword = 'newPassword2'; cy.loginWithCustomer(this.defaultCustomer); @@ -98,7 +98,7 @@ describe('Marketing Events', function() { }); }); - it('should create customer_email_changed event', function() { + it('should create customer_email_changed event', function () { const oldEmail = this.defaultCustomer.email; const newEmail = 'cypress3@default.com'; @@ -116,7 +116,7 @@ describe('Marketing Events', function() { }); }); - it('should create customer_email_and_password_changed event', function() { + it('should create customer_email_and_password_changed event', function () { const oldEmail = this.defaultCustomer.email; const newEmail = 'cypress4@default.com'; const newPassword = 'newPassword3'; diff --git a/dev/testv2/cypress/integration/marketing-events-subscription.spec.js b/dev/testv2/cypress/integration/marketing-events-subscription.spec.js index e1bbb4d5..9e36989d 100644 --- a/dev/testv2/cypress/integration/marketing-events-subscription.spec.js +++ b/dev/testv2/cypress/integration/marketing-events-subscription.spec.js @@ -1,6 +1,6 @@ 'use strict'; -describe('Marketing Events', function() { +describe('Marketing Events', function () { const unsubscribe = email => { cy.task('getSubscription', email).then(subscription => { cy.visit(`/newsletter/subscriber/unsubscribe?id=${subscription.subscriber_id}\ @@ -19,7 +19,7 @@ describe('Marketing Events', function() { cy.task('clearEvents'); }); - context('magentoSendEmails config is disabled', function() { + context('magentoSendEmails config is disabled', function () { before(() => { cy.task('setConfig', { collectMarketingEvents: 'enabled', @@ -27,8 +27,8 @@ describe('Marketing Events', function() { }); }); - context('guest with double optin off', function() { - it('should create subscription events', function() { + context('guest with double optin off', function () { + it('should create subscription events', function () { const guestEmail = 'event.doptin-off.sub@guest-cypress.com'; subscribe(guestEmail); @@ -56,7 +56,7 @@ describe('Marketing Events', function() { }); }); - context('guest with double optin on', function() { + context('guest with double optin on', function () { before(() => { cy.task('setDoubleOptin', true); cy.task('flushMagentoCache'); @@ -66,7 +66,7 @@ describe('Marketing Events', function() { cy.task('setDoubleOptin', false); }); - it('should create newsletter_send_confirmation_request_email event', function() { + it('should create newsletter_send_confirmation_request_email event', function () { const guestEmail = 'event.doptin-on.sub@guest-cypress.com'; subscribe(guestEmail); @@ -95,7 +95,7 @@ describe('Marketing Events', function() { }); }); - context('magentoSendEmails config is enabled', function() { + context('magentoSendEmails config is enabled', function () { before(() => { cy.task('setConfig', { collectMarketingEvents: 'enabled', @@ -103,8 +103,8 @@ describe('Marketing Events', function() { }); }); - context('guest with double optin off', function() { - it('should create subscription events', function() { + context('guest with double optin off', function () { + it('should create subscription events', function () { const guestEmail = 'event.doptin-off.sub@guest-cypress.com'; subscribe(guestEmail); @@ -133,7 +133,7 @@ describe('Marketing Events', function() { }); }); - context('guest with double optin on', function() { + context('guest with double optin on', function () { before(() => { cy.task('setDoubleOptin', true); cy.task('flushMagentoCache'); @@ -143,7 +143,7 @@ describe('Marketing Events', function() { cy.task('setDoubleOptin', false); }); - it('should create newsletter_send_confirmation_request_email event', function() { + it('should create newsletter_send_confirmation_request_email event', function () { const guestEmail = 'event.doptin-on.sub@guest-cypress.com'; subscribe(guestEmail); diff --git a/dev/testv2/cypress/integration/web-extend.spec.js b/dev/testv2/cypress/integration/web-extend.spec.js index f9f49666..71e4a70c 100644 --- a/dev/testv2/cypress/integration/web-extend.spec.js +++ b/dev/testv2/cypress/integration/web-extend.spec.js @@ -4,7 +4,7 @@ const merchantId = 'merchantId123'; const webTrackingSnippetUrl = Cypress.env('snippetUrl'); const predictUrl = `http://cdn.scarabresearch.com/js/${merchantId}/scarab-v2.js`; -describe('Web extend scripts', function() { +describe('Web extend scripts', function () { before(() => { cy.task('setConfig', { injectSnippet: 'enabled', @@ -24,9 +24,9 @@ describe('Web extend scripts', function() { win.customerStub = cy.stub().as('customerStub'); const testScriptNode = win.document.createElement('script'); - testScriptNode.text = `window.require(['Magento_Customer/js/customer-data'], function(customerData) { + testScriptNode.text = `window.require(['Magento_Customer/js/customer-data'], function (customerData) { window.customerStub(customerData.get('customer')()) - customerData.get('customer').subscribe(function(customer) { + customerData.get('customer').subscribe(function (customer) { window.customerStub(customer); }); });`; @@ -38,7 +38,7 @@ describe('Web extend scripts', function() { cy.logout(); }); - it('should include web-extend scripts', function() { + it('should include web-extend scripts', function () { cy.visit('/'); cy.get('script').then(scripts => { @@ -48,7 +48,7 @@ describe('Web extend scripts', function() { }); }); - it('should include proper customer data', function() { + it('should include proper customer data', function () { cy.loginWithCustomer({ email: 'roni_cost@example.com', password: 'roni_cost3@example.com' }); cy.visit('/fusion-backpack.html'); @@ -60,7 +60,7 @@ describe('Web extend scripts', function() { }); }); - it('should include orderData after ordering as a guest', function() { + it('should include orderData after ordering as a guest', function () { cy.visit('/fusion-backpack.html'); cy.get('.loading-mask').should('not.exist'); @@ -71,9 +71,26 @@ describe('Web extend scripts', function() { cy.get('#product-addtocart-button').click(); cy.get('.counter-number').should('contain', '2'); + // Wait for the cart to update + cy.wait(100); cy.get('.action.showcart').click(); + cy.wait(300); cy.get('#top-cart-btn-checkout').click(); + cy.wait(1000); + + // Check if we are on the checkout page (if not, reload the page) + cy.url().then(url => { + cy.log(url); + + if (url.includes('checkout/cart') || url.includes('fusion-backpack')) { + cy.log('Reload checkout page'); + cy.visit('/checkout'); + } + }); + + cy.wait(1000); + cy.get('#checkout-step-shipping input.input-text[name="username"]').type('guest@cypress.net'); cy.get('#checkout-step-shipping input.input-text[name="firstname"]').type('Guest'); cy.get('#checkout-step-shipping input.input-text[name="lastname"]').type('Da Best'); @@ -103,7 +120,7 @@ describe('Web extend scripts', function() { }); }); - it('should include orderData after ordering as a logged in user', function() { + it('should include orderData after ordering as a logged in user', function () { cy.loginWithCustomer({ email: 'roni_cost@example.com', password: 'roni_cost3@example.com' }); cy.visit('/fusion-backpack.html'); diff --git a/dev/testv2/cypress/plugins/index.js b/dev/testv2/cypress/plugins/index.js index dd86e780..30583fb7 100644 --- a/dev/testv2/cypress/plugins/index.js +++ b/dev/testv2/cypress/plugins/index.js @@ -1,6 +1,6 @@ 'use strict'; -const Magento2ApiClient = require('@emartech/magento2-api'); +const Magento2ApiClient = require('@itg-commerce/magento2-api'); const db = require('../../helpers/db'); const { getTableName, cacheTablePrefix } = require('../../helpers/get-table-name'); const { getSentAddresses, clearMails } = require('../../helpers/mailhog'); diff --git a/dev/testv2/cypress/support/e2e.js b/dev/testv2/cypress/support/e2e.js index 45328341..3ee25381 100644 --- a/dev/testv2/cypress/support/e2e.js +++ b/dev/testv2/cypress/support/e2e.js @@ -41,7 +41,7 @@ Cypress.on('fail', error => { throw error; }); -console.log = function(...args) { +console.log = function (...args) { logs += args.join('\n'); logs += '\n'; }; diff --git a/dev/testv2/events/customer.spec.js b/dev/testv2/events/customer.spec.js index b09e4a7e..63836132 100644 --- a/dev/testv2/events/customer.spec.js +++ b/dev/testv2/events/customer.spec.js @@ -17,8 +17,8 @@ const customer = { ] }; -describe('Customer events', function() { - before(async function() { +describe('Customer events', function () { + before(async function () { await this.magentoApi.execute('attributes', 'set', { websiteId: 1, type: 'customer', @@ -26,12 +26,12 @@ describe('Customer events', function() { }); }); - afterEach(async function() { + afterEach(async function () { await this.db.raw(`DELETE FROM ${this.getTableName('customer_entity')} where email = "yolo99@yolo.net"`); await this.turnOffEverySetting(1); }); - after(async function() { + after(async function () { await this.magentoApi.execute('attributes', 'set', { websiteId: 1, type: 'customer', @@ -39,7 +39,7 @@ describe('Customer events', function() { }); }); - it('"customers/update" is saved in DB if customer is created', async function() { + it('"customers/update" is saved in DB if customer is created', async function () { await this.magentoApi.execute('config', 'set', { websiteId: 1, config: { collectCustomerEvents: 'enabled' } }); await this.createCustomer(customer); @@ -56,7 +56,7 @@ describe('Customer events', function() { expect(event.store_id).to.equal(1); }); - it('"customers/update" is saved in DB if customer is updated', async function() { + it('"customers/update" is saved in DB if customer is updated', async function () { const createdCustomer = await this.createCustomer(customer); await this.magentoApi.execute('config', 'set', { websiteId: 1, config: { collectCustomerEvents: 'enabled' } }); @@ -83,7 +83,7 @@ describe('Customer events', function() { expect(event.store_id).to.equal(1); }); - it('"customers/delete" is saved in DB if customer is deleted', async function() { + it('"customers/delete" is saved in DB if customer is deleted', async function () { const createdCustomer = await this.createCustomer(customer); await this.magentoApi.execute('config', 'set', { websiteId: 1, config: { collectCustomerEvents: 'enabled' } }); @@ -100,7 +100,7 @@ describe('Customer events', function() { expect(event.entity_id).to.eql(createdCustomer.entityId); }); - it('are not saved in DB if collectCustomerEvents is disabled', async function() { + it('are not saved in DB if collectCustomerEvents is disabled', async function () { await this.turnOffEverySetting(1); await this.createCustomer(customer); diff --git a/dev/testv2/events/endpoint.spec.js b/dev/testv2/events/endpoint.spec.js index b1fbb9ef..bb198d45 100644 --- a/dev/testv2/events/endpoint.spec.js +++ b/dev/testv2/events/endpoint.spec.js @@ -33,12 +33,12 @@ const customers = [ } ]; -describe('Events API endpoint', function() { - before(async function() { +describe('Events API endpoint', function () { + before(async function () { await this.magentoApi.execute('config', 'set', { websiteId: 1, config: { collectCustomerEvents: 'enabled' } }); }); - afterEach(async function() { + afterEach(async function () { await this.db.raw( `DELETE FROM ${this.getTableName( 'customer_entity' @@ -46,11 +46,11 @@ describe('Events API endpoint', function() { ); }); - after(async function() { + after(async function () { await this.turnOffEverySetting(1); }); - it('returns number of events defined in page_size and deletes events before since_id', async function() { + it('returns number of events defined in page_size and deletes events before since_id', async function () { for (const customer of customers) { await this.createCustomer(customer); } @@ -75,7 +75,7 @@ describe('Events API endpoint', function() { expect(firstEvent.store_id).to.equal(1); }); - it('returns 406 status if sinceId is higher than max event ID in the events table', async function() { + it('returns 406 status if sinceId is higher than max event ID in the events table', async function () { for (const customer of customers) { await this.createCustomer(customer); } @@ -95,7 +95,7 @@ describe('Events API endpoint', function() { expect(eventsResponse.events.length).to.equal(3); }); - it('does not return 406 status if sinceId is equal to the maximal event ID in the table', async function() { + it('does not return 406 status if sinceId is equal to the maximal event ID in the table', async function () { for (const customer of customers) { await this.createCustomer(customer); } @@ -105,7 +105,7 @@ describe('Events API endpoint', function() { expect(eventsResponse.events.length).to.equal(0); }); - it('does not return 406 status if there are no entries in the events table', async function() { + it('does not return 406 status if there are no entries in the events table', async function () { const eventsResponse = await this.magentoApi.execute('events', 'getSinceId', { sinceId: 1, pageSize: 10 }); expect(eventsResponse.events.length).to.equal(0); diff --git a/dev/testv2/inventory/get-inventory-for-products.spec.js b/dev/testv2/inventory/get-inventory-for-products.spec.js index d47f9671..fa67ed02 100644 --- a/dev/testv2/inventory/get-inventory-for-products.spec.js +++ b/dev/testv2/inventory/get-inventory-for-products.spec.js @@ -1,6 +1,6 @@ 'use strict'; -const createSource = async function(magentoApi) { +const createSource = async function (magentoApi) { return await magentoApi.post({ path: '/index.php/rest/V1/inventory/sources', payload: { @@ -15,7 +15,7 @@ const createSource = async function(magentoApi) { }); }; -const addStockForProductInInventorySource = async function(magentoApi) { +const addStockForProductInInventorySource = async function (magentoApi) { return await magentoApi.post({ path: '/index.php/rest/V1/inventory/source-items', payload: { @@ -35,9 +35,9 @@ const inventorySourceCode = 'custom_source'; const skuWithMultipleSources = '24-WB04'; const skuWithDefaultSource = '24-WB07'; -describe('Product inventory API', function() { +describe('Product inventory API', function () { - before(async function() { + before(async function () { if (this.magentoVersion >= '2.3.0') { await createSource(this.magentoApi); try { @@ -48,7 +48,7 @@ describe('Product inventory API', function() { } }); - it('should return product stock for all inventory sources', async function() { + it('should return product stock for all inventory sources', async function () { if (this.magentoVersion >= '2.3.0') { const { items } = await this.magentoApi.execute('inventory', 'getForProducts', { sku: [skuWithMultipleSources, skuWithDefaultSource] diff --git a/dev/testv2/orders/get.spec.js b/dev/testv2/orders/get.spec.js index da1dd9a2..c341c42c 100644 --- a/dev/testv2/orders/get.spec.js +++ b/dev/testv2/orders/get.spec.js @@ -4,10 +4,10 @@ const { shipOrder, createNewGuestOrder } = require('../helpers/orders'); const orderCount = 4; -describe('Orders endpoint', function() { +describe('Orders endpoint', function () { let localCartItem; - before(async function() { + before(async function () { await this.dbCleaner.clearOrders(); localCartItem = this.localCartItem; @@ -17,11 +17,11 @@ describe('Orders endpoint', function() { } }); - after(async function() { + after(async function () { await this.dbCleaner.clearOrders(); }); - it('should return orders and paging info according to parameters', async function() { + it('should return orders and paging info according to parameters', async function () { const limit = 1; const page = 1; const ordersResponse = await this.magentoApi.execute('orders', 'getSinceId', { @@ -40,7 +40,7 @@ describe('Orders endpoint', function() { expect(ordersResponse.orders[0].store_id).to.equal(1); }); - it('should handle multiple store IDs', async function() { + it('should handle multiple store IDs', async function () { const limit = 1; const page = 1; const ordersResponse = await this.magentoApi.execute('orders', 'getSinceId', { @@ -53,7 +53,7 @@ describe('Orders endpoint', function() { expect(ordersResponse.orderCount).to.be.equal(orderCount); }); - it('should filter for store IDs', async function() { + it('should filter for store IDs', async function () { const limit = 1; const page = 1; const ordersResponse = await this.magentoApi.execute('orders', 'getSinceId', { @@ -66,7 +66,7 @@ describe('Orders endpoint', function() { expect(ordersResponse.orderCount).to.be.equal(0); }); - it('should filter with sinceId', async function() { + it('should filter with sinceId', async function () { const limit = 1; const page = 2; const sinceId = 2; diff --git a/dev/testv2/package.json b/dev/testv2/package.json index 20b45d7b..c896cee9 100644 --- a/dev/testv2/package.json +++ b/dev/testv2/package.json @@ -5,11 +5,11 @@ "scripts": { "postinstall": "if [ -d \"./../../.git\" ]; then npm run copy-git-hooks; fi", "test": "npm run mocha && npm run code-style", - "e2e": "cypress run --browser chrome", - "e2e:ci": "cypress run --browser chrome --record --key 80ddf60c-0dca-4075-8074-31207092e038", - "e2e:debug": "DEBUG=cypress:* cypress run --browser chrome", + "e2e": "cypress run --browser electron --headless", + "e2e:ci": "cypress run --browser electron --headless --record --key 80ddf60c-0dca-4075-8074-31207092e038", + "e2e:debug": "DEBUG=cypress:* cypress run --browser electron --headless", "quick-test": "npm run mocha", - "mocha": "./node_modules/mocha/bin/mocha.js --exit --timeout 60000 --colors ./setup.spec.js './!(node_modules|cypress)/**/*.spec.js'", + "mocha": "./node_modules/mocha/bin/mocha.js --exit --timeout 120000 --colors ./setup.spec.js './!(node_modules|cypress)/**/*.spec.js'", "code-style": "eslint '!(node_modules)/**/**.js'", "copy-git-hooks": "cp -rf ./git-hooks/* ./../../.git/hooks && chmod +x ./../../.git/hooks/pre-commit && chmod +x ./../../.git/hooks/commit-msg" }, @@ -23,7 +23,7 @@ "author": "", "license": "UNLICENSED", "dependencies": { - "@emartech/magento2-api": "4.7.0", + "@itg-commerce/magento2-api": "4.7.0", "axios": "^1.6.7", "chai": "^4.4.1", "chai-string": "^1.5.0", diff --git a/dev/testv2/products/list.spec.js b/dev/testv2/products/list.spec.js index 578b999b..23fd14be 100644 --- a/dev/testv2/products/list.spec.js +++ b/dev/testv2/products/list.spec.js @@ -353,12 +353,21 @@ describe('Products endpoint', function () { originalPrice = configurableProduct.store_data.find((data) => data.store_id !== 0).price; await setPriceForEntityId(entityIdUsed, 0, this.db, this.magentoEdition); - await this.reindex(); + + try { + await this.reindex(); + } catch (e) { + console.log(e.message); + } }); after(async function () { await setPriceForEntityId(entityIdUsed, originalPrice, this.db, this.magentoEdition); - await this.reindex(); + try { + await this.reindex(); + } catch (e) { + console.log(e.message); + } }); it('returns configurable product min price if price or final price is 0', async function () { const { products } = await this.magentoApi.execute('products', 'get', requestParams); diff --git a/dev/testv2/setup.spec.js b/dev/testv2/setup.spec.js index 0d0620c8..78ffb1e3 100644 --- a/dev/testv2/setup.spec.js +++ b/dev/testv2/setup.spec.js @@ -6,7 +6,7 @@ const chaiSubset = require('chai-subset'); const sinon = require('sinon'); const sinonChai = require('sinon-chai'); const url = require('url'); -const Magento2ApiClient = require('@emartech/magento2-api'); +const Magento2ApiClient = require('@itg-commerce/magento2-api'); const axios = require('axios'); const { cacheTablePrefix, getTableName } = require('./helpers/get-table-name'); diff --git a/dev/testv2/system-info/get.spec.js b/dev/testv2/system-info/get.spec.js index 5ffbb77f..3b0f34bb 100644 --- a/dev/testv2/system-info/get.spec.js +++ b/dev/testv2/system-info/get.spec.js @@ -1,7 +1,7 @@ 'use strict'; -describe('SystemInfo API', function() { - it('should return system information', async function() { +describe('SystemInfo API', function () { + it('should return system information', async function () { const info = await this.magentoApi.execute('systeminfo', 'get'); @@ -11,13 +11,13 @@ describe('SystemInfo API', function() { expect(info.magento_edition).to.not.be.undefined; }); - it('should return customer DB website scope when configured so', async function() { + it('should return customer DB website scope when configured so', async function () { const info = await this.magentoApi.execute('systeminfo', 'get'); expect(info.is_website_scope).to.be.true; }); - it('should return customer DB website scope when configured so', async function() { + it('should return customer DB website scope when configured so', async function () { await this.db(this.getTableName('core_config_data')).insert( { scope: 'default', path: 'customer/account_share/scope', value: 0 } ); diff --git a/dev/testv2/tools/docker/docker-compose-test-elastic.yml b/dev/testv2/tools/docker/docker-compose-test-elastic.yml index 3bfadee1..fa89a1c4 100644 --- a/dev/testv2/tools/docker/docker-compose-test-elastic.yml +++ b/dev/testv2/tools/docker/docker-compose-test-elastic.yml @@ -22,7 +22,7 @@ services: - ../setup/reindex.php:/app/pub/reindex.php - ../setup/trigger_event.php:/app/trigger_event.php - ../setup/trigger_event.php:/app/pub/trigger_event.php - - ../setup/customer-data.js:/app/vendor/magento/module-customer/view/frontend/web/js/customer-data.js + # - ../setup/customer-data.js:/app/vendor/magento/module-customer/view/frontend/web/js/customer-data.js environment: - MAGENTO_URL=http://magento-test.local - MAGENTO_REPO_KEY=$MAGENTO_REPO_KEY @@ -40,13 +40,13 @@ services: - 'discovery.type=single-node' - 'ES_JAVA_OPTS=-Xms512m -Xmx512m' node: - # image: registry.itg.cloud/itg-commerce/emarsys-magento2-extension-test/mage_node:13.6.4 - build: - context: ../../.. - args: - - NPM_TOKEN=$NPM_TOKEN - dockerfile: testv2/tools/docker/Dockerfile-mage-node - container_name: mage_node + image: mage_node + # build: + # context: ../../.. + # args: + # - NPM_TOKEN=$NPM_TOKEN + # dockerfile: testv2/tools/docker/Dockerfile-mage-node + # container_name: mage_node ipc: host env_file: - ../setup/.env diff --git a/dev/testv2/tools/docker/docker-compose-test.yml b/dev/testv2/tools/docker/docker-compose-test.yml index d896433f..8478c760 100644 --- a/dev/testv2/tools/docker/docker-compose-test.yml +++ b/dev/testv2/tools/docker/docker-compose-test.yml @@ -1,4 +1,4 @@ -version: "3.2" +version: '3.2' services: db: @@ -22,7 +22,7 @@ services: - ../setup/reindex.php:/app/pub/reindex.php - ../setup/trigger_event.php:/app/trigger_event.php - ../setup/trigger_event.php:/app/pub/trigger_event.php - - ../setup/customer-data.js:/app/vendor/magento/module-customer/view/frontend/web/js/customer-data.js + # - ../setup/customer-data.js:/app/vendor/magento/module-customer/view/frontend/web/js/customer-data.js environment: - MAGENTO_URL=http://magento-test.local - MAGENTO_REPO_KEY=$MAGENTO_REPO_KEY @@ -30,25 +30,17 @@ services: - PHP_SENDMAIL_PATH='/usr/local/bin/mhsendmail --smtp-addr="mailhog:1025"' env_file: - ../setup/.env - command: - [ - "/opt/emartech/wait-for-it.sh", - "db:3306", - "--timeout=30", - "--strict", - "--", - "/opt/emartech/init", - ] + command: ['/opt/emartech/wait-for-it.sh', 'db:3306', '--timeout=30', '--strict', '--', '/opt/emartech/init'] links: - db node: - # image: registry.itg.cloud/itg-commerce/emarsys-magento2-extension-test/mage_node:13.6.4 - build: - context: ../../.. - args: - - NPM_TOKEN=$NPM_TOKEN - dockerfile: testv2/tools/docker/Dockerfile-mage-node - container_name: mage_node + image: mage_node + # build: + # context: ../../.. + # args: + # - NPM_TOKEN=$NPM_TOKEN + # dockerfile: testv2/tools/docker/Dockerfile-mage-node + # container_name: mage_node ipc: host env_file: - ../setup/.env diff --git a/dev/testv2/tools/scripts/run-e2e-local.sh b/dev/testv2/tools/scripts/run-e2e-local.sh index 6d04e196..28121d75 100755 --- a/dev/testv2/tools/scripts/run-e2e-local.sh +++ b/dev/testv2/tools/scripts/run-e2e-local.sh @@ -30,7 +30,7 @@ echo "\n|--- Running tests on Magento $VERSION" echo "\n|--- Pulling newest image version" docker pull registry.itg.cloud/itg-commerce/emarsys-magento2-extension-test/ems-integration-magento-sampledata:$VERSION echo "\n|--- Starting containers" -docker compose -p mage_e2e_$project_version -f $composefile up -d +docker compose -p mage_e2e_$project_version -f $composefile up --build -d echo "\n|--- Waiting for containers to initialize" sh ./wait.sh e2e >>/dev/null 2>&1 echo "\n|--- Running frontend tests" @@ -39,4 +39,4 @@ exitcode=$? echo "\n\n|--- All tests passed" docker compose -p mage_e2e_$project_version -f $composefile down -exit $exitcode \ No newline at end of file +exit $exitcode diff --git a/dev/testv2/tools/scripts/run-e2e.sh b/dev/testv2/tools/scripts/run-e2e.sh index 5ec29566..a5ca1d7b 100644 --- a/dev/testv2/tools/scripts/run-e2e.sh +++ b/dev/testv2/tools/scripts/run-e2e.sh @@ -21,7 +21,7 @@ echo "\n|--- Running tests on Magento $VERSION" echo "\n|--- Pulling newest image version" docker pull registry.itg.cloud/itg-commerce/emarsys-magento2-extension-test/ems-integration-magento-sampledata:"$VERSION" echo "\n|--- Starting containers" -docker compose -p mage_e2e_"$project_version" -f $composefile up -d +docker compose -p mage_e2e_"$project_version" -f $composefile up --build -d echo "\n|--- Waiting for containers to initialize" sh ./wait.sh e2e >>/dev/null 2>&1 echo "\n|--- Running frontend tests" @@ -30,4 +30,4 @@ exitcode=$? echo "\n\n|--- All tests passed" docker compose -p mage_e2e_"$project_version" -f $composefile down -exit $exitcode \ No newline at end of file +exit $exitcode diff --git a/dev/testv2/tools/scripts/run-unit-local.sh b/dev/testv2/tools/scripts/run-unit-local.sh index 88336874..8de1319b 100755 --- a/dev/testv2/tools/scripts/run-unit-local.sh +++ b/dev/testv2/tools/scripts/run-unit-local.sh @@ -30,7 +30,7 @@ echo "\n|--- Running tests on Magento $VERSION" echo "\n|--- Pulling newest image version" docker pull registry.itg.cloud/itg-commerce/emarsys-magento2-extension-test/ems-integration-magento-sampledata:$VERSION echo "\n|--- Starting containers" -docker compose -p mage_unit_$project_version -f $composefile up -d +docker compose -p mage_unit_$project_version -f $composefile up --build -d echo "\n|--- Waiting for containers to initialize" sh ./wait.sh unit >>/dev/null 2>&1 diff --git a/dev/testv2/tools/scripts/run-unit.sh b/dev/testv2/tools/scripts/run-unit.sh index ad13316b..e0e82fe2 100644 --- a/dev/testv2/tools/scripts/run-unit.sh +++ b/dev/testv2/tools/scripts/run-unit.sh @@ -23,7 +23,7 @@ echo "\n|--- Running tests on Magento $VERSION" echo "\n|--- Pulling newest image version" docker pull registry.itg.cloud/itg-commerce/emarsys-magento2-extension-test/ems-integration-magento-sampledata:$VERSION echo "\n|--- Starting containers" -docker compose -p mage_unit_$project_version -f $composefile up -d +docker compose -p mage_unit_$project_version -f $composefile up --build -d echo "\n|--- Waiting for containers to initialize" sh ./wait.sh unit >>/dev/null 2>&1 @@ -38,4 +38,4 @@ docker compose -p mage_unit_$project_version -f $composefile run --rm node sh -c exitcode=$? echo "\n\n|--- Stopping containers" docker compose -p mage_unit_$project_version -f $composefile down -exit $exitcode \ No newline at end of file +exit $exitcode diff --git a/dev/testv2/tools/setup/setup b/dev/testv2/tools/setup/setup index a110c968..4530f52a 100644 --- a/dev/testv2/tools/setup/setup +++ b/dev/testv2/tools/setup/setup @@ -25,5 +25,8 @@ fi mysql -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE -e "UPDATE ${TABLE_PREFIX}oauth_token SET token = 'Almafa456';" +echo "-|| Update cookie lifetime" +bin/magento config:set web/cookie/cookie_lifetime 36000 + echo "-|| Flushing cache" -bin/magento cache:flush \ No newline at end of file +bin/magento cache:flush diff --git a/dev/testv2/webextend/script.spec.js b/dev/testv2/webextend/script.spec.js index d0db9215..e8992403 100644 --- a/dev/testv2/webextend/script.spec.js +++ b/dev/testv2/webextend/script.spec.js @@ -45,8 +45,8 @@ const insertNewCategoryBetween = async (magentoApi, { name, parentId, childId }) }; describe('Webextend scripts', function () { - describe('enabled', function() { - beforeEach(async function() { + describe('enabled', function () { + beforeEach(async function () { await this.magentoApi.execute('config', 'set', { websiteId: 1, config: { @@ -57,7 +57,7 @@ describe('Webextend scripts', function () { }); }); - it('should be in the HTML if injectsnippet is enabled', async function() { + it('should be in the HTML if injectsnippet is enabled', async function () { const emarsysSnippets = await getEmarsysSnippetContents('customer/account/login/'); expect(emarsysSnippets.includes('')).to.be.true; @@ -77,7 +77,7 @@ describe('Webextend scripts', function () { ).to.be.true; }); - it('should include search term', async function() { + it('should include search term', async function () { const emarsysSnippets = await getEmarsysSnippetContents('catalogsearch/result/?q=magento+is+hit'); expect( emarsysSnippets.includes( @@ -87,7 +87,7 @@ describe('Webextend scripts', function () { ).to.be.true; }); - it('should include categories in the right order', async function() { + it('should include categories in the right order', async function () { let parentCategoryId = '11'; let childCategoryId = '12'; @@ -117,7 +117,7 @@ describe('Webextend scripts', function () { ).to.be.true; }); - it('should include product', async function() { + it('should include product', async function () { const emarsysSnippets = await getEmarsysSnippetContents('cassius-sparring-tank.html'); let productHelper = new ProductHelper(this.db, this.magentoEdition, this.magentoVersion); @@ -131,7 +131,7 @@ describe('Webextend scripts', function () { ).to.be.true; }); - it('should include if product is visible child', async function() { + it('should include if product is visible child', async function () { await alterProductVisibility(this.magentoApi, 'MT12-XS-Blue'); const emarsysSnippets = await getEmarsysSnippetContents('cassius-sparring-tank-xs-blue.html'); @@ -139,16 +139,16 @@ describe('Webextend scripts', function () { expect(emarsysSnippets.includes('"isVisibleChild":true')).to.be.true; }); - describe('store is not enabled', function() { - before(async function() { + describe('store is not enabled', function () { + before(async function () { await this.clearStoreSettings(); }); - after(async function() { + after(async function () { await this.setDefaultStoreSettings(); }); - it('should not be in the HTML', async function() { + it('should not be in the HTML', async function () { await this.turnOffEverySetting(1); const emarsysSnippets = await getEmarsysSnippetContents('customer/account/login/'); expect(emarsysSnippets).to.eql(''); @@ -157,7 +157,7 @@ describe('Webextend scripts', function () { }); describe('disabled', function () { - it('should not be in the HTML if injectsnippet setting is disabled', async function() { + it('should not be in the HTML if injectsnippet setting is disabled', async function () { await this.turnOffEverySetting(1); const emarsysSnippets = await getEmarsysSnippetContents('customer/account/login/'); expect(emarsysSnippets).to.eql('');