feat(test-setup): 🎸 run afterOrgCreated for test org and persist stable pkey to env

createTestOrg now calls the production afterOrgCreated hook directly so
the test org goes through the same bootstrap as real orgs (Stripe
Connect, Svix, OrgService.update). Both org branches gate
createStripeAccount on the existing test_stripe_connect to stay
idempotent across re-runs. Pins TEST_ORG_PUBLISHABLE_KEY (a real
KSUID-generated am_pk_test_* value) and persists
UNIT_TEST_AUTUMN_PUBLIC_KEY plus the auto-generated
UNIT_TEST_AUTUMN_SECRET_KEY to server/.env.local + server/.env so test
clients pick them up. Deletes ensureDefaultStripeAccount.ts (replaced by
the gated afterOrgCreated call).
This commit is contained in:
amianthus
2026-05-16 15:08:29 +01:00
parent 86609a1640
commit aaa754ae02
4 changed files with 56 additions and 62 deletions

View File

@@ -3,6 +3,7 @@ import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import chalk from "chalk";
import { config } from "dotenv";
import { TEST_ORG_PUBLISHABLE_KEY } from "./createTestOrg.js";
// Get the directory of this script file
const __filename = fileURLToPath(import.meta.url);
@@ -94,6 +95,7 @@ export function updateEnvFile({
// Update with new test variables
envVars.set("TESTS_ORG", testOrgSlug);
envVars.set("TESTS_ORG_ID", testOrgId);
envVars.set("UNIT_TEST_AUTUMN_PUBLIC_KEY", TEST_ORG_PUBLISHABLE_KEY);
// Only update the secret key if a new one was generated
if (autumnSecretKey) {
@@ -127,6 +129,7 @@ export function updateEnvFile({
// Skip test-related vars from existing content - we'll add them fresh
if (
trimmed.startsWith("TESTS_ORG") ||
trimmed.startsWith("UNIT_TEST_AUTUMN_PUBLIC_KEY") ||
trimmed.startsWith("UNIT_TEST_AUTUMN_SECRET_KEY") ||
trimmed.startsWith("STRIPE_TEST_KEY") ||
trimmed.startsWith("UPSTASH_REDIS_REST") ||
@@ -148,6 +151,7 @@ export function updateEnvFile({
"# Test Configuration",
`TESTS_ORG=${testOrgSlug}`,
`TESTS_ORG_ID=${testOrgId}`,
`UNIT_TEST_AUTUMN_PUBLIC_KEY=${TEST_ORG_PUBLISHABLE_KEY}`,
];
// Only add secret key if it was generated/updated