Skip to content

Commit

Permalink
test(e2e): spa flows on login and registration code
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko committed Aug 22, 2023
1 parent f2db1d4 commit f13a51f
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 250 deletions.
83 changes: 32 additions & 51 deletions test/e2e/cypress/integration/profiles/code/login/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ context("Login error messages with code method", () => {
app: "express" as "express",
profile: "code",
},
// {
// route: react.login,
// app: "react" as "react",
// profile: "code",
// },
{
route: react.login,
app: "react" as "react",
profile: "code",
},
].forEach(({ route, profile, app }) => {
describe(`for app ${app}`, () => {
before(() => {
cy.proxy(app)
cy.useConfigProfile(profile)
cy.deleteMail()
})

beforeEach(() => {
cy.useConfigProfile(profile)
cy.deleteMail()
cy.clearAllCookies()

Expand All @@ -40,9 +41,7 @@ context("Login error messages with code method", () => {
it("should show error message when account identifier does not exist", () => {
const email = gen.email()

cy.get(
'form[data-testid="login-flow-code"] input[name="identifier"]',
).type(email)
cy.get('input[name="identifier"]').type(email)
cy.submitCodeForm()

cy.url().should("contain", "login")
Expand All @@ -55,9 +54,7 @@ context("Login error messages with code method", () => {

it("should show error message when code is invalid", () => {
cy.get("@email").then((email) => {
cy.get('form[data-testid="login-flow-code"] input[name="identifier"]')
.clear()
.type(email.toString())
cy.get('input[name="identifier"]').clear().type(email.toString())
})

cy.submitCodeForm()
Expand All @@ -68,9 +65,7 @@ context("Login error messages with code method", () => {
"An email containing a code has been sent to the email address you provided",
)

cy.get('form[data-testid="login-flow-code"] input[name="code"]').type(
"invalid-code",
)
cy.get('input[name="code"]').type("invalid-code")
cy.submitCodeForm()

cy.get('[data-testid="ui/message/4010008"]').should(
Expand All @@ -81,20 +76,14 @@ context("Login error messages with code method", () => {

it("should show error message when identifier has changed", () => {
cy.get("@email").then((email) => {
cy.get(
'form[data-testid="login-flow-code"] input[name="identifier"]',
).type(email.toString())
cy.get('input[name="identifier"]').type(email.toString())
})

cy.submitCodeForm()

cy.url().should("contain", "login")
cy.get('form[data-testid="login-flow-code"] input[name="identifier"]')
.clear()
.type(gen.email())
cy.get('form[data-testid="login-flow-code"] input[name="code"]').type(
"invalid-code",
)
cy.get('input[name="identifier"]').clear().type(gen.email())
cy.get('input[name="code"]').type("invalid-code")
cy.submitCodeForm()

cy.get('[data-testid="ui/message/4000029"]').should(
Expand All @@ -105,36 +94,24 @@ context("Login error messages with code method", () => {

it("should show error message when required fields are missing", () => {
cy.get("@email").then((email) => {
cy.get(
'form[data-testid="login-flow-code"] input[name="identifier"]',
).type(email.toString())
cy.get('input[name="identifier"]').type(email.toString())
})

cy.submitCodeForm()
cy.url().should("contain", "login")

cy.removeAttribute(
['form[data-testid="login-flow-code"] input[name="code"]'],
"required",
)
cy.removeAttribute(['input[name="code"]'], "required")
cy.submitCodeForm()

cy.get('[data-testid="ui/message/4000002"]').should(
"contain",
"Property code is missing",
)

cy.get('form[data-testid="login-flow-code"] input[name="code"]').type(
"invalid-code",
)
cy.removeAttribute(
['form[data-testid="login-flow-code"] input[name="identifier"]'],
"required",
)
cy.get('input[name="code"]').type("invalid-code")
cy.removeAttribute(['input[name="identifier"]'], "required")

cy.get(
'form[data-testid="login-flow-code"] input[name="identifier"]',
).clear()
cy.get('input[name="identifier"]').clear()

cy.submitCodeForm()
cy.get('[data-testid="ui/message/4000002"]').should(
Expand All @@ -158,28 +135,32 @@ context("Login error messages with code method", () => {
})

cy.get("@email").then((email) => {
cy.get(
'form[data-testid="login-flow-code"] input[name="identifier"]',
).type(email.toString())
cy.get('input[name="identifier"]').type(email.toString())
})
cy.submitCodeForm()

cy.url().should("contain", "login")

cy.get("@email").then((email) => {
cy.getLoginCodeFromEmail(email.toString()).then((code) => {
cy.get(
'form[data-testid="login-flow-code"] input[name="code"]',
).type(code)
cy.get('input[name="code"]').type(code)
})
})

cy.submitCodeForm()

cy.get('[data-testid="ui/message/4010001"]').should(
"contain",
"The login flow expired",
)
// the react app does not show the error message for 410 errors
// it just creates a new flow
if (app === "express") {
cy.get('[data-testid="ui/message/4010001"]').should(
"contain",
"The login flow expired",
)
} else {
cy.get("input[name=identifier]").should("be.visible")
}

cy.noSession()

cy.updateConfigFile((config) => {
config.selfservice.methods.code = {
Expand Down
41 changes: 14 additions & 27 deletions test/e2e/cypress/integration/profiles/code/login/success.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import { appPrefix, APP_URL, gen } from "../../../../helpers"
import { gen } from "../../../../helpers"
import { routes as express } from "../../../../helpers/express"
import { routes as react } from "../../../../helpers/react"

context("Login success with code method", () => {
;[
Expand All @@ -11,11 +12,11 @@ context("Login success with code method", () => {
app: "express" as "express",
profile: "code",
},
// {
// route: react.registration,
// app: "react" as "react",
// profile: "code",
// },
{
route: react.login,
app: "react" as "react",
profile: "code",
},
].forEach(({ route, profile, app }) => {
describe(`for app ${app}`, () => {
before(() => {
Expand All @@ -38,15 +39,11 @@ context("Login success with code method", () => {

it("should be able to sign in with code", () => {
cy.get("@email").then((email) => {
cy.get('form[data-testid="login-flow-code"] input[name="identifier"]')
.clear()
.type(email.toString())
cy.get('input[name="identifier"]').clear().type(email.toString())
cy.submitCodeForm()

cy.getLoginCodeFromEmail(email.toString()).then((code) => {
cy.get(
'form[data-testid="login-flow-code"] input[name="code"]',
).type(code)
cy.get('input[name="code"]').type(code)

cy.get("button[name=method][value=code]").click()
})
Expand All @@ -68,9 +65,7 @@ context("Login success with code method", () => {

it("should be able to resend login code", () => {
cy.get("@email").then((email) => {
cy.get('form[data-testid="login-flow-code"] input[name="identifier"]')
.clear()
.type(email.toString())
cy.get('input[name="identifier"]').clear().type(email.toString())
cy.submitCodeForm()

cy.getLoginCodeFromEmail(email.toString()).then((code) => {
Expand All @@ -91,9 +86,7 @@ context("Login success with code method", () => {

// attempt to submit code 1
cy.get("@code1").then((code1) => {
cy.get('form[data-testid="login-flow-code"] input[name="code"]')
.clear()
.type(code1.toString())
cy.get('input[name="code"]').clear().type(code1.toString())
})

cy.get("button[name=method][value=code]").click()
Expand All @@ -104,9 +97,7 @@ context("Login success with code method", () => {

// attempt to submit code 2
cy.get("@code2").then((code2) => {
cy.get('form[data-testid="login-flow-code"] input[name="code"]')
.clear()
.type(code2.toString())
cy.get('input[name="code"]').clear().type(code2.toString())
})

cy.get('button[name="method"][value="code"]').click()
Expand Down Expand Up @@ -146,15 +137,11 @@ context("Login success with code method", () => {

cy.visit(route)

cy.get('form[data-testid="login-flow-code"] input[name="identifier"]')
.clear()
.type(email2)
cy.get('input[name="identifier"]').clear().type(email2)
cy.submitCodeForm()

cy.getLoginCodeFromEmail(email2).then((code) => {
cy.get('form[data-testid="login-flow-code"] input[name="code"]').type(
code,
)
cy.get('input[name="code"]').type(code)
cy.get("button[name=method][value=code]").click()
})

Expand Down
Loading

0 comments on commit f13a51f

Please sign in to comment.