Skip to content

Commit

Permalink
♻️ Add createParserTestCases function and update parser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FunamaYukina committed Jan 27, 2025
1 parent 2fe62a6 commit 3b96968
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 174 deletions.
6 changes: 6 additions & 0 deletions .changeset/nice-starfishes-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/db-structure": patch
"@liam-hq/cli": patch
---

♻️ Add createParserTestCases function and update parser tests
69 changes: 24 additions & 45 deletions frontend/packages/db-structure/src/parser/__tests__/testcase.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
import {
type Table,
aColumn,
aDBStructure,
aTable,
type aDBStructure,
anIndex,
} from '../../schema/index.js'

const userTable = (override?: Partial<Table>) =>
aDBStructure({
tables: {
users: aTable({
name: 'users',
columns: {
id: aColumn({
name: 'id',
type: 'bigserial',
notNull: true,
primary: true,
unique: true,
}),
...override?.columns,
},
indices: {
...override?.indices,
},
comment: override?.comment ?? null,
}),
},
})

export const parserTestCases = {
export const createParserTestCases = (
userTable: (override?: Partial<Table>) => ReturnType<typeof aDBStructure>,
) => ({
'table comment': userTable({
comment: 'store our users.',
}),
Expand Down Expand Up @@ -96,20 +74,21 @@ export const parserTestCases = {
}),
},
}),
'index (unique: false)': userTable({
columns: {
email: aColumn({
name: 'email',
}),
},
indices: {
index_users_on_id_and_email: anIndex({
name: 'index_users_on_id_and_email',
unique: false,
columns: ['id', 'email'],
}),
},
}),
'index (unique: false)': (indexName: string) =>
userTable({
columns: {
email: aColumn({
name: 'email',
}),
},
indices: {
[indexName]: anIndex({
name: indexName,
unique: false,
columns: ['id', 'email'],
}),
},
}),
'index (unique: true)': userTable({
columns: {
email: aColumn({
Expand All @@ -136,9 +115,9 @@ export const parserTestCases = {
deleteConstraint: 'NO_ACTION',
},
}),
'foreign key (one-to-one)': {
users_id_to_posts_user_id: {
name: 'users_id_to_posts_user_id',
'foreign key (one-to-one)': (name: string) => ({
[name]: {
name,
primaryTableName: 'users',
primaryColumnName: 'id',
foreignTableName: 'posts',
Expand All @@ -147,7 +126,7 @@ export const parserTestCases = {
updateConstraint: 'NO_ACTION',
deleteConstraint: 'NO_ACTION',
},
},
}),
'foreign key with action': {
fk_posts_user_id: {
name: 'fk_posts_user_id',
Expand All @@ -160,4 +139,4 @@ export const parserTestCases = {
deleteConstraint: 'CASCADE',
},
},
}
})
Loading

0 comments on commit 3b96968

Please sign in to comment.