Skip to content

Commit

Permalink
test(e2e): fix compile errors in commands (#3179)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas committed Mar 21, 2023
1 parent 9d59fd7 commit 0002668
Show file tree
Hide file tree
Showing 10 changed files with 1,973 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
verifyHrefPattern,
} from "../../../../helpers"

import { routes as react } from "../../../../helpers/react"
import { routes as express } from "../../../../helpers/express"
import { routes as react } from "../../../../helpers/react"

context("Account Verification Registration Errors", () => {
;[
Expand Down Expand Up @@ -49,7 +49,7 @@ context("Account Verification Registration Errors", () => {
it("is unable to verify the email address if the code is no longer valid and resend the code", () => {
cy.shortCodeLifespan()
cy.verifyEmailButExpired({
expect: { email: identity.email, password: identity.password },
expect: { email: identity.email },
})

cy.longCodeLifespan()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
verifyHrefPattern,
} from "../../../../helpers"

import { routes as react } from "../../../../helpers/react"
import { routes as express } from "../../../../helpers/express"
import { routes as react } from "../../../../helpers/react"

context("Account Verification Settings Error", () => {
;[
Expand Down Expand Up @@ -62,7 +62,7 @@ context("Account Verification Settings Error", () => {
cy.get('button[value="profile"]').click()

cy.verifyEmailButExpired({
expect: { email, password: identity.password },
expect: { email },
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ context("Registration success with email profile with webhooks", () => {
expect(identity.schema_id).to.equal("default")
expect(identity.schema_url).to.equal(`${APP_URL}/schemas/ZGVmYXVsdA`)
expect(identity.traits.email).to.equal("updated-" + email)
expect(identity.metadata_public.some).to.equal("public fields")
expect((identity as any).metadata_public.some).to.equal(
"public fields",
)
expect(identity.verifiable_addresses[0].verified).to.equal(true)
expect(identity.verifiable_addresses[0].verified_at).not.to.be.empty
expect(identity.verifiable_addresses[0].via).to.eq("email")
Expand Down
45 changes: 13 additions & 32 deletions test/e2e/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import {
MOBILE_URL,
parseHtml,
pollInterval,
privilegedLifespan,
} from "../helpers"

import { Session } from "@ory/kratos-client"
import dayjs from "dayjs"
import YAML from "yamljs"
import { Strategy } from "."
import { OryKratosConfiguration } from "./config"

const configFile = "kratos.generated.yml"

Expand Down Expand Up @@ -49,7 +48,9 @@ function checkConfigVersion(previous, tries = 0) {
})
}

const updateConfigFile = (cb: (arg: any) => any) => {
const updateConfigFile = (
cb: (arg: OryKratosConfiguration) => OryKratosConfiguration,
) => {
cy.request("GET", KRATOS_ADMIN + "/health/config").then(({ body }) => {
cy.readFile(configFile).then((contents) => {
cy.writeFile(configFile, YAML.stringify(cb(YAML.parse(contents))))
Expand Down Expand Up @@ -398,6 +399,7 @@ Cypress.Commands.add(
})
.then(({ body }) => {
expect(body.identity.traits.email).to.contain(email)
return body
}),
)

Expand Down Expand Up @@ -440,6 +442,7 @@ Cypress.Commands.add("loginApi", ({ email, password } = {}) =>
})
.then(({ body }) => {
expect(body.session.identity.traits.email).to.contain(email)
return body
}),
)

Expand Down Expand Up @@ -1003,18 +1006,6 @@ Cypress.Commands.add("noSession", () =>
return request
}),
)
Cypress.Commands.add("getIdentityByEmail", ({ email }) =>
cy
.request({
method: "GET",
url: `${KRATOS_ADMIN}/identities`,
failOnStatusCode: false,
})
.then((response) => {
expect(response.status).to.eq(200)
return response.body.find((identity) => identity.traits.email === email)
}),
)

Cypress.Commands.add(
"performEmailVerification",
Expand Down Expand Up @@ -1115,7 +1106,7 @@ Cypress.Commands.add(
// Uses the verification email but waits so that it expires
Cypress.Commands.add(
"verifyEmailButExpired",
({ expect: { email, password }, strategy = "code" }) => {
({ expect: { email }, strategy = "code" }) => {
cy.getMail().then((message) => {
expect(message.subject).to.equal("Please verify your email address")

Expand Down Expand Up @@ -1158,27 +1149,17 @@ Cypress.Commands.add("useVerificationStrategy", (strategy: Strategy) => {
})
})

// Uses the verification email but waits so that it expires
Cypress.Commands.add("waitForPrivilegedSessionToExpire", () => {
cy.getSession().should((session: Session) => {
expect(session.authenticated_at).to.not.be.empty
cy.wait(
dayjs(session.authenticated_at).add(privilegedLifespan).diff(dayjs()) +
100,
)
})
})

Cypress.Commands.add("getLookupSecrets", () =>
cy
.get('[data-testid="node/text/lookup_secret_codes/text"] code')
.then(($e) => $e.map((_, e) => e.innerText.trim()).toArray()),
)
Cypress.Commands.add("expectSettingsSaved", () =>
cy
.get('[data-testid="ui/message/1050001"]')
.should("contain.text", "Your changes have been saved"),
)
Cypress.Commands.add("expectSettingsSaved", () => {
cy.get('[data-testid="ui/message/1050001"]').should(
"contain.text",
"Your changes have been saved",
)
})

Cypress.Commands.add("getMail", ({ removeMail = true } = {}) => {
let tries = 0
Expand Down
Loading

0 comments on commit 0002668

Please sign in to comment.