Skip to content

Commit

Permalink
test(e2e): add recovery tests for SPA
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 21b35b0 commit b6014ee
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
4 changes: 3 additions & 1 deletion test/e2e/cypress/helpers/express.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {APP_URL} from "./index";
import {APP_URL, SPA_URL} from "./index";

export const routes = {
base: APP_URL,
login: APP_URL + '/login',
registration: APP_URL + '/registration',
settings: APP_URL + '/settings',
recovery: APP_URL + '/recovery',
verification: APP_URL + '/verification',
}
4 changes: 3 additions & 1 deletion test/e2e/cypress/helpers/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export const routes = {
base: SPA_URL,
login: SPA_URL + '/login',
registration: SPA_URL + '/registration',
settings: SPA_URL + '/settings'
settings: SPA_URL + '/settings',
recovery: SPA_URL + '/recovery',
verification: SPA_URL + '/verification',
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import { APP_URL, gen, parseHtml } from '../../../../helpers'

context('Recovery Profile', () => {
describe('Recovery', () => {
before(() => {
cy.useConfigProfile('recovery')
})

describe('error flow', () => {
let identity

import {gen, parseHtml} from '../../../../helpers'
import {routes as react} from "../../../../helpers/react";
import {routes as express} from "../../../../helpers/express";

const fields = {'traits.website': 'https://www.ory.sh'}

context('Account Recovery Errors', () => {
[
{
recovery: react.recovery,
app: 'react', profile: 'spa'
},
{
recovery: express.recovery,
app: 'express', profile: 'recovery'
}
].forEach(({recovery, profile, app,}) => {
describe(`for app ${app}`, () => {
before(() => {
cy.deleteMail()
cy.useConfigProfile(profile)
})

beforeEach(() => {
cy.deleteMail()
cy.longRecoveryLifespan()
cy.longLinkLifespan()
cy.visit(APP_URL + '/recovery')
cy.disableVerification()
cy.enableRecovery()
})

it('should receive a stub email when recovering a non-existent account', () => {
cy.visit(recovery)

const email = gen.email()
cy.get('input[name="email"]').type(email)
cy.get('button[value="link"]').click()

cy.location('pathname').should('eq', '/recovery')
cy.get('.messages .message.info').should(
cy.get('[data-testid="ui/message/1060002"]').should(
'have.text',
'An email containing a recovery link has been sent to the email address you provided.'
)
Expand All @@ -43,28 +55,26 @@ context('Recovery Profile', () => {
})

it('should cause form errors', () => {
cy.visit(recovery)

cy.get('button[value="link"]').click()
cy.get('.messages .message').should(
cy.get('[data-testid="ui/message/4000002"]').should(
'contain.text',
'"" is not valid "email"'
'Property email is missing.'
)
cy.get('button[type="submit"][name="method"][value="link"]').should(
cy.get('[name="method"][value="link"]').should(
'exist'
)
})

it('is unable to recover the email address if the code is expired', () => {
cy.shortLinkLifespan()
identity = gen.identity()
cy.register(identity)
cy.visit(APP_URL + '/recovery')
const identity = gen.identity()
cy.registerApi({...identity, fields})
cy.recoverApi({email: identity.email})
cy.recoverEmailButExpired({expect: {email: identity.email}})

cy.get('input[name="email"]').type(identity.email)
cy.get('button[value="link"]').click()

cy.recoverEmailButExpired({ expect: { email: identity.email } })

cy.get('.messages .message.error').should(
cy.get('[data-testid="ui/message/4060005"]').should(
'contain.text',
'The recovery flow expired'
)
Expand All @@ -73,17 +83,15 @@ context('Recovery Profile', () => {
})

it('is unable to recover the account if the code is incorrect', () => {
identity = gen.identity()
cy.register(identity)
cy.visit(APP_URL + '/recovery')

cy.get('input[name="email"]').type(identity.email)
cy.get('button[value="link"]').click()
const identity = gen.identity()
cy.registerApi({...identity, fields})
cy.recoverApi({email: identity.email})

cy.getMail().then((mail) => {
console.log(mail)
const link = parseHtml(mail.body).querySelector('a')
cy.visit(link.href + '-not') // add random stuff to the confirm challenge
cy.get('.messages .message.error').should(
cy.get('[data-testid="ui/message/4060004"]').should(
'have.text',
'The recovery token is invalid or has already been used. Please retry the flow.'
)
Expand All @@ -92,12 +100,9 @@ context('Recovery Profile', () => {
})

it('is unable to recover the account using the token twice', () => {
identity = gen.identity()
cy.register(identity)
cy.visit(APP_URL + '/recovery')

cy.get('input[name="email"]').type(identity.email)
cy.get('button[value="link"]').click()
const identity = gen.identity()
cy.registerApi({...identity, fields})
cy.recoverApi({email: identity.email})

cy.getMail().then((mail) => {
const link = parseHtml(mail.body).querySelector('a')
Expand All @@ -107,7 +112,7 @@ context('Recovery Profile', () => {
cy.logout()

cy.visit(link.href)
cy.get('.messages .message.error').should(
cy.get('[data-testid="ui/message/4060004"]').should(
'have.text',
'The recovery token is invalid or has already been used. Please retry the flow.'
)
Expand Down

0 comments on commit b6014ee

Please sign in to comment.