LogicalBackupCliInstructions.test.ts78 lines · main
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | |
| 3 | import { |
| 4 | buildDirectPostgresConnectionUri, |
| 5 | buildLogicalBackupShellScript, |
| 6 | DB_PASSWORD_PLACEHOLDER, |
| 7 | } from '../../components/layouts/ProjectLayout/LogicalBackupCliInstructions.utils' |
| 8 | |
| 9 | describe('buildDirectPostgresConnectionUri', () => { |
| 10 | it('builds a valid postgresql URI from settings', () => { |
| 11 | const uri = buildDirectPostgresConnectionUri({ |
| 12 | db_user: 'postgres', |
| 13 | db_host: 'db.abcdef.supabase.co', |
| 14 | db_port: 5432, |
| 15 | db_name: 'postgres', |
| 16 | }) |
| 17 | expect(uri).toBe( |
| 18 | `postgresql://postgres:${DB_PASSWORD_PLACEHOLDER}@db.abcdef.supabase.co:5432/postgres` |
| 19 | ) |
| 20 | }) |
| 21 | |
| 22 | it('uses the password placeholder, never a real password', () => { |
| 23 | const uri = buildDirectPostgresConnectionUri({ |
| 24 | db_user: 'postgres', |
| 25 | db_host: 'db.abcdef.supabase.co', |
| 26 | db_port: 5432, |
| 27 | db_name: 'postgres', |
| 28 | }) |
| 29 | expect(uri).toContain(DB_PASSWORD_PLACEHOLDER) |
| 30 | expect(uri).not.toContain('secret') |
| 31 | }) |
| 32 | |
| 33 | it('includes a non-default port', () => { |
| 34 | const uri = buildDirectPostgresConnectionUri({ |
| 35 | db_user: 'postgres', |
| 36 | db_host: 'db.abcdef.supabase.co', |
| 37 | db_port: 6543, |
| 38 | db_name: 'postgres', |
| 39 | }) |
| 40 | expect(uri).toContain(':6543/') |
| 41 | }) |
| 42 | }) |
| 43 | |
| 44 | describe('buildLogicalBackupShellScript', () => { |
| 45 | const testUri = `postgresql://postgres:${DB_PASSWORD_PLACEHOLDER}@db.abcdef.supabase.co:5432/postgres` |
| 46 | |
| 47 | it('produces exactly three commands', () => { |
| 48 | const script = buildLogicalBackupShellScript(testUri) |
| 49 | expect(script.split('\n')).toHaveLength(3) |
| 50 | }) |
| 51 | |
| 52 | it('wraps the connection URI in single quotes to prevent shell expansion', () => { |
| 53 | const script = buildLogicalBackupShellScript(testUri) |
| 54 | for (const line of script.split('\n')) { |
| 55 | expect(line).toContain(`'${testUri}'`) |
| 56 | } |
| 57 | }) |
| 58 | |
| 59 | it('dumps roles, schema, and data in that order', () => { |
| 60 | const [roles, schema, data] = buildLogicalBackupShellScript(testUri).split('\n') |
| 61 | expect(roles).toContain('--role-only') |
| 62 | expect(roles).toContain('-f roles.sql') |
| 63 | expect(schema).toContain('-f schema.sql') |
| 64 | expect(data).toContain('--data-only') |
| 65 | expect(data).toContain('-f data.sql') |
| 66 | }) |
| 67 | |
| 68 | it('excludes storage vector tables from the data dump', () => { |
| 69 | const [, , data] = buildLogicalBackupShellScript(testUri).split('\n') |
| 70 | expect(data).toContain('-x "storage.buckets_vectors"') |
| 71 | expect(data).toContain('-x "storage.vector_indexes"') |
| 72 | }) |
| 73 | |
| 74 | it('does not include npx briven login', () => { |
| 75 | const script = buildLogicalBackupShellScript(testUri) |
| 76 | expect(script).not.toContain('briven login') |
| 77 | }) |
| 78 | }) |