From 14ae788203513dfe70137af63311603938a54da5 Mon Sep 17 00:00:00 2001 From: Sebastian Seggewiss Date: Wed, 11 Jan 2023 09:50:55 +0100 Subject: [PATCH] 7.0.1 --- cypress/support/commands/api-commands.js | 39 ++++++++++++------- cypress/support/commands/fixture-commands.js | 34 ++++++++-------- .../commands/storefront-api-commands.js | 4 +- package.json | 2 +- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/cypress/support/commands/api-commands.js b/cypress/support/commands/api-commands.js index d6122c2..b6e7930 100644 --- a/cypress/support/commands/api-commands.js +++ b/cypress/support/commands/api-commands.js @@ -51,10 +51,20 @@ Cypress.Commands.add('authenticate', () => { }, }).then(() => true); }); - } + }, } ); + return cy.getBearerAuth(); +}); + +/** + * Get current Bearer token + * @memberOf Cypress.Chainable# + * @name getBearerAuth + * @function + */ +Cypress.Commands.add('getBearerAuth', () => { return cy.getCookie('bearerAuth').then((cookie) => { return JSON.parse(decodeURIComponent(cookie && cookie.value)); }); @@ -68,8 +78,8 @@ Cypress.Commands.add('authenticate', () => { * @param {Object} data - Necessary data for the API request */ Cypress.Commands.add('searchViaAdminApi', (data) => { - return cy.authenticate().then((authInformation) => { - const fixture = new Fixture(authInformation); + return cy.getBearerAuth().then((authData) => { + const fixture = new Fixture(authData); return fixture.search(data.endpoint, { field: data.data.field, @@ -89,7 +99,7 @@ Cypress.Commands.add('searchViaAdminApi', (data) => { * @function */ Cypress.Commands.add('requestAdminApi', (method, url, requestData = {}) => { - return cy.authenticate().then((result) => { + return cy.getBearerAuth().then((result) => { const requestConfig = { headers: { Accept: 'application/vnd.api+json', @@ -133,17 +143,16 @@ Cypress.Commands.add('requestAdminApi', (method, url, requestData = {}) => { * @function */ Cypress.Commands.add('clearCacheAdminApi', (method, url) => { - return cy.authenticate().then((result) => { - return cy.getCookie('bearerAuth').then((cookie) => { - const requestConfig = { - headers: { - Authorization: `Bearer ${JSON.parse(cookie.value).access}` - }, - method: method, - url: url - }; - return cy.request(requestConfig); - }) + return cy.getBearerAuth().then((bearerToken) => { + const requestConfig = { + headers: { + Authorization: `Bearer ${bearerToken.access}` + }, + method: method, + url: url + }; + + return cy.request(requestConfig); }); }); diff --git a/cypress/support/commands/fixture-commands.js b/cypress/support/commands/fixture-commands.js index 9495326..2fe5305 100644 --- a/cypress/support/commands/fixture-commands.js +++ b/cypress/support/commands/fixture-commands.js @@ -21,7 +21,7 @@ const Fixture = require('../service/administration/fixture.service'); * @param {String} jsonPath - Path to JSON if it's deviating from endpoint */ Cypress.Commands.add('createDefaultFixture', (endpoint, data = {}, jsonPath) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new Fixture(authInformation); let finalRawData = {}; @@ -45,7 +45,7 @@ Cypress.Commands.add('createDefaultFixture', (endpoint, data = {}, jsonPath) => * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createProductFixture', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new ProductFixture(authInformation); return cy.fixture('product').then((result) => { @@ -64,7 +64,7 @@ Cypress.Commands.add('createProductFixture', (userData = {}) => { * @param {object} [userData={}] - Additional category data */ Cypress.Commands.add('createCategoryFixture', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new CategoryFixture(authInformation); return cy.fixture('category').then((result) => { @@ -83,7 +83,7 @@ Cypress.Commands.add('createCategoryFixture', (userData = {}) => { * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createSalesChannelFixture', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new AdminSalesChannelFixture(authInformation); return cy.fixture('sales-channel').then((result) => { @@ -102,7 +102,7 @@ Cypress.Commands.add('createSalesChannelFixture', (userData = {}) => { * @param {String} [salesChannelName=Storefront] - Name of the sales channel to work on */ Cypress.Commands.add('setSalesChannelDomain', (salesChannelName = 'Storefront') => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new AdminSalesChannelFixture(authInformation); return fixture.setSalesChannelDomain(salesChannelName) }); @@ -116,7 +116,7 @@ Cypress.Commands.add('setSalesChannelDomain', (salesChannelName = 'Storefront') * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createCustomerFixture', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new CustomerFixture(authInformation); let customerJson = null; @@ -137,7 +137,7 @@ Cypress.Commands.add('createCustomerFixture', (userData = {}) => { * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createCmsFixture', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new CmsFixture(authInformation); let pageJson = null; @@ -165,7 +165,7 @@ Cypress.Commands.add('createCmsFixture', (userData = {}) => { * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createPropertyFixture', (options = {}, userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { let json = {}; const fixture = new Fixture(authInformation); @@ -186,7 +186,7 @@ Cypress.Commands.add('createPropertyFixture', (options = {}, userData = {}) => { * @function */ Cypress.Commands.add('createLanguageFixture', () => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { let json = {}; const fixture = new Fixture(authInformation); @@ -218,7 +218,7 @@ Cypress.Commands.add('createLanguageFixture', () => { * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createShippingFixture', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new ShippingFixture(authInformation); return cy.fixture('shipping-method').then((result) => { @@ -237,7 +237,7 @@ Cypress.Commands.add('createShippingFixture', (userData = {}) => { * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createPaymentMethodFixture', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new PaymentMethodFixture(authInformation); return cy.fixture('payment-method').then((result) => { @@ -256,7 +256,7 @@ Cypress.Commands.add('createPaymentMethodFixture', (userData = {}) => { * @param {Object} [recipient={}] - Options concerning creation */ Cypress.Commands.add('createNewsletterRecipientFixture', (recipient = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new NewsletterRecipientFixture(authInformation); return cy.fixture('customer').then((result) => { @@ -274,7 +274,7 @@ Cypress.Commands.add('createNewsletterRecipientFixture', (recipient = {}) => { * @function */ Cypress.Commands.add('createSnippetFixture', () => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { let json = {}; const fixture = new Fixture(authInformation); @@ -317,7 +317,7 @@ Cypress.Commands.add('createSnippetFixture', () => { * @param {Object} [customer={}] - Options concerning customer */ Cypress.Commands.add('createOrder', (productId, customer = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new OrderFixture(authInformation); return fixture.createOrder(productId, customer); @@ -333,7 +333,7 @@ Cypress.Commands.add('createOrder', (productId, customer = {}) => { * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createGuestOrder', (productId, userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new OrderFixture(authInformation); return cy.fixture('storefront-customer').then((result) => { @@ -352,7 +352,7 @@ Cypress.Commands.add('createGuestOrder', (productId, userData = {}) => { * @param {Object} [userData={}] - Data proved for this order to be created */ Cypress.Commands.add('createAdminOrder', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new OrderAdminFixture(authInformation); return cy.fixture('order').then((result) => { @@ -371,7 +371,7 @@ Cypress.Commands.add('createAdminOrder', (userData = {}) => { * @param {Object} [userData={}] - Options concerning creation */ Cypress.Commands.add('createPromotionFixture', (userData = {}) => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new OrderFixture(authInformation); let promotionId = ''; diff --git a/cypress/support/commands/storefront-api-commands.js b/cypress/support/commands/storefront-api-commands.js index 2764aeb..a77ff90 100644 --- a/cypress/support/commands/storefront-api-commands.js +++ b/cypress/support/commands/storefront-api-commands.js @@ -28,7 +28,7 @@ Cypress.Commands.add('createViaAdminApi', (data) => { * @function */ Cypress.Commands.add('getSalesChannelId', () => { - return cy.authenticate().then((result) => { + return cy.getBearerAuth().then((result) => { const parameters = { data: { headers: { @@ -359,7 +359,7 @@ Cypress.Commands.add('setAnalyticsFixtureToSalesChannel', (state) => { * @param {String} [shippingMethodName="Standard"] - NAme of the shipping method */ Cypress.Commands.add('createRuleFixtureStorefront', (userData = {}, shippingMethodName = 'Standard') => { - return cy.authenticate().then((authInformation) => { + return cy.getBearerAuth().then((authInformation) => { const fixture = new RuleBuilderFixture(authInformation); return cy.fixture('rule-builder-shipping-payment.json').then((result) => { diff --git a/package.json b/package.json index 66db1da..527d357 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@shopware-ag/e2e-testsuite-platform", - "version": "7.0.0", + "version": "7.0.1", "description": "E2E Testsuite for Shopware 6 using Cypress.js", "keywords": [ "e2e",