schema-export.test.ts38 lines · main
1import { describe, expect, it } from 'bun:test';
2
3import { exportSchemaToDsl } from './schema-export.js';
4
5describe('exportSchemaToDsl', () => {
6 it('emits a minimal blank table', () => {
7 const dsl = exportSchemaToDsl({
8 tables: [
9 {
10 name: 'notes',
11 columns: [
12 { name: 'id', sqlType: 'text', nullable: false, primaryKey: true },
13 { name: 'body', sqlType: 'text', nullable: false, primaryKey: false },
14 ],
15 },
16 ],
17 });
18 expect(dsl).toContain("from '@briven/cli/schema'");
19 expect(dsl).toContain('notes: table({');
20 expect(dsl).toContain('id: text().primaryKey(),');
21 expect(dsl).toContain('body: text().notNull(),');
22 });
23
24 it('marks unknown postgres types with a TODO comment', () => {
25 const dsl = exportSchemaToDsl({
26 tables: [
27 {
28 name: 'odd',
29 columns: [
30 { name: 'id', sqlType: 'text', nullable: false, primaryKey: true },
31 { name: 'data', sqlType: 'tsvector', nullable: true, primaryKey: false },
32 ],
33 },
34 ],
35 });
36 expect(dsl).toContain("// TODO: unsupported type 'tsvector' — confirm");
37 });
38});