stack/apps/e2e/tests/js/app.test.ts
BilalG1 609579abab
Some checks failed
all-good: Did all the other checks pass? / all-good (push) Has been cancelled
Ensure Prisma migrations are in sync with the schema / check_prisma_migrations (22.x) (push) Has been cancelled
DB migration compat / Check if migrations changed (push) Has been cancelled
Docker Server Build and Push / Docker Build and Push Server (push) Has been cancelled
Docker Server Build and Run / docker (push) Has been cancelled
Runs E2E API Tests (Local Emulator) / E2E Tests (Local Emulator, Node ${{ matrix.node-version }}) (22.x) (push) Has been cancelled
Runs E2E API Tests / E2E Tests (Node ${{ matrix.node-version }}, Freestyle ${{ matrix.freestyle-mode }}) (mock, 22.x) (push) Has been cancelled
Runs E2E API Tests / E2E Tests (Node ${{ matrix.node-version }}, Freestyle ${{ matrix.freestyle-mode }}) (prod, 22.x) (push) Has been cancelled
Runs E2E API Tests with custom port prefix / build (22.x) (push) Has been cancelled
Runs E2E Fallback Tests / E2E Fallback Tests (Node ${{ matrix.node-version }}) (22.x) (push) Has been cancelled
Lint & build / lint_and_build (24) (push) Has been cancelled
TOC Generator / TOC Generator (push) Has been cancelled
DB migration compat / Back-compat — Current branch migrations with ${{ needs.check-migrations-changed.outputs.base_branch }} branch code (push) Has been cancelled
DB migration compat / Forward-compat — Current branch code with ${{ needs.check-migrations-changed.outputs.base_branch }} branch migrations (push) Has been cancelled
DB migration compat / No migration changes (skipped) (push) Has been cancelled
feat(hexclave): PR 3 — native @hexclave/* source rename + delete dual-publish wiring (#1482)
2026-05-29 15:21:59 -07:00

161 lines
4.6 KiB
TypeScript

import { isUuid } from "@hexclave/shared/dist/utils/uuids";
import { it } from "../helpers";
import { createApp, scaffoldProject } from "./js-helpers";
it("should scaffold the project", async ({ expect }) => {
const { project } = await scaffoldProject();
expect(project.displayName).toBe("New Project");
});
it("should sign up with credential", async ({ expect }) => {
const { clientApp } = await createApp();
const result1 = await clientApp.signUpWithCredential({
email: "test@test.com",
password: "password",
verificationCallbackUrl: "http://localhost:3000",
});
expect(result1).toMatchInlineSnapshot(`
{
"data": undefined,
"status": "ok",
}
`);
const result2 = await clientApp.signInWithCredential({
email: "test@test.com",
password: "password",
});
expect(result2).toMatchInlineSnapshot(`
{
"data": undefined,
"status": "ok",
}
`);
});
it("should sign up without a verification callback when disabled", async ({ expect }) => {
const { clientApp } = await createApp();
const signUpResult = await clientApp.signUpWithCredential({
email: "no-verification@test.com",
password: "password",
noVerificationCallback: true,
});
expect(signUpResult).toMatchInlineSnapshot(`
{
"data": undefined,
"status": "ok",
}
`);
const signInResult = await clientApp.signInWithCredential({
email: "no-verification@test.com",
password: "password",
});
expect(signInResult).toMatchInlineSnapshot(`
{
"data": undefined,
"status": "ok",
}
`);
});
it("should throw when disabling verification with a callback url provided", async ({ expect }) => {
const { clientApp } = await createApp();
await expect(clientApp.signUpWithCredential({
email: "no-verification-conflict@test.com",
password: "password",
noVerificationCallback: true,
// @ts-expect-error - testing the error case
verificationCallbackUrl: "http://localhost:3000",
})).rejects.toMatchObject({
message: expect.stringContaining("verificationCallbackUrl is not allowed when noVerificationCallback is true"),
name: "HexclaveAssertionError",
});
});
it("should create user on the server", async ({ expect }) => {
const { serverApp } = await createApp();
const user = await serverApp.createUser({
primaryEmail: "test@test.com",
password: "password",
primaryEmailAuthEnabled: true,
});
expect(isUuid(user.id)).toBe(true);
const user2 = await serverApp.getUser(user.id);
expect(user2?.id).toBe(user.id);
const result = await serverApp.signInWithCredential({
email: "test@test.com",
password: "password",
});
expect(result).toMatchInlineSnapshot(`
{
"data": undefined,
"status": "ok",
}
`);
});
it("should create user on the server with country code and risk scores", async ({ expect }) => {
const { serverApp } = await createApp();
const user = await serverApp.createUser({
primaryEmail: "imported-risk@test.com",
primaryEmailAuthEnabled: true,
countryCode: "US",
riskScores: {
signUp: {
bot: 61,
freeTrialAbuse: 27,
},
},
});
expect(user.countryCode).toBe("US");
expect(user.riskScores).toEqual({
signUp: {
bot: 61,
freeTrialAbuse: 27,
},
});
});
it("should throw a helpful error when destructuring user", async ({ expect }) => {
const { clientApp, serverApp } = await createApp();
const email = "user-destructure@test.com";
const password = "password";
const signUpResult = await clientApp.signUpWithCredential({
email,
password,
verificationCallbackUrl: "http://localhost:3000",
});
expect(signUpResult.status).toBe("ok");
const signInResult = await clientApp.signInWithCredential({
email,
password,
});
expect(signInResult.status).toBe("ok");
const currentUser = await clientApp.getUser({ or: "throw" });
const accessClientUser = () => (currentUser as any).user;
expect(accessClientUser).toThrowError("Hexclave: useUser() already returns the user object. Use `const user = useUser()` (or `const user = await app.getUser()`) instead of destructuring it like `const { user } = ...`.");
const serverUser = await serverApp.getUser(currentUser.id);
if (!serverUser) {
throw new Error("Expected server user to exist for destructure guard test");
}
const accessServerUser = () => (serverUser as any).user;
expect(accessServerUser).toThrowError("Hexclave: useUser() already returns the user object. Use `const user = useUser()` (or `const user = await app.getUser()`) instead of destructuring it like `const { user } = ...`.");
});