Skip to content

Commit

Permalink
test(e2e): prototype typescript implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 293d920 commit 2e869cf
Show file tree
Hide file tree
Showing 30 changed files with 301 additions and 250 deletions.
77 changes: 71 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
"text-run": "exit 0"
},
"devDependencies": {
"@ory/kratos-client": "^0.0.0-next.8d3b018594f7",
"@types/node": "^16.9.6",
"@types/yamljs": "^0.2.31",
"chrome-remote-interface": "^0.31.0",
"cypress": "^8.3.0",
"dayjs": "^1.10.4",
"ory-prettier-styles": "1.1.1",
"otplib": "^12.0.1",
"prettier": "2.2.1",
"typescript": "^4.4.3",
"wait-on": "5.3.0"
},
"dependencies": {
Expand Down
5 changes: 0 additions & 5 deletions test/e2e/cypress/fixtures/example.json

This file was deleted.

73 changes: 0 additions & 73 deletions test/e2e/cypress/helpers/index.js

This file was deleted.

75 changes: 75 additions & 0 deletions test/e2e/cypress/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
export const email = () => Math.random().toString(36) + '@ory.sh'

export const password = () => Math.random().toString(36)

export const assertVerifiableAddress = ({isVerified, email}) => ({identity}) => {
expect(identity).to.have.property('verifiable_addresses')
expect(identity.verifiable_addresses).to.have.length(1)

const address = identity.verifiable_addresses[0]
expect(address.id).to.not.be.empty
expect(address.verified).to.equal(isVerified)
expect(address.value).to.equal(email)

if (isVerified) {
expect(address.verified_at).to.not.be.null
} else {
expect(address).to.not.have.property('verified_at')
}
}

export const assertRecoveryAddress = ({email}) => ({identity}) => {
expect(identity).to.have.property('recovery_addresses')
expect(identity.recovery_addresses).to.have.length(1)

const address = identity.recovery_addresses[0]
expect(address.id).to.not.be.empty
expect(address.value).to.equal(email)
}

export const parseHtml = (html) => new DOMParser().parseFromString(html, 'text/html')

export const APP_URL = (Cypress.env('app_url') || 'http://localhost:4455').replace(
/\/$/,
''
)

export const MOBILE_URL = (Cypress.env('mobile_url') || 'http://localhost:4457').replace(
/\/$/,
''
)
export const SPA_URL = (Cypress.env('react_url') || 'http://localhost:4458').replace(
/\/$/,
''
)
export const KRATOS_ADMIN = (Cypress.env('kratos_admin') || 'http://localhost:4434')
.replace()
.replace(/\/$/, '')

export const KRATOS_PUBLIC = (Cypress.env('kratos_public') || 'http://localhost:4433')
.replace()
.replace(/\/$/, '')

export const MAIL_API = (Cypress.env('mail_url') || 'http://localhost:4437').replace(
/\/$/,
''
)

export const website = 'https://www.ory.sh/'

export const gen = {
email,
password,
identity: () => ({email: email(), password: password()})
}

// Format is
export const verifyHrefPattern = /^http:.*\/self-service\/verification\?(((&|)token|(&|)flow)=([\-a-zA-Z0-9]+)){2}$/

// intervals define how long to wait for something,
export const pollInterval = 250 // how long to wait before retry

// Adding 1+ second on top because MySQL doesn't do millisecs.
export const verifyLifespan = 5000 + 1000
export const privilegedLifespan = 5000 + 1000

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { APP_URL } = require('../../../../helpers')
import { APP_URL } from '../../../../helpers'

context('Email Profile', () => {
describe('Self-Service Error UI', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ context('Email Profile', () => {
cy.get('input[name="password"]').type(password)
cy.get('button[type="submit"]').click()

cy.session().should((session) => {
cy.getSession().should((session) => {
const { identity } = session
expect(identity.id).to.not.be.empty
expect(identity.schema_id).to.equal('default')
Expand All @@ -38,7 +38,7 @@ context('Email Profile', () => {
cy.get('input[name="password"]').type(password)
cy.get('button[type="submit"]').click()

cy.session().should((session) => {
cy.getSession().should((session) => {
const { identity } = session
expect(identity.id).to.not.be.empty
expect(identity.schema_id).to.equal('default')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ context('Email Profile', () => {

it('should sign out and be able to sign in again', () => {
cy.visit(APP_URL + '/')
cy.session()
cy.getSession()
cy.get('a[href*="logout"]').click()
cy.noSession()
cy.url().should('include', '/auth/login')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ context('Email Profile', () => {
cy.get('pre').should('contain.text', email)
cy.get('.greeting').should('contain.text', 'Welcome back')

cy.session().should((session) => {
cy.getSession().should((session) => {
const { identity } = session
expect(identity.id).to.not.be.empty
expect(identity.verifiable_addresses).to.be.undefined
Expand Down

0 comments on commit 2e869cf

Please sign in to comment.