-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from liam-hq/enhance-postgres-parser-test
Enhance postgres parser test
- Loading branch information
Showing
3 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
frontend/packages/db-structure/src/parser/sql/postgresql/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import type { Table } from 'src/schema' | ||
import { aColumn, aDBStructure, aTable } from 'src/schema/factories' | ||
import { describe, expect, it } from 'vitest' | ||
import { processor } from '.' | ||
|
||
describe(processor, () => { | ||
describe('should parse create_table correctry', () => { | ||
const userTable = (override?: Partial<Table>) => | ||
aDBStructure({ | ||
tables: { | ||
users: aTable({ | ||
name: 'users', | ||
columns: { | ||
id: aColumn({ | ||
name: 'id', | ||
type: 'serial', | ||
notNull: true, | ||
primary: true, | ||
}), | ||
...override?.columns, | ||
}, | ||
}), | ||
}, | ||
}) | ||
|
||
it('not null', () => { | ||
const result = processor(/* PostgreSQL */ ` | ||
CREATE TABLE users ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL | ||
); | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
name: aColumn({ | ||
name: 'name', | ||
type: 'varchar', | ||
notNull: true, | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
it('nullable', () => { | ||
const result = processor(/* PostgreSQL */ ` | ||
CREATE TABLE users ( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) | ||
); | ||
`) | ||
|
||
const expected = userTable({ | ||
columns: { | ||
name: aColumn({ | ||
name: 'name', | ||
type: 'varchar', | ||
notNull: false, | ||
}), | ||
}, | ||
}) | ||
|
||
expect(result).toEqual(expected) | ||
}) | ||
|
||
// TODO: Implement default value | ||
}) | ||
}) |