import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; describe('billing customer foundation correction migration', () => { let migrationSql: string; beforeAll(async () => { migrationSql = await readFile( join( process.cwd(), 'prisma/migrations/20260708130000_milestone121_checkout_customer_foundation_correction/migration.sql', ), 'utf8', ); }); it('creates the billing_customers table', () => { expect(migrationSql).toContain(`CREATE TABLE "billing_customers"`); }); it('enforces one billing customer per user and unique provider customer ids', () => { expect(migrationSql).toContain( `CREATE UNIQUE INDEX "billing_customers_user_id_key"`, ); expect(migrationSql).toContain( `CREATE UNIQUE INDEX "billing_customers_provider_customer_id_key"`, ); }); it('relates billing customers to users with cascading deletes', () => { expect(migrationSql).toContain( `ADD CONSTRAINT "billing_customers_user_id_fkey"`, ); expect(migrationSql).toContain(`REFERENCES "users"("id")`); expect(migrationSql).toContain(`ON DELETE CASCADE`); expect(migrationSql).toContain(`ON UPDATE CASCADE`); }); it('removes provider customer identity from user_subscriptions', () => { expect(migrationSql).toContain( `DROP INDEX "user_subscriptions_provider_customer_id_key";`, ); expect(migrationSql).toContain( `DROP COLUMN "provider_customer_id";`, ); }); });