import { describe, expect, test } from 'vitest'; import { PgTable, PgType } from '../../abstractions'; import { PkColumn } from './pk-column'; interface PkColumnTestInput { type: PgType; expectedExpression: string; } const dummyTable: PgTable = {} as PgTable; const testData: [string, PkColumnTestInput][] = [ [ 'PK with TEXT type', { type: 'TEXT', expectedExpression: 'id TEXT PRIMARY KEY' }, ], [ 'PK with INTEGER type', { type: 'INTEGER', expectedExpression: 'id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY', }, ], ]; describe('PkColumn', () => { test.each(testData)( '%s', (_description: string, input: PkColumnTestInput) => { // Arrange const pkColumn = new PkColumn(dummyTable, input.type); // Act & Assert expect(pkColumn.buildExpression()).toBe(input.expectedExpression); }, ); test('PK column with unsupported type throws', () => { // Arrange const unsupportedType: PgType = 'BOOLEAN'; // Act const action = (): void => { new PkColumn(dummyTable, unsupportedType); }; // Assert expect(action).toThrow(TypeError); }); });