|
1 | 1 | import { Client, ClientConfig } from 'pg'; |
2 | 2 | import { expect } from 'vitest'; |
3 | 3 | import { niceFetch, STACK_BACKEND_BASE_URL } from '../../../../helpers'; |
4 | | -import { Project } from '../../../backend-helpers'; |
| 4 | +import { InternalApiKey, Project } from '../../../backend-helpers'; |
5 | 5 |
|
6 | 6 |
|
7 | 7 | const PORT_PREFIX = process.env.NEXT_PUBLIC_STACK_PORT_PREFIX || '81'; |
@@ -36,7 +36,7 @@ const CLIENT_CONFIG: Partial<ClientConfig> = { |
36 | 36 | // Track all projects created with external DB configs for cleanup |
37 | 37 | type ProjectContext = { |
38 | 38 | projectId: string, |
39 | | - adminAccessToken: string, |
| 39 | + superSecretAdminKey: string, |
40 | 40 | }; |
41 | 41 | const createdProjects: ProjectContext[] = []; |
42 | 42 |
|
@@ -315,14 +315,18 @@ export async function countUsersInExternalDb(client: Client): Promise<number> { |
315 | 315 | */ |
316 | 316 | export async function createProjectWithExternalDb(externalDatabases: any, projectOptions?: { display_name?: string, description?: string }) { |
317 | 317 | const project = await Project.createAndSwitch(projectOptions); |
| 318 | + const { projectKeys } = await InternalApiKey.createAndSetProjectKeys(project.adminAccessToken); |
| 319 | + if (!projectKeys.superSecretAdminKey) { |
| 320 | + throw new Error('Expected super secret admin key to be present for external DB sync tests.'); |
| 321 | + } |
318 | 322 | await Project.updateConfig({ |
319 | 323 | "dbSync.externalDatabases": externalDatabases |
320 | 324 | }); |
321 | 325 |
|
322 | 326 | // Track this project for cleanup |
323 | 327 | createdProjects.push({ |
324 | 328 | projectId: project.projectId, |
325 | | - adminAccessToken: project.adminAccessToken, |
| 329 | + superSecretAdminKey: projectKeys.superSecretAdminKey, |
326 | 330 | }); |
327 | 331 |
|
328 | 332 | return project; |
@@ -352,8 +356,9 @@ export async function cleanupAllProjectConfigs() { |
352 | 356 | method: 'PATCH', |
353 | 357 | headers: { |
354 | 358 | 'Content-Type': 'application/json', |
| 359 | + 'x-stack-access-type': 'admin', |
355 | 360 | 'x-stack-project-id': project.projectId, |
356 | | - 'x-stack-admin-access-token': project.adminAccessToken, |
| 361 | + 'x-stack-super-secret-admin-key': project.superSecretAdminKey, |
357 | 362 | }, |
358 | 363 | body: JSON.stringify({ |
359 | 364 | config_override_string: JSON.stringify({ "dbSync.externalDatabases": {} }) |
|
0 commit comments