Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
101 lines
2.2 KiB
TypeScript
101 lines
2.2 KiB
TypeScript
// Copyright © 2024 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import { faker } from "@faker-js/faker"
|
|
import { APIRequestContext } from "@playwright/test"
|
|
import { CreateIdentityBody } from "@ory/kratos-client"
|
|
import { generatePhoneNumber, CountryNames } from "phone-number-generator-js"
|
|
import { expect } from "../fixtures"
|
|
|
|
export async function createIdentity(
|
|
request: APIRequestContext,
|
|
data: Partial<CreateIdentityBody>,
|
|
) {
|
|
const resp = await request.post("http://localhost:4434/admin/identities", {
|
|
data,
|
|
})
|
|
expect(resp.status()).toBe(201)
|
|
return await resp.json()
|
|
}
|
|
|
|
export async function createIdentityWithPhoneNumber(
|
|
request: APIRequestContext,
|
|
) {
|
|
const phone = generatePhoneNumber({
|
|
countryName: CountryNames.Germany,
|
|
withoutCountryCode: false,
|
|
})
|
|
return {
|
|
identity: await createIdentity(request, {
|
|
schema_id: "sms",
|
|
traits: {
|
|
phone,
|
|
},
|
|
}),
|
|
phone,
|
|
}
|
|
}
|
|
|
|
export async function createIdentityWithEmail(request: APIRequestContext) {
|
|
const email = faker.internet.email({ provider: "ory.sh" })
|
|
return {
|
|
identity: await createIdentity(request, {
|
|
schema_id: "email",
|
|
traits: {
|
|
email,
|
|
website: faker.internet.url(),
|
|
},
|
|
}),
|
|
email,
|
|
}
|
|
}
|
|
|
|
export async function createIdentityWithPhoneAndPassword(
|
|
request: APIRequestContext,
|
|
phone: string,
|
|
password: string,
|
|
schemaId = "sms-password",
|
|
) {
|
|
return {
|
|
identity: await createIdentity(request, {
|
|
schema_id: schemaId,
|
|
traits: {
|
|
phone,
|
|
},
|
|
credentials: {
|
|
password: {
|
|
config: {
|
|
password,
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
phone,
|
|
password,
|
|
}
|
|
}
|
|
|
|
export async function createIdentityWithPassword(request: APIRequestContext) {
|
|
const email = faker.internet.email({ provider: "ory.sh" })
|
|
const password = faker.internet.password()
|
|
return {
|
|
identity: await createIdentity(request, {
|
|
schema_id: "email",
|
|
traits: {
|
|
email,
|
|
website: faker.internet.url(),
|
|
},
|
|
|
|
credentials: {
|
|
password: {
|
|
config: {
|
|
password,
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
email,
|
|
password,
|
|
}
|
|
}
|