Skip to content

Commit

Permalink
chore: Add e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: sawadashota <[email protected]>
  • Loading branch information
sawadashota committed Nov 29, 2021
1 parent 2ed20c8 commit 5da1d78
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ context('Account Recovery Success', () => {
recovery: react.recovery,
base: react.base,
app: 'react' as 'react',
profile: 'spa'
profile: 'spa',
},
{
recovery: express.recovery,
base: express.base,
app: 'express' as 'express',
profile: 'recovery'
profile: 'recovery',
}
].forEach(({ recovery, profile, base, app }) => {
describe(`for app ${app}`, () => {
Expand Down Expand Up @@ -68,4 +68,34 @@ context('Account Recovery Success', () => {
})
})
})

it('should recover, set password and be redirected', () => {
const app = 'express' as 'express'

cy.deleteMail()
cy.useConfigProfile('recovery')
cy.proxy(app)

cy.deleteMail()
cy.longRecoveryLifespan()
cy.longLinkLifespan()
cy.disableVerification()
cy.enableRecovery()

const identity = gen.identityWithWebsite()
cy.registerApi(identity)

cy.recoverApi({ email: identity.email, returnTo: 'https://www.ory.sh/' })

cy.recoverEmail({ expect: identity })

cy.getSession()
cy.location('pathname').should('eq', '/settings')

cy.get(appPrefix(app) + 'input[name="password"]')
.clear()
.type(gen.password())
cy.get('button[value="password"]').click()
cy.url().should('eq', 'https://www.ory.sh/')
})
})
12 changes: 7 additions & 5 deletions test/e2e/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,13 @@ Cypress.Commands.add('loginApiWithoutCookies', ({ email, password } = {}) => {
})
})

Cypress.Commands.add('recoverApi', ({ email }) =>
Cypress.Commands.add('recoverApi', ({ email, returnTo }) => {
let url = APP_URL + '/self-service/recovery/api'
if (returnTo) {
url += '?return_to=' + returnTo
}
cy
.request({
url: APP_URL + '/self-service/recovery/api'
})
.request({url})
.then(({ body }) => {
const form = body.ui
return cy.request({
Expand All @@ -354,7 +356,7 @@ Cypress.Commands.add('recoverApi', ({ email }) =>
.then(({ body }) => {
expect(body.state).to.contain('sent_email')
})
)
})

Cypress.Commands.add(
'registerOidc',
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ declare global {
*
* @param opts
*/
recoverApi(opts: { email: string }): Chainable<void>
recoverApi(opts: { email: string, returnTo?: string }): Chainable<void>

/**
* Changes the config so that the login flow lifespan is very short.
Expand Down

0 comments on commit 5da1d78

Please sign in to comment.