From 8b88c7a2586cf4a7b7ddb977085fe8980d80c6b1 Mon Sep 17 00:00:00 2001 From: CactusBlue Date: Thu, 27 Feb 2025 16:32:41 -0800 Subject: [PATCH] Add E2E tests for the JS library (#487) * Add dependency on @stackframe/js to e2e tests * add more * add some additional logic for issuing api key * more * fix window dependency * roll it back * chore: update package versions * Make Project description field non-nullable (#483) Co-Authored-By: Konstantin Wohlwend * Run E2E API tests on Node v22 too * Run E2E tests on latest Node.js version * Codegen + macros for SDK docs (#456) * add extra body * Add link to Docker image to docs * Permit signUpWithCredential in non-browser environments * get the tests running * remove * fix * update the interface * Update apps/e2e/tests/js/js-helpers.ts Co-authored-by: Konsti Wohlwend --------- Co-authored-by: Konstantin Wohlwend Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Zai Shi --- apps/e2e/package.json | 1 + apps/e2e/tests/js/general.test.ts | 7 ++++++ apps/e2e/tests/js/js-helpers.ts | 35 ++++++++++++++++++++++++++ packages/template/src/lib/stack-app.ts | 2 +- pnpm-lock.yaml | 3 +++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 apps/e2e/tests/js/general.test.ts create mode 100644 apps/e2e/tests/js/js-helpers.ts diff --git a/apps/e2e/package.json b/apps/e2e/package.json index 1daf4e31b..e89342451 100644 --- a/apps/e2e/package.json +++ b/apps/e2e/package.json @@ -11,6 +11,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { + "@stackframe/js": "workspace:*", "@stackframe/stack-shared": "workspace:*", "dotenv": "^16.4.5", "jose": "^5.2.2", diff --git a/apps/e2e/tests/js/general.test.ts b/apps/e2e/tests/js/general.test.ts new file mode 100644 index 000000000..d7e58eefc --- /dev/null +++ b/apps/e2e/tests/js/general.test.ts @@ -0,0 +1,7 @@ +import { it } from "../helpers"; +import { scaffoldProject } from "./js-helpers"; + +it("should scaffold the project", async ({ expect }) => { + const { project } = await scaffoldProject(); + expect(project.displayName).toBe("New Project"); +}); diff --git a/apps/e2e/tests/js/js-helpers.ts b/apps/e2e/tests/js/js-helpers.ts new file mode 100644 index 000000000..b8256ae2a --- /dev/null +++ b/apps/e2e/tests/js/js-helpers.ts @@ -0,0 +1,35 @@ +import { AdminProjectUpdateOptions, StackAdminApp } from '@stackframe/js'; +import { wait } from '@stackframe/stack-shared/dist/utils/promises'; +import { STACK_BACKEND_BASE_URL, STACK_INTERNAL_PROJECT_ADMIN_KEY, STACK_INTERNAL_PROJECT_CLIENT_KEY, STACK_INTERNAL_PROJECT_SERVER_KEY } from '../helpers'; + +export async function scaffoldProject(body?: AdminProjectUpdateOptions) { + const internalApp = new StackAdminApp({ + projectId: 'internal', + baseUrl: STACK_BACKEND_BASE_URL, + publishableClientKey: STACK_INTERNAL_PROJECT_CLIENT_KEY, + secretServerKey: STACK_INTERNAL_PROJECT_SERVER_KEY, + superSecretAdminKey: STACK_INTERNAL_PROJECT_ADMIN_KEY, + tokenStore: "memory", + }); + + const fakeEmail = `${crypto.randomUUID()}@stack-js-test.example.com`; + + await internalApp.signUpWithCredential({ + email: fakeEmail, + password: "password", + verificationCallbackUrl: "https://stack-js-test.example.com/verify", + }); + const user = await internalApp.getUser({ + or: 'throw', + }); + + const project = await user.createProject({ + displayName: body?.displayName || 'New Project', + ...body, + }); + + return { + project, + user, + }; +} diff --git a/packages/template/src/lib/stack-app.ts b/packages/template/src/lib/stack-app.ts index 67afa8910..7be2d8883 100644 --- a/packages/template/src/lib/stack-app.ts +++ b/packages/template/src/lib/stack-app.ts @@ -3574,7 +3574,7 @@ export type StackClientApp, signInWithCredential(options: { email: string, password: string, noRedirect?: boolean }): Promise>, - signUpWithCredential(options: { email: string, password: string, noRedirect?: boolean }): Promise>, + signUpWithCredential(options: { email: string, password: string, noRedirect?: boolean, verificationCallbackUrl?: string }): Promise>, signInWithPasskey(): Promise>, callOAuthCallback(): Promise, sendForgotPasswordEmail(email: string, options?: { callbackUrl?: string }): Promise>, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4e421d543..ad8f5e74c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -419,6 +419,9 @@ importers: apps/e2e: dependencies: + '@stackframe/js': + specifier: workspace:* + version: link:../../packages/js '@stackframe/stack-shared': specifier: workspace:* version: link:../../packages/stack-shared