(options: { readonly ledgerExists?: boolean; readonly stamped?: string[] })
| 8 | } from "../../scripts/code-migrations/runner"; |
| 9 | |
| 10 | const makeFakeSql = (options: { readonly ledgerExists?: boolean; readonly stamped?: string[] }) => { |
| 11 | const log: { readonly query: string; readonly params?: readonly unknown[] }[] = []; |
| 12 | const stamped = [...(options.stamped ?? [])]; |
| 13 | const sql: CodeMigrationSql = { |
| 14 | unsafe: (query, params) => { |
| 15 | log.push({ query, params }); |
| 16 | if (query.includes("to_regclass")) { |
| 17 | const rows = [ |
| 18 | { ledger_table: options.ledgerExists === false ? null : "cloud_code_migration" }, |
| 19 | ]; |
| 20 | return Promise.resolve(rows as never); |
| 21 | } |
| 22 | if (query.includes('SELECT "name" FROM "cloud_code_migration"')) { |
| 23 | return Promise.resolve(stamped.map((name) => ({ name })) as never); |
| 24 | } |
| 25 | if (query.includes('INSERT INTO "cloud_code_migration"')) { |
| 26 | stamped.push(String(params?.[0])); |
| 27 | } |
| 28 | return Promise.resolve([] as never); |
| 29 | }, |
| 30 | }; |
| 31 | return { sql, log, stamped }; |
| 32 | }; |
| 33 | |
| 34 | const migrationSpy = (name: string): { migration: CodeMigration; calls: boolean[] } => { |
| 35 | const calls: boolean[] = []; |
no test coverage detected