Files
supabase/packages/pg-meta/test/schemas.test.ts
0e2c31bf60 feat: Stripe Sync Engine integration (#41317)
* add initial installation flow of stripe sync engine

* update docs link

* Add supabase_vault extension dep

* Add stripe logo to sync engine integration

* Move overview content to bottom of integration pages

* Add sync state to stripe sync page

* only check sync state if stripe integration is installed

* Use proper stripe-sync package and setup flows

* Improve sync engine installation ux

* Remove unused hardcoded dep

* Add alpha status to stripe sync engine integration

* fix typo

* run format

* fix types

* Rename the stripe-sync path to remove the 'integration". The path needs to have BASE_PATH to work on prod.

* Design tidy up (#41337)

UI tidy up

* update to latest sync engine package

* Add stripe key verification

* Remove noop try/catch

* Add integration isntallation telelemtry

* Add basic settings page

* Address coderabbit comments

* remove unused dep

* Remove state setting on render

* s/description/comment

* Cleanup settings screen UI

* Improve settings screen design

* update schema test snapshot

* Use latest stripe-sync-engine package

* Update repo url to new official location

* revert marketing change

* Update stripe sync engine package

* Add link to table from overview page

* Add feature flag and improve telemetry

* Fix missing useMemo dep

* add uninstall telemetry note

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
2025-12-20 00:42:10 +00:00

137 lines
3.5 KiB
TypeScript

import { expect, test, beforeAll, afterAll } from 'vitest'
import pgMeta from '../src/index'
import { createTestDatabase, cleanupRoot } from './db/utils'
beforeAll(async () => {
// Any global setup if needed
})
afterAll(async () => {
await cleanupRoot()
})
const withTestDatabase = (
name: string,
fn: (db: Awaited<ReturnType<typeof createTestDatabase>>) => Promise<void>
) => {
test(name, async () => {
const db = await createTestDatabase()
try {
await fn(db)
} finally {
await db.cleanup()
}
})
}
// Example of refactored tests using the wrapper
withTestDatabase('list with system schemas', async ({ executeQuery }) => {
const { sql, zod } = await pgMeta.schemas.list({ includeSystemSchemas: true })
const res = zod.parse(await executeQuery(sql))
expect(res.find(({ name }) => name === 'pg_catalog')).toMatchInlineSnapshot(
{ id: expect.any(Number) },
`
{
"comment": "system catalog schema",
"id": Any<Number>,
"name": "pg_catalog",
"owner": "postgres",
}
`
)
})
withTestDatabase('list without system schemas', async ({ executeQuery }) => {
const { sql, zod } = await pgMeta.schemas.list({ includeSystemSchemas: false })
const rq = await executeQuery<typeof zod._type>(sql)
const res = zod.parse(rq)
expect(res.find(({ name }) => name === 'pg_catalog')).toMatchInlineSnapshot(`undefined`)
expect(res.find(({ name }) => name === 'public')).toMatchInlineSnapshot(
{ id: expect.any(Number) },
`
{
"comment": "standard public schema",
"id": Any<Number>,
"name": "public",
"owner": "postgres",
}
`
)
})
withTestDatabase('retrieve, create, update, delete', async ({ executeQuery }) => {
// Create schema
const { sql: createSql } = await pgMeta.schemas.create({ name: 's' })
await executeQuery(createSql)
// Get the created schema
const { sql: retrieveSql, zod } = await pgMeta.schemas.retrieve({ name: 's' })
const createRes = zod.parse((await executeQuery(retrieveSql))[0])
expect(createRes).toMatchInlineSnapshot(
{ id: expect.any(Number) },
`
{
"comment": null,
"id": Any<Number>,
"name": "s",
"owner": "postgres",
}
`
)
// Retrieve schema again to verify
const { sql: retrieveSql2, zod: retrieveZod } = await pgMeta.schemas.retrieve({
id: createRes!.id,
})
const retrieveRes = retrieveZod.parse((await executeQuery(retrieveSql2))[0])
expect(retrieveRes).toMatchInlineSnapshot(
{ id: expect.any(Number) },
`
{
"comment": null,
"id": Any<Number>,
"name": "s",
"owner": "postgres",
}
`
)
// Update schema
const { sql: updateSql } = await pgMeta.schemas.update(
{ id: createRes!.id },
{
name: 'ss',
owner: 'postgres',
}
)
await executeQuery(updateSql)
// Get the updated schema
const { sql: retrieveUpdatedSql, zod: retrieveUpdatedZod } = await pgMeta.schemas.retrieve({
name: 'ss',
})
const updateRes = retrieveUpdatedZod.parse((await executeQuery(retrieveUpdatedSql))[0])
expect(updateRes).toMatchInlineSnapshot(
{ id: expect.any(Number) },
`
{
"comment": null,
"id": Any<Number>,
"name": "ss",
"owner": "postgres",
}
`
)
// Delete schema
const { sql: deleteSql } = await pgMeta.schemas.remove({ id: updateRes!.id })
await executeQuery(deleteSql)
// Verify deletion
const { sql: finalRetrieveSql } = await pgMeta.schemas.retrieve({ id: updateRes!.id })
const finalRes = await executeQuery(finalRetrieveSql)
expect(finalRes).toMatchInlineSnapshot(`[]`)
})