-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): refactor and add support for SPA app
- Loading branch information
Showing
21 changed files
with
227 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {APP_URL} from "./index"; | ||
|
||
export const routes = { | ||
base: APP_URL, | ||
login: APP_URL + '/login' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {SPA_URL} from "./index"; | ||
|
||
export const routes = { | ||
base: SPA_URL, | ||
login: SPA_URL + '/login' | ||
} |
33 changes: 22 additions & 11 deletions
33
test/e2e/cypress/integration/profiles/email/error/ui.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
import { APP_URL } from '../../../../helpers' | ||
import {routes as express} from "../../../../helpers/express"; | ||
import {routes as react} from "../../../../helpers/react"; | ||
|
||
context('Email Profile', () => { | ||
describe('Self-Service Error UI', () => { | ||
before(() => { | ||
cy.useConfigProfile('email') | ||
}) | ||
describe('Handling self-service error flows', () => { | ||
[{ | ||
route: express.base, | ||
app: 'express', | ||
profile: 'email' | ||
}, { | ||
route: react.base, | ||
app: 'react', | ||
profile: 'spa' | ||
}].forEach(({route, app,profile}) => { | ||
describe(`for app ${app}`, () => { | ||
before(() => { | ||
cy.useConfigProfile(profile) | ||
}); | ||
|
||
it('should show the error', () => { | ||
cy.visit(`${APP_URL}/error?id=stub:500`, { | ||
failOnStatusCode: false | ||
}) | ||
it('should show the error', () => { | ||
cy.visit(`${route}/error?id=stub:500`, { | ||
failOnStatusCode: false | ||
}) | ||
|
||
cy.get('code').should('contain.text', 'This is a stub error.') | ||
cy.get('code').should('contain.text', 'This is a stub error.') | ||
}) | ||
}) | ||
}) | ||
}) |
63 changes: 0 additions & 63 deletions
63
test/e2e/cypress/integration/profiles/email/login/error.spec.js
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
test/e2e/cypress/integration/profiles/email/login/error.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import {gen} from '../../../../helpers' | ||
import {routes as express} from "../../../../helpers/express"; | ||
import {routes as react} from "../../../../helpers/react"; | ||
|
||
describe('Basic email profile with failing login flows', () => { | ||
[{ | ||
route: express.login, | ||
app: 'express', profile: 'email' | ||
}, { | ||
route: react.login, | ||
app: 'react', profile: 'spa' | ||
}].forEach(({route, profile, app}) => { | ||
describe(`for app ${app}`, () => { | ||
before(() => { | ||
cy.useConfigProfile(profile) | ||
}); | ||
|
||
beforeEach(() => { | ||
cy.visit(route) | ||
}) | ||
|
||
it('fails when CSRF cookies are missing', () => { | ||
cy.clearCookies() | ||
|
||
cy.get('input[name="password_identifier"]').type('i-do-not-exist') | ||
cy.get('input[name="password"]').type('invalid-password') | ||
|
||
let initial | ||
cy.location().should((location) => { | ||
initial = location.search | ||
}) | ||
cy.get('button[type="submit"]').click() | ||
|
||
// We end up at a new flow | ||
cy.location('search').should('not.eq', initial) | ||
}) | ||
|
||
describe('shows validation errors when invalid signup data is used', () => { | ||
it('should show an error when the identifier is missing', () => { | ||
cy.get('button[type="submit"]').click() | ||
cy.get('*[data-testid="ui.node.message.4000001"]').should( | ||
'contain.text', | ||
'length must be >= 1, but got 0' | ||
) | ||
}) | ||
|
||
it('should show an error when the password is missing', () => { | ||
const identity = gen.email() | ||
cy.get('input[name="password_identifier"]') | ||
.type(identity) | ||
.should('have.value', identity) | ||
|
||
cy.get('button[type="submit"]').click() | ||
|
||
cy.get('*[data-testid^="ui.node.message."]').invoke('text').then((text)=> { | ||
expect(text).to.be.oneOf(['length must be >= 1, but got 0', 'Property password is missing.']) | ||
}) | ||
}) | ||
|
||
it('should show fail to sign in', () => { | ||
cy.get('input[name="password_identifier"]').type('i-do-not-exist') | ||
cy.get('input[name="password"]').type('invalid-password') | ||
|
||
cy.get('button[type="submit"]').click() | ||
cy.get('*[data-testid="ui.node.message.4000006"]').should( | ||
'contain.text', | ||
'credentials are invalid' | ||
) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import {Session} from "@ory/kratos-client"; | ||
import {gen} from "../helpers"; | ||
|
||
export interface MailMessage { | ||
fromAddress: string | ||
toAddresses: Array<string> | ||
body:string | ||
subject:string | ||
} | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
/** | ||
* Delete mails from the email server. | ||
* | ||
* @param options | ||
*/ | ||
deleteMail(options: { | ||
atLeast?: boolean, | ||
}): Chainable<void> | ||
|
||
/** | ||
* Fetch the browser's Ory Session. | ||
* | ||
* @param opts | ||
*/ | ||
getSession(opts?: | ||
{ | ||
expectAal: 'aal2' |'aal1', | ||
expectMethods: Array<'password' | 'webauthn'>, | ||
} | ||
): Chainable<Session> | ||
|
||
/** | ||
* Expect that the browser has no valid Ory Kratos Cookie Session. | ||
*/ | ||
noSession(): Chainable<Response<any>> | ||
|
||
/** | ||
* Set the "privileged session lifespan" to a large value. | ||
*/ | ||
longPrivilegedSessionTime(): Chainable<void> | ||
|
||
/** | ||
* Return and optionally delete an email from the fake email server. | ||
* | ||
* @param opts | ||
*/ | ||
getMail(opts?: { removeMail: boolean }): Chainable<MailMessage> | ||
|
||
performEmailVerification(opts?: {expect?: {email?: string, redirectTo?: string}}): Chainable<void> | ||
|
||
/** | ||
* Sets the Ory Kratos configuration profile. | ||
* | ||
* @param profile | ||
*/ | ||
useConfigProfile(profile: string): Chainable<void> | ||
|
||
/** | ||
* Register a new user with email + password via the API. | ||
* | ||
* Recommended to use if you need an Ory Session Token or alternatively the user created. | ||
* | ||
* @param opts | ||
*/ | ||
registerApi(opts?: {email:string, password:string, fields: { [key: string]: string }}): Chainable<Session> | ||
|
||
/** | ||
* Changes the config so that the login flow lifespan is very short. | ||
* | ||
* | ||
* Useful when testing expiry of login flows. | ||
* @see longLoginLifespan() | ||
*/ | ||
shortLoginLifespan(): Chainable<void> | ||
|
||
/** | ||
* Changes the config so that the login flow lifespan is very long. | ||
* | ||
* Useful when testing expiry of login flows. | ||
* @see shortLoginLifespan() | ||
*/ | ||
longLoginLifespan(): Chainable<void> | ||
|
||
/** | ||
* Change the config so that `https://www.ory.sh/` is a allowed return to URL. | ||
*/ | ||
browserReturnUrlOry(): Chainable<void> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './commands' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.