Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/drizzle/__tests__/drizzle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ beforeAll(async () => {
postgresClient = postgres(process.env.DATABASE_URL as string)
db = drizzle({ client: postgresClient })

// Idempotent fixture setup. The `protect-ci` table is shared across the
// drizzle + protect/supabase + stack/supabase integration suites; each
// suite's beforeAll runs the same CREATE TABLE so a fresh database is
// ready without manual DBA work. The schema is the union of every
// column those suites read or write.
await postgresClient`
CREATE TABLE IF NOT EXISTS "protect-ci" (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
email eql_v2_encrypted,
age eql_v2_encrypted,
score eql_v2_encrypted,
profile eql_v2_encrypted,
encrypted eql_v2_encrypted,
created_at TIMESTAMPTZ DEFAULT NOW(),
test_run_id TEXT
)
`

const encryptedUsers = unwrapResult(
await protectClient.bulkEncryptModels(userSeedData, users),
'bulkEncryptModels',
Expand Down
33 changes: 32 additions & 1 deletion packages/protect/__tests__/supabase.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dotenv/config'
import { csColumn, csTable } from '@cipherstash/schema'
import postgres from 'postgres'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import {
type Encrypted,
Expand All @@ -18,6 +19,9 @@ if (!process.env.SUPABASE_URL) {
if (!process.env.SUPABASE_ANON_KEY) {
throw new Error('Missing env.SUPABASE_ANON_KEY')
}
if (!process.env.DATABASE_URL) {
throw new Error('Missing env.DATABASE_URL — needed for fixture setup DDL')
}

const supabase = createClient(
process.env.SUPABASE_URL,
Expand All @@ -41,6 +45,33 @@ const TEST_RUN_ID = `test-run-${Date.now()}-${Math.random().toString(36).slice(2
const insertedIds: number[] = []

beforeAll(async () => {
// Idempotent fixture setup. The `protect-ci` table is shared across the
// drizzle + protect/supabase + stack/supabase integration suites; each
// suite's beforeAll runs the same CREATE TABLE so a fresh database is
// ready without manual DBA work. The schema is the union of every
// column those suites read or write.
const sql = postgres(process.env.DATABASE_URL as string, { prepare: false })
try {
await sql`
CREATE TABLE IF NOT EXISTS "protect-ci" (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
email eql_v2_encrypted,
age eql_v2_encrypted,
score eql_v2_encrypted,
profile eql_v2_encrypted,
encrypted eql_v2_encrypted,
created_at TIMESTAMPTZ DEFAULT NOW(),
test_run_id TEXT
)
`
// Tell PostgREST to refresh its schema cache so the supabase-js client
// can see a freshly created table without waiting for the polling
// interval. No-op on plain Postgres (no listener bound).
await sql`NOTIFY pgrst, 'reload schema'`
} finally {
await sql.end()
}

// Clean up any data from this specific test run (safe for concurrent runs)
const { error } = await supabase
.from('protect-ci')
Expand All @@ -50,7 +81,7 @@ beforeAll(async () => {
if (error) {
console.warn(`[protect]: Failed to clean up test data: ${error.message}`)
}
})
}, 30000)

afterAll(async () => {
// Clean up all data from this test run
Expand Down
31 changes: 31 additions & 0 deletions packages/stack/__tests__/supabase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dotenv/config'
import { Encryption } from '@/index'
import { encryptedColumn, encryptedTable } from '@/schema'
import { encryptedSupabase } from '@/supabase'
import postgres from 'postgres'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'

import { createClient } from '@supabase/supabase-js'
Expand All @@ -12,6 +13,9 @@ if (!process.env.SUPABASE_URL) {
if (!process.env.SUPABASE_ANON_KEY) {
throw new Error('Missing env.SUPABASE_ANON_KEY')
}
if (!process.env.DATABASE_URL) {
throw new Error('Missing env.DATABASE_URL — needed for fixture setup DDL')
}

const supabase = createClient(
process.env.SUPABASE_URL,
Expand Down Expand Up @@ -42,6 +46,33 @@ const TEST_RUN_ID = `test-run-${Date.now()}-${Math.random().toString(36).slice(2
const insertedIds: number[] = []

beforeAll(async () => {
// Idempotent fixture setup. The `protect-ci` table is shared across the
// drizzle + protect/supabase + stack/supabase integration suites; each
// suite's beforeAll runs the same CREATE TABLE so a fresh database is
// ready without manual DBA work. The schema is the union of every
// column those suites read or write.
const sql = postgres(process.env.DATABASE_URL as string, { prepare: false })
try {
await sql`
CREATE TABLE IF NOT EXISTS "protect-ci" (
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
email eql_v2_encrypted,
age eql_v2_encrypted,
score eql_v2_encrypted,
profile eql_v2_encrypted,
encrypted eql_v2_encrypted,
created_at TIMESTAMPTZ DEFAULT NOW(),
test_run_id TEXT
)
`
// Tell PostgREST to refresh its schema cache so the supabase-js client
// can see a freshly created table without waiting for the polling
// interval. No-op on plain Postgres (no listener bound).
await sql`NOTIFY pgrst, 'reload schema'`
} finally {
await sql.end()
}

// Clean up any data from this specific test run (safe for concurrent runs)
const { error } = await supabase
.from('protect-ci')
Expand Down
Loading