diff --git a/projects/storefrontapp-e2e-cypress/cypress/e2e/b2b/regression/asm/asm.core-e2e.cy.ts b/projects/storefrontapp-e2e-cypress/cypress/e2e/b2b/regression/asm/asm.core-e2e.cy.ts index 7968ce6b4bb..f6a33f0c225 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/e2e/b2b/regression/asm/asm.core-e2e.cy.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/e2e/b2b/regression/asm/asm.core-e2e.cy.ts @@ -65,7 +65,7 @@ context('B2B - Assisted Service Module', () => { cy.findByText(/Continue/i).click(); - cy.wait('@getCostCenters'); + cy.wait('@getCostCenters').its('response.statusCode').should('eq', 200); }); }); }); diff --git a/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/asm/asm.deeplink.core-e2e.cy.ts b/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/asm/asm.deeplink.core-e2e.cy.ts index c4c6e713ac5..fbb8bfac886 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/asm/asm.deeplink.core-e2e.cy.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/asm/asm.deeplink.core-e2e.cy.ts @@ -5,7 +5,7 @@ */ import * as asm from '../../../helpers/asm'; -import { agentLoginForJDK21, login } from '../../../helpers/auth-forms'; +import { login } from '../../../helpers/auth-forms'; import * as customerTicketing from '../../../helpers/customer-ticketing/customer-ticketing'; import { signOutUser } from '../../../helpers/login'; import * as savedCart from '../../../helpers/saved-cart'; @@ -24,10 +24,13 @@ import { doPlaceOrderForB2CCustomerForJDK21, emulateExistedCustomerPrepare, getCurrentCartIdAndAddProducts, + getCurrentCartIdAndAddProductsForJdk21, getCustomerId, getCustomerIdForJDK21, + getCustomerIdWithAgentToken, getInactiveCartIdAndAddProducts, getInactiveCartIdAndAddProductsForJDK21, + getToken, } from '../../../helpers/asm'; import { waitForPage } from '../../../helpers/navigation'; @@ -64,8 +67,6 @@ context('Assisted Service Module', () => { ).then((customerId) => { cy.visit('/assisted-service/emulate?customerId=' + customerId); - agentLoginForJDK21(b2cAgent.userName, b2cAgent.password); - cy.log('--> Should has assignCart'); cy.get('.cx-asm-assignCart-input-show-no-button').should('exist'); }); @@ -138,8 +139,6 @@ context('Assisted Service Module', () => { cy.get('cx-asm-main-ui').should('exist'); cy.get('cx-asm-main-ui').should('be.visible'); - agentLoginForJDK21(b2cAgent.userName, b2cAgent.password); - cy.log('--> Should has assignCart'); cy.get('.cx-asm-assignCart-input-show-no-button').should('exist'); @@ -193,8 +192,6 @@ context('Assisted Service Module', () => { cy.get('cx-asm-main-ui').should('exist'); cy.get('cx-asm-main-ui').should('be.visible'); - asm.agentLogin(b2cAgent.userName, b2cAgent.password); - cy.log('--> Should has assignCart'); cy.get('.cx-asm-assignCart-input-show-no-button').should('exist'); @@ -220,7 +217,6 @@ context('Assisted Service Module', () => { cy.get( '.cx-asm-customer-list .cx-asm-customer-list-link' ).click(); - agentLoginForJDK21(b2cAgent.userName, b2cAgent.password); cy.log('--> Should has assignCart'); cy.get('.cx-asm-assignCart-input-show-no-button').should('exist'); @@ -305,7 +301,6 @@ context('Assisted Service Module', () => { cy.get('cx-asm-main-ui').should('be.visible'); cy.get('.cx-asm-customer-list .cx-asm-customer-list-link').click(); - agentLoginForJDK21(b2cAgent.userName, b2cAgent.password); cy.log('--> Should has assignCart'); cy.get('.cx-asm-assignCart-input-show-no-button').should('exist'); @@ -420,38 +415,40 @@ context('Assisted Service Module', () => { 'have.text', customerOld.email ); - - getCustomerIdForJDK21( - b2cAgent.userName, - b2cAgent.password, - customerNew.email - ).then((customerNewId) => { - cy.visit('/assisted-service/emulate?customerId=' + customerNewId); - - cy.log('--> Switch emulated customer dialog should be exist'); - cy.get('cx-asm-switch-customer-dialog').should('exist'); - - cy.log('--> Click switch button to switch to emulate new customer'); - cy.get( - 'cx-asm-switch-customer-dialog .cx-dialog-footer .btn-primary' - ) - .should('exist') - .click(); - - cy.log('--> Should has emulated new customer'); - cy.get('.cx-asm-customerInfo .cx-asm-name').should( - 'have.text', - customerNew.fullName - ); - cy.get('.cx-asm-customerInfo .cx-asm-uid').should( - 'have.text', - customerNew.email + getToken().then((token) => { + getCustomerIdWithAgentToken(token, customerNew.email).then( + (customerNewId) => { + cy.visit( + '/assisted-service/emulate?customerId=' + customerNewId + ); + + cy.log('--> Switch emulated customer dialog should be exist'); + cy.get('cx-asm-switch-customer-dialog').should('exist'); + + cy.log( + '--> Click switch button to switch to emulate new customer' + ); + cy.get( + 'cx-asm-switch-customer-dialog .cx-dialog-footer .btn-primary' + ) + .should('exist') + .click(); + + cy.log('--> Should has emulated new customer'); + cy.get('.cx-asm-customerInfo .cx-asm-name').should( + 'have.text', + customerNew.fullName + ); + cy.get('.cx-asm-customerInfo .cx-asm-uid').should( + 'have.text', + customerNew.email + ); + } ); }); }); }); }); - it('should not to switch emulated customer with deeplink when click cancel after agent login (CXSPA-3380)', () => { let customerA = getASMB2CCustomer(); const customerB = getASMB2CCustomer2(); @@ -524,30 +521,30 @@ context('Assisted Service Module', () => { customerA.email ); - getCustomerIdForJDK21( - b2cAgent.userName, - b2cAgent.password, - customerB.email - ).then((customerId2) => { - cy.visit('/assisted-service/emulate?customerId=' + customerId2); - - cy.log('--> Switch emulated customer dialog should be exist'); - cy.get('cx-asm-switch-customer-dialog').should('exist'); - - cy.log('--> Click cancel button to not switch customer'); - cy.get( - 'cx-asm-switch-customer-dialog .cx-dialog-footer .btn-secondary' - ).should('exist'); - cy.findByText(/Cancel/i).click(); - - cy.log('--> Should still emulated customerA'); - cy.get('.cx-asm-customerInfo .cx-asm-name').should( - 'have.text', - customerA.fullName - ); - cy.get('.cx-asm-customerInfo .cx-asm-uid').should( - 'have.text', - customerA.email + getToken().then((token) => { + getCustomerIdWithAgentToken(token, customerB.email).then( + (customerId2) => { + cy.visit('/assisted-service/emulate?customerId=' + customerId2); + + cy.log('--> Switch emulated customer dialog should be exist'); + cy.get('cx-asm-switch-customer-dialog').should('exist'); + + cy.log('--> Click cancel button to not switch customer'); + cy.get( + 'cx-asm-switch-customer-dialog .cx-dialog-footer .btn-secondary' + ).should('exist'); + cy.findByText(/Cancel/i).click(); + + cy.log('--> Should still emulated customerA'); + cy.get('.cx-asm-customerInfo .cx-asm-name').should( + 'have.text', + customerA.fullName + ); + cy.get('.cx-asm-customerInfo .cx-asm-uid').should( + 'have.text', + customerA.email + ); + } ); }); }); @@ -872,16 +869,6 @@ context('Assisted Service Module', () => { `/assisted-service/emulate?customerId=${customerId}&cartId=${activeCartId}&cartType=active` ); - // cy.log('--> set input should be active cart id'); - // cy.get( - // 'cx-customer-emulation input[formcontrolname="cartNumber"]' - // ).should('have.value', activeCartId); - - // cy.log('--> the message strip should be display'); - // cy.get('cx-asm-save-cart-dialog .cx-message-info button cx-icon') - // .should('exist') - // .click(); - cy.log('--> Should navigate to current cart page'); cy.get('.cart-details-wrapper .cx-total').should( 'contain', @@ -900,44 +887,35 @@ context('Assisted Service Module', () => { }); cy.whenJDK21(() => { - getCustomerIdForJDK21( - b2cAgent.userName, - b2cAgent.password, - customer.email - ).then((customerId) => { - asm - .getCurrentCartIdAndAddProducts( - customer.email, - customer.password, - '1934793', - '2' - ) - .then((activeCartId) => { - cy.visit( - `/assisted-service/emulate?customerId=${customerId}&cartId=${activeCartId}&cartType=active` - ); - - // cy.log('--> set input should be active cart id'); - // cy.get( - // 'cx-customer-emulation input[formcontrolname="cartNumber"]' - // ).should('have.value', activeCartId); + getCurrentCartIdAndAddProductsForJdk21( + customer.email, + customer.password, + '1934793', + '2' + ).then((activeCartId) => { + signOutUser(); - // cy.log('--> the message strip should be display'); - // cy.get('cx-asm-save-cart-dialog .cx-message-info button cx-icon') - // .should('exist') - // .click(); + getCustomerIdForJDK21( + b2cAgent.userName, + b2cAgent.password, + customer.email + ).then((customerId) => { + cy.visit( + `/assisted-service/emulate?customerId=${customerId}&cartId=${activeCartId}&cartType=active` + ); - cy.log('--> Should navigate to current cart page'); - cy.get('.cart-details-wrapper .cx-total').should( - 'contain', - activeCartId - ); + cy.log('--> Should navigate to current cart page'); + cy.get('.cart-details-wrapper .cx-total').should( + 'contain', + activeCartId + ); - cy.get('cx-asm-main-ui').should('exist'); - cy.get('cx-asm-main-ui').should('be.visible'); + cy.get('cx-asm-main-ui').should('exist'); + cy.get('cx-asm-main-ui').should('be.visible'); - cy.url().should('contain', '/cart'); - }); + cy.url().should('contain', '/cart'); + cy.log('--> test end'); + }); }); }); }); @@ -963,16 +941,6 @@ context('Assisted Service Module', () => { `/assisted-service/emulate?customerId=${customerId}&ticketId=00000008&cartId=${activeCartId}&cartType=active` ); - // cy.log('--> set input should be active cart id'); - // cy.get( - // 'cx-customer-emulation input[formcontrolname="cartNumber"]' - // ).should('have.value', activeCartId); - - // cy.log('--> the message strip should be display'); - // cy.get('cx-asm-save-cart-dialog .cx-message-info button cx-icon') - // .should('exist') - // .click(); - cy.log('--> Should navigate to current cart page'); cy.get('.cart-details-wrapper .cx-total').should( 'contain', @@ -988,31 +956,22 @@ context('Assisted Service Module', () => { }); cy.whenJDK21(() => { - getCustomerIdForJDK21( - b2cAgent.userName, - b2cAgent.password, - customer.email - ).then((customerId) => { - getCurrentCartIdAndAddProducts( - customer.email, - customer.password, - '1934793', - '2' - ).then((activeCartId) => { + getCurrentCartIdAndAddProductsForJdk21( + customer.email, + customer.password, + '1934793', + '2' + ).then((activeCartId) => { + signOutUser(); + getCustomerIdForJDK21( + b2cAgent.userName, + b2cAgent.password, + customer.email + ).then((customerId) => { cy.visit( `/assisted-service/emulate?customerId=${customerId}&ticketId=00000008&cartId=${activeCartId}&cartType=active` ); - cy.log('--> set input should be active cart id'); - cy.get( - 'cx-customer-emulation input[formcontrolname="cartNumber"]' - ).should('have.value', activeCartId); - - cy.log('--> the message strip should be display'); - cy.get('cx-asm-save-cart-dialog .cx-message-info button cx-icon') - .should('exist') - .click(); - cy.log('--> Should navigate to current cart page'); cy.get('.cart-details-wrapper .cx-total').should( 'contain', @@ -1023,6 +982,8 @@ context('Assisted Service Module', () => { cy.get('cx-asm-main-ui').should('be.visible'); cy.url().should('contain', '/cart'); + + cy.log('--> test end'); }); }); }); @@ -1129,17 +1090,18 @@ context('Assisted Service Module', () => { }); }); cy.whenJDK21(() => { - getCustomerIdForJDK21( - b2cAgent.userName, - b2cAgent.password, - customer.email - ).then((customerId) => { - getInactiveCartIdAndAddProductsForJDK21( - customer.email, - customer.password, - '1934793', - '2' - ).then((inactiveCartId) => { + getInactiveCartIdAndAddProductsForJDK21( + customer.email, + customer.password, + '1934793', + '2' + ).then((inactiveCartId) => { + signOutUser(); + getCustomerIdForJDK21( + b2cAgent.userName, + b2cAgent.password, + customer.email + ).then((customerId) => { cy.visit( `/assisted-service/emulate?customerId=${customerId}&cartId=${inactiveCartId}&cartType=inactive` ); @@ -1180,6 +1142,8 @@ context('Assisted Service Module', () => { ); cy.url().should('include', 'saved-cart'); cy.url().should('include', inactiveCartId); + + cy.log('--> test end'); }); }); }); @@ -1188,9 +1152,9 @@ context('Assisted Service Module', () => { it('should not save empty inactive cart in deeplink after agent login (CXSPA-3278)', () => { let customer = getASMB2CCustomer(); - emulateExistedCustomerPrepare(b2cAgent.userName, b2cAgent.password); - cy.whenJDK17(() => { + emulateExistedCustomerPrepare(b2cAgent.userName, b2cAgent.password); + getInactiveCartIdAndAddProducts(customer.email, customer.password).then( (inactiveCartId) => { cy.log('--> create inactive cart'); @@ -1245,7 +1209,7 @@ context('Assisted Service Module', () => { customer.password ).then((inactiveCartId) => { cy.log('--> create inactive cart'); - cy.get('button.logout').should('exist').and('be.visible').click(); + signOutUser(); getCustomerIdForJDK21( b2cAgent.userName, b2cAgent.password, @@ -1281,6 +1245,8 @@ context('Assisted Service Module', () => { ); cy.get('button[id=asm-save-cart-dialog-btn]').should('be.disabled'); cy.findByText(/Cancel/i).click(); + + cy.log('--> test end'); }); }); }); diff --git a/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/asm/asm.emulation.core-e2e.cy.ts b/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/asm/asm.emulation.core-e2e.cy.ts index 6cb2e8c9c2d..0a837b2049a 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/asm/asm.emulation.core-e2e.cy.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/e2e/regression/asm/asm.emulation.core-e2e.cy.ts @@ -12,8 +12,6 @@ import { getErrorAlert } from '../../../helpers/global-message'; import { navigateToCategory, waitForPage } from '../../../helpers/navigation'; import { APPAREL_BASESITE } from '../../../helpers/variants/apparel-checkout-flow'; import { getB2CAgent } from '../../../sample-data/asm-flow'; -import { getSampleUser } from '../../../sample-data/checkout-flow'; -import { clearAllStorage } from '../../../support/utils/clear-all-storage'; import { visitLoginPage } from '../../../support/utils/login'; const b2cAgent = getB2CAgent(); @@ -22,10 +20,7 @@ context('Assisted Service Module', () => { asm.testCustomerEmulation(); it('should checkout as customer (CXSPA-7026)', () => { - const customer = getSampleUser(); - cy.log('--> Register user'); - checkout.visitHomePage(); - checkout.registerUser(false, customer); + const customer = asm.registerUser(); cy.log('--> Agent logging in'); checkout.visitHomePage('asm=true'); cy.get('cx-asm-main-ui').should('exist'); @@ -83,17 +78,8 @@ context('Assisted Service Module', () => { }); describe('When a customer session and an asm agent session are both active', () => { - let customer; - - before(() => { - clearAllStorage(); - checkout.visitHomePage(); - - customer = getSampleUser(); - checkout.registerUser(false, customer); - }); - it('Customer should not be able to login when there is an active CS agent session (CXSPA-10932)', () => { + const customer = asm.registerUser(); cy.whenJDK17(() => { const loginPage = waitForPage('/login', 'getLoginPage'); cy.visit('/login?asm=true'); @@ -116,6 +102,7 @@ context('Assisted Service Module', () => { // TODO(#3974): fix the bug to enable e2e test for this scenario it('agent login when user is logged in should start this user emulation', () => { + const customer = asm.registerUser(); cy.whenJDK17(() => { visitLoginPage(); }); @@ -148,6 +135,7 @@ context('Assisted Service Module', () => { // TODO(#7221): enable this case it('agent logout when user was logged and emulated should restore the session', () => { + const customer = asm.registerUser(); checkout.visitHomePage('asm=true'); cy.get('cx-asm-main-ui').should('exist'); @@ -198,9 +186,7 @@ context('Assisted Service Module', () => { }, }); - const customer = getSampleUser(); - checkout.visitHomePage(); - checkout.registerUser(false, customer); + const customer = asm.registerUser(); cy.visit('/', { qs: { asm: true } }); diff --git a/projects/storefrontapp-e2e-cypress/cypress/helpers/asm.ts b/projects/storefrontapp-e2e-cypress/cypress/helpers/asm.ts index 2af5a76a5c7..46d008ec8b1 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/helpers/asm.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/helpers/asm.ts @@ -23,6 +23,7 @@ import { } from '../support/utils/cart'; import { login as fetchingToken, visitLoginPage } from '../support/utils/login'; +import { clearAllStorage } from '../support/utils/clear-all-storage'; import { interceptGet, interceptPatch, @@ -693,13 +694,8 @@ export function startCustomerEmulation(customer, b2b = false): void { cy.get('cx-customer-emulation').should('be.visible'); } -export function startCustomerEmulationWithOrderID( - order, - customer, - b2b = false -): void { +export function startCustomerEmulationWithOrderID(order, customer): void { const customerSearchRequestAlias = listenForCustomerSearchRequest(); - const userDetailsRequestAlias = listenForUserDetailsRequest(b2b); cy.get('cx-csagent-login-form').should('not.exist'); cy.get('cx-customer-selection').should('exist'); @@ -717,7 +713,6 @@ export function startCustomerEmulationWithOrderID( cy.get('cx-customer-selection div.asm-results button').click(); cy.get('cx-customer-selection button[type="submit"]').click(); - cy.wait(userDetailsRequestAlias).its('response.statusCode').should('eq', 200); cy.get('cx-customer-emulation .cx-asm-customerInfo label.cx-asm-name').should( 'contain', customer.fullName @@ -735,6 +730,15 @@ export function loginCustomerInStorefront(customer) { cy.wait(authRequest).its('response.statusCode').should('eq', 200); } +export function loginCustomerWithNameAndPassword( + name: string, + password: string +) { + const authRequest = listenForAuthenticationRequest(); + login(name, password); + cy.wait(authRequest).its('response.statusCode').should('eq', 200); +} + // It is not recommended to use agentSignOut as it can cause failure in E2E tests related to ASM in the pipeline export function agentSignOut() { const tokenRevocationAlias = loginHelper.listenForTokenRevocationRequest(); @@ -1075,66 +1079,74 @@ export function emulateExistedCustomerPrepare(agentToken, agentPwd) { return customer; } -export function getCustomerId(agentUserName, agentPwd, customerUid) { - return new Promise((resolve, reject) => { +export function getCustomerId( + agentUserName, + agentPwd, + customerUid +): Promise { + return new Promise((resolve) => { fetchingToken(agentUserName, agentPwd, false).then((res) => { - // get customerId of it - cy.request({ - method: 'get', - url: - `${Cypress.env('API_URL')}${Cypress.env('OCC_PREFIX')}/${Cypress.env( - 'BASE_SITE' - )}/users/` + customerUid, - headers: { - Authorization: `bearer ${res.body.access_token}`, - }, - }).then((response) => { - if (response.status === 200) { - resolve(response.body.customerId); - } else { - reject(response.status); - } - }); + getCustomerIdWithAgentToken(res.body.access_token, customerUid).then( + resolve + ); }); }); } -export function getCustomerIdForJDK21(agentUserName, agentPwd, customerUid) { - return new Promise((resolve, reject) => { - let token; - cy.visit('/?asm=true'); - cy.get('.cx-asm-customer-list .cx-asm-customer-list-link').click(); - agentLoginForJDK21(agentUserName, agentPwd); - cy.get('button.logout') - .should('exist') - .and('be.visible') - .and('have.attr', 'title', 'Sign Out'); - cy.window().should('have.property', 'localStorage'); +export function getCustomerIdForJDK21( + agentUserName, + agentPwd, + customerUid +): Promise { + cy.visit('/?asm=true'); + cy.get('.cx-asm-customer-list .cx-asm-customer-list-link').click(); + agentLoginForJDK21(agentUserName, agentPwd); + cy.get('button.logout') + .should('exist') + .and('be.visible') + .and('have.attr', 'title', 'Sign Out'); + return getToken().then((token) => { + return getCustomerIdWithAgentToken(token, customerUid); + }); +} +export function getToken(): Promise { + return new Promise((resolve) => { + cy.wait(2000); + cy.wait(2000); + cy.window().should('have.property', 'localStorage'); cy.window().then((win) => { const spartacusAuth = win.localStorage.getItem('spartacus⚿⚿auth'); if (spartacusAuth) { const authObj = JSON.parse(spartacusAuth); + const token = authObj.token.access_token; + cy.log('--> get token: ' + token); + resolve(token); + } + }); + }); +} - token = authObj.token.access_token; +export function getCustomerIdWithAgentToken( + token, + customerUid +): Promise { + return new Promise((resolve, reject) => { + cy.request({ + method: 'get', + url: + `${Cypress.env('API_URL')}${Cypress.env('OCC_PREFIX')}/${Cypress.env( + 'BASE_SITE' + )}/users/` + customerUid, + headers: { + Authorization: `bearer ${token}`, + }, + }).then((response) => { + if (response.status === 200) { + resolve(response.body.customerId); + } else { + reject(response.status); } - // get customerId of it - cy.request({ - method: 'get', - url: - `${Cypress.env('API_URL')}${Cypress.env('OCC_PREFIX')}/${Cypress.env( - 'BASE_SITE' - )}/users/` + customerUid, - headers: { - Authorization: `bearer ${token}`, - }, - }).then((response) => { - if (response.status === 200) { - resolve(response.body.customerId); - } else { - reject(response.status); - } - }); }); }); } @@ -1179,29 +1191,11 @@ export function getInactiveCartIdAndAddProductsForJDK21( productCode?, quantity? ) { - let token = null; return new Promise((resolve, reject) => { - cy.get('button.logout').should('exist').and('be.visible').click(); - cy.get('button.close[title="Close ASM"]').should('be.visible').click(); - cy.visit('/'); - cy.log('Customer login in'); - cy.contains('a[role="link"]', 'Sign In / Register').click(); - - cy.get('input[name="username"]').clear().type(customerEmail); - cy.get('input[name="password"]').clear().type(customerPwd); - cy.contains('button.btn-primary', 'Sign In').should('be.visible').click(); - - cy.get('cx-login .cx-login-greet').should('be.visible'); - - cy.window().should('have.property', 'localStorage'); - - cy.window().then((win) => { - const spartacusAuth = win.localStorage.getItem('spartacus⚿⚿auth'); - if (spartacusAuth) { - const authObj = JSON.parse(spartacusAuth); - - token = authObj.token.access_token; - } + checkout.visitHomePage(); + cy.getLoginRegisterLink({ clickAndWait: true }); + loginCustomerWithNameAndPassword(customerEmail, customerPwd); + getToken().then((token) => { createInactiveCart(token) .then((inactiveCartId) => { if (!!productCode && quantity) { @@ -1261,3 +1255,49 @@ export function getCurrentCartIdAndAddProducts( }); }); } + +export function getCurrentCartIdAndAddProductsForJdk21( + customerName, + customerPwd, + productCode?, + quantity? +) { + return new Promise((resolve, reject) => { + checkout.visitHomePage(); + cy.getLoginRegisterLink({ clickAndWait: true }); + loginCustomerWithNameAndPassword(customerName, customerPwd); + getToken().then((token) => { + createCart(token).then((response) => { + if (response.status === 201) { + const activeCartId = response.body.code; + if (!!productCode && quantity) { + addToCartWithProducts( + activeCartId, + productCode, + quantity, + token + ).then((response) => { + if (response.status === 200) { + resolve(activeCartId); + } else { + reject(response.status); + } + }); + } else { + resolve(activeCartId); + } + } else { + reject(response.status); + } + }); + }); + }); +} + +export function registerUser() { + clearAllStorage(); + const customer = getSampleUser(); + checkout.visitHomePage(); + checkout.registerUser(false, customer); + return customer; +} diff --git a/projects/storefrontapp-e2e-cypress/cypress/helpers/auth-forms.ts b/projects/storefrontapp-e2e-cypress/cypress/helpers/auth-forms.ts index 9e43314cc30..fec1c62e913 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/helpers/auth-forms.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/helpers/auth-forms.ts @@ -141,6 +141,7 @@ export function agentLoginForJDK21(username: string, password: string) { `${Cypress.env('API_URL')}`, { args: { username, password } }, ({ username, password }) => { + cy.wait(2000); cy.get('form[id="loginForm"]').within(() => { cy.get('input[name=username]').clear().type(username); cy.get('input[name=password]').clear().type(password); diff --git a/projects/storefrontapp-e2e-cypress/cypress/support/utils/cart.ts b/projects/storefrontapp-e2e-cypress/cypress/support/utils/cart.ts index 70ff1327372..01cf27b01dd 100644 --- a/projects/storefrontapp-e2e-cypress/cypress/support/utils/cart.ts +++ b/projects/storefrontapp-e2e-cypress/cypress/support/utils/cart.ts @@ -64,7 +64,7 @@ export function addToCartWithProducts( quantity: string, accessToken: string ) { - const addToCartUrl = `${Cypress.env('API_URL')}/${Cypress.env( + const addToCartUrl = `${Cypress.env('API_URL')}${Cypress.env( 'OCC_PREFIX' )}/${Cypress.env('BASE_SITE')}/users/current/carts/${cartCode}/entries`;