|
1 | 1 | import { describe, test, expect } from 'bun:test'; |
2 | | -import { generateTableQuery, generateSelectQuery, shouldRefreshSchema, quoteIdentifier } from '@/lib/query-generators'; |
| 2 | +import { generateTableQuery, generateSelectQuery, shouldRefreshSchema, quoteIdentifier, quoteQualifiedName } from '@/lib/query-generators'; |
3 | 3 | import type { ProviderCapabilities } from '@/lib/db/types'; |
4 | 4 | import type { ColumnSchema } from '@/lib/types'; |
5 | 5 |
|
@@ -153,6 +153,24 @@ describe('quoteIdentifier', () => { |
153 | 153 | .toBe('SELECT * FROM "Customer" LIMIT 50;'); |
154 | 154 | }); |
155 | 155 |
|
| 156 | + test('schema-qualified names are quoted per-segment, not as one identifier', () => { |
| 157 | + // lowercase schema.table → no quotes (Postgres) |
| 158 | + expect(quoteQualifiedName('employees.department', makeCaps({ defaultPort: 5432 }))) |
| 159 | + .toBe('employees.department'); |
| 160 | + // mixed-case table in a schema → only the table segment is quoted |
| 161 | + expect(quoteQualifiedName('public.Order', makeCaps({ defaultPort: 5432 }))) |
| 162 | + .toBe('public."Order"'); |
| 163 | + // bare name (no dot) is unchanged |
| 164 | + expect(quoteQualifiedName('Customer', makeCaps({ defaultPort: 5432 }))) |
| 165 | + .toBe('"Customer"'); |
| 166 | + }); |
| 167 | + |
| 168 | + test('generateTableQuery on a schema-qualified table does NOT wrap the dot (regression)', () => { |
| 169 | + // Was producing the broken `"employees.department"`; must be `employees.department`. |
| 170 | + expect(generateTableQuery('employees.department', makeCaps({ defaultPort: 5432 }))) |
| 171 | + .toBe('SELECT * FROM employees.department LIMIT 50;'); |
| 172 | + }); |
| 173 | + |
156 | 174 | test('generateSelectQuery quotes mixed-case table and columns (Postgres)', () => { |
157 | 175 | const cols: ColumnSchema[] = [ |
158 | 176 | { name: 'Id', type: 'integer', nullable: false, isPrimary: true }, |
|
0 commit comments