Skip to content

Commit

Permalink
feat: fix e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Jun 24, 2024
1 parent 3801e35 commit 698cb06
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/ory/hydra-client-go/v2 v2.2.0-rc.3.0.20240202131107-1c7b57df3bb0
github.com/ory/hydra/v2 v2.2.0-pre.1
github.com/ory/jsonschema/v3 v3.0.8
github.com/ory/keto v0.11.1-alpha.0.0.20231228131228-b2c3464bdc4f
github.com/ory/keto v0.13.0-alpha.0.0.20240624092507-567ceb9144b0
github.com/ory/kratos v1.1.0-pre.0.0.20240205165553-fd7995077307
github.com/ory/x v0.0.613
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,8 @@ github.com/ory/hydra/v2 v2.2.0-pre.1 h1:+VzGZ6AtiajgTq0I5m2nYvEX0l+I/nIci5kTuVA/
github.com/ory/hydra/v2 v2.2.0-pre.1/go.mod h1:yQRtYAxtGOD41QakuLLI9GVO9BUQzL5ShAxikGZPQbA=
github.com/ory/jsonschema/v3 v3.0.8 h1:Ssdb3eJ4lDZ/+XnGkvQS/te0p+EkolqwTsDOCxr/FmU=
github.com/ory/jsonschema/v3 v3.0.8/go.mod h1:ZPzqjDkwd3QTnb2Z6PAS+OTvBE2x5i6m25wCGx54W/0=
github.com/ory/keto v0.13.0-alpha.0.0.20240624092507-567ceb9144b0 h1:lsBYI6FsW+DQSzTld2fiC4bC8ELOfGrbARqguomWIqk=
github.com/ory/keto v0.13.0-alpha.0.0.20240624092507-567ceb9144b0/go.mod h1:NXGcNJ65ocZG5mvUCtoDHW53tA2MNoK2iQL7L0UDaGs=
github.com/ory/keto/proto v0.11.1-alpha.0.0.20231229091411-ac44cabd79b7 h1:qHgWDFJ642DUYj7fMUs7pRTqr1oM7Hqw26qnxB9lvlk=
github.com/ory/keto/proto v0.11.1-alpha.0.0.20231229091411-ac44cabd79b7/go.mod h1:6RagCXA7X1hhFSVjcy13ruIo8Dq/nj4J0mcN92qL+hY=
github.com/ory/kratos v1.1.0-pre.0.0.20240205165553-fd7995077307 h1:GM/UJdUQY+t42wmo/6gcrqqr/BwwZI/NpyAirQtcppQ=
Expand Down
96 changes: 96 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"prettier": "ory-prettier-styles",
"dependencies": {
"@ory/client": "^1.11.11",
"binwrap": "^0.2.3"
},
"devDependencies": {
Expand Down
39 changes: 34 additions & 5 deletions tests/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,48 @@ import { ChildProcessWithoutNullStreams, spawn } from "child_process"
import { randomBytes } from "crypto"
import { unlink } from "fs/promises"
import readline from "node:readline/promises"
import * as sdk from "@ory/client"

function generateRandomFileName(extension: string): string {
const randomString = randomBytes(16).toString("hex")
return `${randomString}${extension}`
}

test.describe("should be able to login with the CLI", () => {
const email = `${randomBytes(16).toString("hex")}@example.com`
const password = randomBytes(16).toString("hex")
const config = generateRandomFileName(".cli-config.json")
let url: string = ""
let child: ChildProcessWithoutNullStreams
let child: ChildProcessWithoutNullStreams | undefined
let rl: readline.Interface

test.beforeAll(async () => {
const ory = new sdk.FrontendApi(
new sdk.Configuration({
basePath: "https://project.console.ory:8080",
}),
)

const {
data: { id: flowID },
} = await ory.createNativeRegistrationFlow()
const res = await ory.updateRegistrationFlow({
flow: flowID,
updateRegistrationFlowBody: {
method: "password",
password,
traits: {
email,
name: "John Doe",
consent: {
newsletter: false,
tos: new Date().toISOString(),
},
},
},
})
expect(res.status).toBe(200)

child = spawn("./cli", ["auth"], {
env: {
HOME: "/dev/null",
Expand Down Expand Up @@ -44,20 +73,20 @@ test.describe("should be able to login with the CLI", () => {
})

test.afterAll(async () => {
child.kill()
await unlink(config)
child?.kill()
await unlink(config).catch(() => {})
})

test("with email and password", async ({ page }) => {
await page.goto(url)
const emailInput = await page.locator(
`[data-testid="node/input/identifier"] input`,
)
await emailInput.fill("<email>")
await emailInput.fill(email)
const passwordInput = await page.locator(
`[data-testid="node/input/password"] input`,
)
await passwordInput.fill("<password>")
await passwordInput.fill(password)
const submit = page.locator(
'[type="submit"][name="method"][value="password"]',
)
Expand Down

0 comments on commit 698cb06

Please sign in to comment.