-
Notifications
You must be signed in to change notification settings - Fork 168
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
f5528f2
commit acaf6d7
Showing
5 changed files
with
267 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,67 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { alterView } from '../../../src/operations/views'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('views', () => { | ||
describe('alterView', () => { | ||
const alterViewFn = alterView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(alterViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-03-09: This should throw an error | ||
it('should return sql statement', () => { | ||
const statement = alterViewFn('a_view', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toHaveLength(0); | ||
}); | ||
|
||
it('should return sql statement with viewOptions', () => { | ||
const statement = alterViewFn('a_view', { | ||
checkOption: 'LOCAL', | ||
options: { | ||
classification: 'PG', | ||
}, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER VIEW "a_view" SET (classification = PG, check_option = LOCAL);' | ||
); | ||
}); | ||
|
||
it('should return sql statement with options containing null value', () => { | ||
const statement = alterViewFn('a_view', { | ||
checkOption: 'LOCAL', | ||
options: { | ||
classification: null, | ||
}, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
`ALTER VIEW "a_view" SET (check_option = LOCAL); | ||
ALTER VIEW "a_view" RESET (classification);` | ||
); | ||
}); | ||
|
||
it('should throw error on duplicate checkOption', () => { | ||
expect(() => | ||
alterViewFn('a_view', { | ||
checkOption: 'LOCAL', | ||
options: { | ||
check_option: 'CASCADED', | ||
}, | ||
}) | ||
).toThrow( | ||
new Error( | ||
'"options.check_option" and "checkOption" can\'t be specified together' | ||
) | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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,44 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { alterViewColumn } from '../../../src/operations/views'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('views', () => { | ||
describe('alterViewColumn', () => { | ||
const alterViewColumnFn = alterViewColumn(options1); | ||
|
||
it('should return a function', () => { | ||
expect(alterViewColumnFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = alterViewColumnFn('a_view', 'ts', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toHaveLength(0); | ||
}); | ||
|
||
it('should return sql statement with viewColumnOptions', () => { | ||
const statement = alterViewColumnFn('a_view', 'ts', { | ||
default: 'now()', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER VIEW "a_view" ALTER COLUMN "ts" SET DEFAULT $pga$now()$pga$;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with viewColumnOptions drop default', () => { | ||
const statement = alterViewColumnFn('a_view', 'ts', { | ||
default: null, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER VIEW "a_view" ALTER COLUMN "ts" DROP DEFAULT;' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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,77 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createView } from '../../../src/operations/views'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('views', () => { | ||
describe('createView', () => { | ||
const createViewFn = createView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(createViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-03-20: This should throw an error | ||
it.todo('should return sql statement', () => { | ||
const statement = createViewFn('comedies', {}, ''); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('CREATE VIEW "comedies" AS ;'); | ||
}); | ||
|
||
it('should return sql statement with viewOptions', () => { | ||
const statement = createViewFn( | ||
'comedies', | ||
{ | ||
ifExists: true, | ||
cascade: true, | ||
replace: true, | ||
recursive: true, | ||
columns: ['column1', 'column2'], | ||
options: { | ||
classification: 'PG', | ||
}, | ||
checkOption: 'LOCAL', | ||
temporary: true, | ||
}, | ||
"SELECT * FROM films WHERE kind = 'Comedy'" | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'CREATE OR REPLACE TEMPORARY RECURSIVE VIEW "comedies"("column1", "column2") WITH (classification = PG) AS SELECT * FROM films WHERE kind = \'Comedy\' WITH LOCAL CHECK OPTION;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = createViewFn( | ||
{ name: 'comedies', schema: 'myschema' }, | ||
{}, | ||
"SELECT * FROM films WHERE kind = 'Comedy'" | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'CREATE VIEW "myschema"."comedies" AS SELECT * FROM films WHERE kind = \'Comedy\';' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(createViewFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createViewFn.reverse( | ||
'comedies', | ||
{}, | ||
"SELECT * FROM films WHERE kind = 'Comedy'" | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP VIEW "comedies";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,32 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { dropView } from '../../../src/operations/views'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('views', () => { | ||
describe('dropView', () => { | ||
const dropViewFn = dropView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(dropViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = dropViewFn('kinds'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP VIEW "kinds";'); | ||
}); | ||
|
||
it('should return sql statement with dropOptions', () => { | ||
const statement = dropViewFn('kinds', { | ||
ifExists: true, | ||
cascade: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP VIEW IF EXISTS "kinds" 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,47 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renameView } from '../../../src/operations/views'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('views', () => { | ||
describe('renameView', () => { | ||
const renameViewFn = renameView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renameViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameViewFn('foo', 'bar'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('ALTER VIEW "foo" RENAME TO "bar";'); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renameViewFn( | ||
{ name: 'foo', schema: 'myschema' }, | ||
{ name: 'bar', schema: 'myschema' } | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER VIEW "myschema"."foo" RENAME TO "myschema"."bar";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renameViewFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameViewFn.reverse('foo', 'bar'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('ALTER VIEW "bar" RENAME TO "foo";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |