diff --git a/test/e2e/cypress/support/commands.ts b/test/e2e/cypress/support/commands.ts index 68802d992627..e8a9b54cf5a2 100644 --- a/test/e2e/cypress/support/commands.ts +++ b/test/e2e/cypress/support/commands.ts @@ -13,24 +13,24 @@ import { import dayjs from 'dayjs' import YAML from 'yamljs' -import {Session} from '@ory/kratos-client' +import { Session } from '@ory/kratos-client' const configFile = 'kratos.generated.yml' const mergeFields = (form, fields) => { const result = {} - form.nodes.forEach(({attributes, type}) => { + form.nodes.forEach(({ attributes, type }) => { if (type === 'input') { result[attributes.name] = attributes.value } }) - return {...result, ...fields} + return { ...result, ...fields } } function checkConfigVersion(previous, tries = 0) { cy.wait(50) - cy.request('GET', KRATOS_ADMIN + '/health/config').then(({body}) => { + cy.request('GET', KRATOS_ADMIN + '/health/config').then(({ body }) => { if (previous !== body) { return } else if (tries > 8) { @@ -45,7 +45,7 @@ function checkConfigVersion(previous, tries = 0) { } const updateConfigFile = (cb: (arg: any) => any) => { - cy.request('GET', KRATOS_ADMIN + '/health/config').then(({body}) => { + cy.request('GET', KRATOS_ADMIN + '/health/config').then(({ body }) => { cy.readFile(configFile).then((contents) => { cy.writeFile(configFile, YAML.stringify(cb(YAML.parse(contents)))) cy.wait(500) @@ -55,7 +55,7 @@ const updateConfigFile = (cb: (arg: any) => any) => { } Cypress.Commands.add('useConfigProfile', (profile: string) => { - cy.request('GET', KRATOS_ADMIN + '/health/config').then(({body}) => { + cy.request('GET', KRATOS_ADMIN + '/health/config').then(({ body }) => { console.log('Switching config profile to:', profile) cy.readFile(`kratos.${profile}.yml`).then((contents) => cy.writeFile(configFile, contents) @@ -68,7 +68,7 @@ Cypress.Commands.add('proxy', (app: string) => { console.log('Switching proxy profile to:', app) cy.writeFile(`proxy.json`, `"${app}"`) cy.request(APP_URL + '/') - .its('body', {log: false}) + .its('body', { log: false }) .then((body) => { expect(body.indexOf(`data-testid="app-${app}"`) > -1).to.be.true }) @@ -156,7 +156,7 @@ Cypress.Commands.add('longRecoveryLifespan', ({} = {}) => { Cypress.Commands.add('enableLoginForVerifiedAddressOnly', () => { updateConfigFile((config) => { config.selfservice.flows.login['after'] = { - password: {hooks: [{hook: 'require_verified_address'}]} + password: { hooks: [{ hook: 'require_verified_address' }] } } return config }) @@ -255,12 +255,12 @@ Cypress.Commands.add('updateConfigFile', (cb: (arg: any) => any) => { Cypress.Commands.add( 'register', ({ - email = gen.email(), - password = gen.password(), - query = {}, - fields = {} - } = {}) => { - console.log('Creating user account: ', {email, password}) + email = gen.email(), + password = gen.password(), + query = {}, + fields = {} + } = {}) => { + console.log('Creating user account: ', { email, password }) // see https://github.com/cypress-io/cypress/issues/408 cy.visit(APP_URL) @@ -274,7 +274,7 @@ Cypress.Commands.add( }, qs: query }) - .then(({body, status}) => { + .then(({ body, status }) => { expect(status).to.eq(200) const form = body.ui return cy.request({ @@ -289,7 +289,7 @@ Cypress.Commands.add( followRedirect: false }) }) - .then(({body}) => { + .then(({ body }) => { expect(body.identity.traits.email).to.contain(email) }) } @@ -297,12 +297,12 @@ Cypress.Commands.add( Cypress.Commands.add( 'registerApi', - ({email = gen.email(), password = gen.password(), fields = {}} = {}) => + ({ email = gen.email(), password = gen.password(), fields = {} } = {}) => cy .request({ url: APP_URL + '/self-service/registration/api' }) - .then(({body}) => { + .then(({ body }) => { const form = body.ui return cy.request({ method: form.method, @@ -315,17 +315,17 @@ Cypress.Commands.add( url: form.action }) }) - .then(({body}) => { + .then(({ body }) => { expect(body.identity.traits.email).to.contain(email) }) ) -Cypress.Commands.add('settingsApi', ({fields = {}} = {}) => +Cypress.Commands.add('settingsApi', ({ fields = {} } = {}) => cy .request({ url: APP_URL + '/self-service/settings/api' }) - .then(({body}) => { + .then(({ body }) => { const form = body.ui return cy.request({ method: form.method, @@ -335,17 +335,17 @@ Cypress.Commands.add('settingsApi', ({fields = {}} = {}) => url: form.action }) }) - .then(({body}) => { + .then(({ body }) => { expect(body.statusCode).to.eq(200) }) ) -Cypress.Commands.add('loginApi', ({email, password} = {}) => +Cypress.Commands.add('loginApi', ({ email, password } = {}) => cy .request({ url: APP_URL + '/self-service/login/api' }) - .then(({body}) => { + .then(({ body }) => { const form = body.ui return cy.request({ method: form.method, @@ -357,12 +357,12 @@ Cypress.Commands.add('loginApi', ({email, password} = {}) => url: form.action }) }) - .then(({body}) => { + .then(({ body }) => { expect(body.session.identity.traits.email).to.contain(email) }) ) -Cypress.Commands.add('loginApiWithoutCookies', ({email, password} = {}) => { +Cypress.Commands.add('loginApiWithoutCookies', ({ email, password } = {}) => { cy.task('httpRequest', { url: APP_URL + '/self-service/login/api', headers: { @@ -389,56 +389,56 @@ Cypress.Commands.add('loginApiWithoutCookies', ({email, password} = {}) => { }) }) -Cypress.Commands.add('recoverApi', ({email, returnTo}) => { +Cypress.Commands.add('recoverApi', ({ email, returnTo }) => { let url = APP_URL + '/self-service/recovery/api' if (returnTo) { url += '?return_to=' + returnTo } - cy.request({url}) - .then(({body}) => { + cy.request({ url }) + .then(({ body }) => { const form = body.ui return cy.request({ method: form.method, - body: mergeFields(form, {email, method: 'link'}), + body: mergeFields(form, { email, method: 'link' }), url: form.action }) }) - .then(({body}) => { + .then(({ body }) => { expect(body.state).to.contain('sent_email') }) }) -Cypress.Commands.add('verificationApi', ({email, returnTo}) => { +Cypress.Commands.add('verificationApi', ({ email, returnTo }) => { let url = APP_URL + '/self-service/verification/api' if (returnTo) { url += '?return_to=' + returnTo } - cy.request({url}) - .then(({body}) => { + cy.request({ url }) + .then(({ body }) => { const form = body.ui return cy.request({ method: form.method, - body: mergeFields(form, {email, method: 'link'}), + body: mergeFields(form, { email, method: 'link' }), url: form.action }) }) - .then(({body}) => { + .then(({ body }) => { expect(body.state).to.contain('sent_email') }) }) -Cypress.Commands.add('verificationApiExpired', ({email, returnTo}) => { +Cypress.Commands.add('verificationApiExpired', ({ email, returnTo }) => { cy.shortVerificationLifespan() let url = APP_URL + '/self-service/verification/api' if (returnTo) { url += '?return_to=' + returnTo } - cy.request({url}) - .then(({body}) => { + cy.request({ url }) + .then(({ body }) => { const form = body.ui return cy.request({ method: form.method, - body: mergeFields(form, {email, method: 'link'}), + body: mergeFields(form, { email, method: 'link' }), url: form.action, failOnStatusCode: false }) @@ -454,21 +454,21 @@ Cypress.Commands.add('verificationApiExpired', ({email, returnTo}) => { }) }) -Cypress.Commands.add('verificationBrowser', ({email, returnTo}) => { +Cypress.Commands.add('verificationBrowser', ({ email, returnTo }) => { let url = APP_URL + '/self-service/verification/browser' if (returnTo) { url += '?return_to=' + returnTo } - cy.request({url}) - .then(({body}) => { + cy.request({ url }) + .then(({ body }) => { const form = body.ui return cy.request({ method: form.method, - body: mergeFields(form, {email, method: 'link'}), + body: mergeFields(form, { email, method: 'link' }), url: form.action }) }) - .then(({body}) => { + .then(({ body }) => { expect(body.state).to.contain('sent_email') }) }) @@ -497,16 +497,16 @@ Cypress.Commands.add('addVirtualAuthenticator', () => Cypress.Commands.add( 'registerOidc', ({ - email, - website, - scopes, - rememberLogin = true, - rememberConsent = true, - acceptLogin = true, - acceptConsent = true, - expectSession = true, - route = APP_URL + '/registration' - }) => { + email, + website, + scopes, + rememberLogin = true, + rememberConsent = true, + acceptLogin = true, + acceptConsent = true, + expectSession = true, + route = APP_URL + '/registration' + }) => { cy.visit(route) cy.triggerOidc() @@ -605,7 +605,7 @@ Cypress.Commands.add('remoteCourierRecoveryTemplates', ({} = {}) => { Cypress.Commands.add( 'loginOidc', - ({expectSession = true, url = APP_URL + '/login'}) => { + ({ expectSession = true, url = APP_URL + '/login' }) => { cy.visit(url) cy.triggerOidc('hydra') cy.location('href').should('not.eq', '/consent') @@ -619,11 +619,11 @@ Cypress.Commands.add( Cypress.Commands.add( 'login', - ({email, password, expectSession = true, cookieUrl = APP_URL}) => { + ({ email, password, expectSession = true, cookieUrl = APP_URL }) => { if (expectSession) { - console.log('Singing in user: ', {email, password}) + console.log('Singing in user: ', { email, password }) } else { - console.log('Attempting user sign in: ', {email, password}) + console.log('Attempting user sign in: ', { email, password }) } // see https://github.com/cypress-io/cypress/issues/408 @@ -639,7 +639,7 @@ Cypress.Commands.add( Accept: 'application/json' } }) - .then(({body, status}) => { + .then(({ body, status }) => { expect(status).to.eq(200) const form = body.ui return cy.request({ @@ -657,7 +657,7 @@ Cypress.Commands.add( failOnStatusCode: false }) }) - .then(({status}) => { + .then(({ status }) => { console.log('Login sequence completed: ', { email, password, @@ -674,7 +674,7 @@ Cypress.Commands.add( } ) -Cypress.Commands.add('loginMobile', ({email, password}) => { +Cypress.Commands.add('loginMobile', ({ email, password }) => { cy.visit(MOBILE_URL + '/Login') cy.get('input[data-testid="identifier"]').type(email) cy.get('input[data-testid="password"]').type(password) @@ -684,7 +684,7 @@ Cypress.Commands.add('loginMobile', ({email, password}) => { Cypress.Commands.add('logout', () => { cy.getCookies().should((cookies) => { const c = cookies.find( - ({name}) => name.indexOf('ory_kratos_session') > -1 + ({ name }) => name.indexOf('ory_kratos_session') > -1 ) expect(c).to.not.be.undefined cy.clearCookie(c.name) @@ -695,13 +695,13 @@ Cypress.Commands.add('logout', () => { Cypress.Commands.add( 'reauthWithOtherAccount', ({ - previousUrl, - expect: {email, success = true}, - type: {email: temail, password: tpassword} = { - email: undefined, - password: undefined - } - }) => { + previousUrl, + expect: { email, success = true }, + type: { email: temail, password: tpassword } = { + email: undefined, + password: undefined + } + }) => { cy.location('pathname').should('contain', '/login') cy.location().then((loc) => { const uri = new URLSearchParams(loc.search) @@ -714,7 +714,7 @@ Cypress.Commands.add( headers: { Accept: 'application/json' } - }).then(({body, status}) => { + }).then(({ body, status }) => { expect(status).to.eq(200) const form = body.ui console.log(form.action) @@ -745,12 +745,12 @@ Cypress.Commands.add( Cypress.Commands.add( 'reauth', ({ - expect: {email, success = true}, - type: {email: temail, password: tpassword} = { - email: undefined, - password: undefined - } - }) => { + expect: { email, success = true }, + type: { email: temail, password: tpassword } = { + email: undefined, + password: undefined + } + }) => { cy.location('pathname').should('contain', '/login') cy.get('input[name="identifier"]').should('have.value', email) if (temail) { @@ -767,13 +767,13 @@ Cypress.Commands.add( } ) -Cypress.Commands.add('deleteMail', ({atLeast = 0} = {}) => { +Cypress.Commands.add('deleteMail', ({ atLeast = 0 } = {}) => { let tries = 0 let count = 0 const req = () => cy - .request('DELETE', `${MAIL_API}/mail`, {pruneCode: 'all'}) - .then(({body}) => { + .request('DELETE', `${MAIL_API}/mail`, { pruneCode: 'all' }) + .then(({ body }) => { count += parseInt(body) if (count < atLeast && tries < 100) { cy.log( @@ -792,9 +792,11 @@ Cypress.Commands.add('deleteMail', ({atLeast = 0} = {}) => { Cypress.Commands.add( 'getSession', - ({expectAal = 'aal1', expectMethods = []} = {}) => { + ({ expectAal = 'aal1', expectMethods = [] } = {}) => { // Do the request once to ensure we have a session (with retry) - cy.request('GET', `${KRATOS_PUBLIC}/sessions/whoami`).its('status').should('eq', 200) + cy.request('GET', `${KRATOS_PUBLIC}/sessions/whoami`) + .its('status') + .should('eq', 200) // Return the session for further propagation return cy @@ -822,7 +824,7 @@ Cypress.Commands.add( expectMethods.forEach((value) => { expect( response.body.authentication_methods.find( - ({method}) => method === value + ({ method }) => method === value ) ).to.exist }) @@ -845,7 +847,7 @@ Cypress.Commands.add('noSession', () => return request }) ) -Cypress.Commands.add('getIdentityByEmail', ({email}) => +Cypress.Commands.add('getIdentityByEmail', ({ email }) => cy .request({ method: 'GET', @@ -861,8 +863,8 @@ Cypress.Commands.add('getIdentityByEmail', ({email}) => Cypress.Commands.add( 'performEmailVerification', ({ - expect: {email, redirectTo} = {email: undefined, redirectTo: undefined} - } = {}) => + expect: { email, redirectTo } = { email: undefined, redirectTo: undefined } + } = {}) => cy.getMail().then((message) => { expect(message.subject.trim()).to.equal( 'Please verify your email address' @@ -875,7 +877,7 @@ Cypress.Commands.add( expect(link).to.not.be.null expect(link.href).to.contain(APP_URL) - cy.request({url: link.href, followRedirect: false}).should( + cy.request({ url: link.href, followRedirect: false }).should( (response) => { expect(response.status).to.eq(303) if (redirectTo) { @@ -890,16 +892,16 @@ Cypress.Commands.add( Cypress.Commands.add( 'verifyEmail', - ({expect: {email, password, redirectTo}}) => - cy.performEmailVerification({expect: {email, redirectTo}}).then(() => { + ({ expect: { email, password, redirectTo } }) => + cy.performEmailVerification({ expect: { email, redirectTo } }).then(() => { cy.getSession().should((session) => - assertVerifiableAddress({email, isVerified: true})(session) + assertVerifiableAddress({ email, isVerified: true })(session) ) }) ) // Uses the verification email but waits so that it expires -Cypress.Commands.add('recoverEmailButExpired', ({expect: {email}}) => { +Cypress.Commands.add('recoverEmailButExpired', ({ expect: { email } }) => { cy.getMail().should((message) => { expect(message.subject.trim()).to.equal('Recover access to your account') expect(message.toAddresses[0].trim()).to.equal(email) @@ -914,7 +916,7 @@ Cypress.Commands.add('recoverEmailButExpired', ({expect: {email}}) => { Cypress.Commands.add( 'recoverEmail', - ({expect: {email}, shouldVisit = true}) => + ({ expect: { email }, shouldVisit = true }) => cy.getMail().should((message) => { expect(message.subject.trim()).to.equal('Recover access to your account') expect(message.fromAddress.trim()).to.equal('no-reply@ory.kratos.sh') @@ -935,7 +937,7 @@ Cypress.Commands.add( // Uses the verification email but waits so that it expires Cypress.Commands.add( 'verifyEmailButExpired', - ({expect: {email, password}}) => + ({ expect: { email, password } }) => cy.getMail().then((message) => { expect(message.subject.trim()).to.equal( 'Please verify your email address' @@ -975,7 +977,7 @@ Cypress.Commands.add('waitForPrivilegedSessionToExpire', () => { expect(session.authenticated_at).to.not.be.empty cy.wait( dayjs(session.authenticated_at).add(privilegedLifespan).diff(dayjs()) + - 100 + 100 ) }) }) @@ -991,7 +993,7 @@ Cypress.Commands.add('expectSettingsSaved', () => .should('contain.text', 'Your changes have been saved') ) -Cypress.Commands.add('getMail', ({removeMail = true} = {}) => { +Cypress.Commands.add('getMail', ({ removeMail = true } = {}) => { let tries = 0 const req = () => cy.request(`${MAIL_API}/mail`).then((response) => { @@ -1006,7 +1008,7 @@ Cypress.Commands.add('getMail', ({removeMail = true} = {}) => { expect(count).to.equal(1) if (removeMail) { return cy - .deleteMail({atLeast: count}) + .deleteMail({ atLeast: count }) .then(() => Promise.resolve(response.body.mailItems[0])) } @@ -1017,7 +1019,7 @@ Cypress.Commands.add('getMail', ({removeMail = true} = {}) => { }) Cypress.Commands.add('clearAllCookies', () => { - cy.clearCookies({domain: null}) + cy.clearCookies({ domain: null }) }) Cypress.Commands.add('submitPasswordForm', () => { @@ -1047,8 +1049,8 @@ Cypress.Commands.add('shouldShow2FAScreen', () => { Cypress.Commands.add( 'shouldErrorOnDisallowedReturnTo', - (init: string, {app}: { app: 'express' | 'react' }) => { - cy.visit(init, {failOnStatusCode: false}) + (init: string, { app }: { app: 'express' | 'react' }) => { + cy.visit(init, { failOnStatusCode: false }) if (app === 'react') { cy.location('href').should('include', init.split('?')[0]) cy.get('.Toastify').should( @@ -1067,7 +1069,7 @@ Cypress.Commands.add( Cypress.Commands.add( 'shouldHaveCsrfError', - ({app}: { app: 'express' | 'react' }) => { + ({ app }: { app: 'express' | 'react' }) => { let initial let pathname cy.location().should((location) => { @@ -1076,7 +1078,7 @@ Cypress.Commands.add( }) cy.getCookies().should((cookies) => { - const csrf = cookies.find(({name}) => name.indexOf('csrf') > -1) + const csrf = cookies.find(({ name }) => name.indexOf('csrf') > -1) expect(csrf).to.not.be.undefined cy.clearCookie(csrf.name) })