-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d62a769
commit 84fb4bb
Showing
4 changed files
with
210 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { alterTable } from '../../../src/operations/tables'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('tables', () => { | ||
describe('alterTable', () => { | ||
const alterTableFn = alterTable(options1); | ||
|
||
it('should return a function', () => { | ||
expect(alterTableFn).toBeTypeOf('function'); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-03-11: This should throw an error | ||
it('should return sql statement', () => { | ||
const statement = alterTableFn( | ||
'films', | ||
// @ts-expect-error: add runtime error | ||
{} | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual(`ALTER TABLE "films" | ||
;`); | ||
}); | ||
|
||
it('should return sql statement with tableOptions', () => { | ||
const statement = alterTableFn('distributors', { | ||
levelSecurity: 'ENABLE', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual(`ALTER TABLE "distributors" | ||
ENABLE ROW LEVEL SECURITY;`); | ||
}); | ||
}); | ||
}); | ||
}); |
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,87 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { PgType } from '../../../src'; | ||
import { createTable } from '../../../src/operations/tables'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('tables', () => { | ||
describe('createTable', () => { | ||
const createTableFn = createTable(options1); | ||
|
||
it('should return a function', () => { | ||
expect(createTableFn).toBeTypeOf('function'); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-03-12: This should throw an error when columns are empty | ||
it('should return sql statement', () => { | ||
const statement = createTableFn('films', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual('CREATE TABLE "films" (\n \n);'); | ||
}); | ||
|
||
it('should return sql statement with tableOptions', () => { | ||
const statement = createTableFn('films', { | ||
code: { | ||
type: 'char(5)', | ||
primaryKey: true, | ||
}, | ||
title: { | ||
type: 'varchar(40)', | ||
notNull: true, | ||
}, | ||
did: { | ||
type: PgType.INTEGER, | ||
notNull: true, | ||
}, | ||
date_prod: PgType.DATE, | ||
kind: 'varchar(10)', | ||
len: { | ||
type: 'interval hour to minute', | ||
}, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
`CREATE TABLE "films" ( | ||
"code" char(5) PRIMARY KEY, | ||
"title" varchar(40) NOT NULL, | ||
"did" integer NOT NULL, | ||
"date_prod" date, | ||
"kind" varchar(10), | ||
"len" interval hour to minute | ||
);` | ||
); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-03-12: This should throw an error when columns are empty | ||
it('should return sql statement with schema', () => { | ||
const statement = createTableFn( | ||
{ | ||
name: 'films', | ||
schema: 'myschema', | ||
}, | ||
{} | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE TABLE "myschema"."films" (\n \n);' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(createTableFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createTableFn.reverse('films', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP TABLE "films";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,34 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { dropTable } from '../../../src/operations/tables'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('tables', () => { | ||
describe('dropTable', () => { | ||
const dropTableFn = dropTable(options1); | ||
|
||
it('should return a function', () => { | ||
expect(dropTableFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = dropTableFn('films'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual('DROP TABLE "films";'); | ||
}); | ||
|
||
it('should return sql statement with dropOptions', () => { | ||
const statement = dropTableFn('films', { | ||
ifExists: true, | ||
cascade: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'DROP TABLE IF EXISTS "films" CASCADE;' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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,51 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renameTable } from '../../../src/operations/tables'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('tables', () => { | ||
describe('renameTable', () => { | ||
const renameTableFn = renameTable(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renameTableFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameTableFn('distributors', 'suppliers'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER TABLE "distributors" RENAME TO "suppliers";' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renameTableFn( | ||
{ name: 'distributors', schema: 'myschema' }, | ||
{ name: 'suppliers', schema: 'myschema' } | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER TABLE "myschema"."distributors" RENAME TO "myschema"."suppliers";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renameTableFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameTableFn.reverse('distributors', 'suppliers'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TABLE "suppliers" RENAME TO "distributors";' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |