-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add more types unit tests (#1043)
- Loading branch information
1 parent
e9ca60c
commit 0b5b964
Showing
10 changed files
with
317 additions
and
10 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,55 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { PgType } from '../../../src'; | ||
import { addTypeAttribute } from '../../../src/operations/types'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('types', () => { | ||
describe('addTypeAttribute', () => { | ||
const addTypeAttributeFn = addTypeAttribute(options1); | ||
|
||
it('should return a function', () => { | ||
expect(addTypeAttributeFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = addTypeAttributeFn('compfoo', 'f3', PgType.INT); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "compfoo" ADD ATTRIBUTE "f3" integer;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = addTypeAttributeFn( | ||
{ name: 'compfoo', schema: 'myschema' }, | ||
'f3', | ||
'int' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "myschema"."compfoo" ADD ATTRIBUTE "f3" integer;' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(addTypeAttributeFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = addTypeAttributeFn.reverse( | ||
'compfoo', | ||
'f3', | ||
PgType.INT | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('ALTER TYPE "compfoo" DROP ATTRIBUTE "f3";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,69 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { addTypeValue } from '../../../src/operations/types'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('types', () => { | ||
describe('addTypeValue', () => { | ||
const addTypeValueFn = addTypeValue(options1); | ||
|
||
it('should return a function', () => { | ||
expect(addTypeValueFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = addTypeValueFn('colors', 'purple'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "colors" ADD VALUE $pga$purple$pga$;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with typeValueOptions', () => { | ||
const statement = addTypeValueFn('colors', 'purple', { | ||
after: 'red', | ||
ifNotExists: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "colors" ADD VALUE IF NOT EXISTS $pga$purple$pga$ AFTER $pga$red$pga$;' | ||
); | ||
|
||
const statement2 = addTypeValueFn('colors', 'purple', { | ||
before: 'yellow', | ||
ifNotExists: true, | ||
}); | ||
|
||
expect(statement2).toBeTypeOf('string'); | ||
expect(statement2).toBe( | ||
'ALTER TYPE "colors" ADD VALUE IF NOT EXISTS $pga$purple$pga$ BEFORE $pga$yellow$pga$;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = addTypeValueFn( | ||
{ name: 'colors', schema: 'myschema' }, | ||
'purple' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "myschema"."colors" ADD VALUE $pga$purple$pga$;' | ||
); | ||
}); | ||
|
||
it('should throw when before and after are specified together', () => { | ||
expect(() => | ||
addTypeValueFn('colors', 'purple', { | ||
before: 'blue', | ||
after: 'red', | ||
}) | ||
).toThrow( | ||
new Error('"before" and "after" 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { dropTypeAttribute } from '../../../src/operations/types'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('types', () => { | ||
describe('dropTypeAttribute', () => { | ||
const dropTypeAttributeFn = dropTypeAttribute(options1); | ||
|
||
it('should return a function', () => { | ||
expect(dropTypeAttributeFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = dropTypeAttributeFn('compfoo', 'bar', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('ALTER TYPE "compfoo" DROP ATTRIBUTE "bar";'); | ||
}); | ||
|
||
it('should return sql statement with dropOptions', () => { | ||
const statement = dropTypeAttributeFn('compfoo', 'bar', { | ||
ifExists: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "compfoo" DROP ATTRIBUTE "bar" IF EXISTS;' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renameTypeAttribute } from '../../../src/operations/types'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('types', () => { | ||
describe('renameTypeAttribute', () => { | ||
const renameTypeAttributeFn = renameTypeAttribute(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renameTypeAttributeFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameTypeAttributeFn('compfoo', 'f3', 'f4'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "compfoo" RENAME ATTRIBUTE "f3" TO "f4";' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renameTypeAttributeFn( | ||
{ name: 'compfoo', schema: 'myschema' }, | ||
'f3', | ||
'f4' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "myschema"."compfoo" RENAME ATTRIBUTE "f3" TO "f4";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renameTypeAttributeFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameTypeAttributeFn.reverse( | ||
'compfoo', | ||
'f3', | ||
'f4' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "compfoo" RENAME ATTRIBUTE "f4" TO "f3";' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,56 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renameTypeValue } from '../../../src/operations/types'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('types', () => { | ||
describe('renameTypeValue', () => { | ||
const renameTypeValueFn = renameTypeValue(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renameTypeValueFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameTypeValueFn('colors', 'purple', 'mauve'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "colors" RENAME VALUE $pga$purple$pga$ TO $pga$mauve$pga$;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renameTypeValueFn( | ||
{ name: 'colors', schema: 'myschema' }, | ||
'purple', | ||
'mauve' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "myschema"."colors" RENAME VALUE $pga$purple$pga$ TO $pga$mauve$pga$;' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renameTypeValueFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameTypeValueFn.reverse( | ||
'colors', | ||
'purple', | ||
'mauve' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "colors" RENAME VALUE $pga$mauve$pga$ TO $pga$purple$pga$;' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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 { PgType } from '../../../src'; | ||
import { setTypeAttribute } from '../../../src/operations/types'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('types', () => { | ||
describe('setTypeAttribute', () => { | ||
const setTypeAttributeFn = setTypeAttribute(options1); | ||
|
||
it('should return a function', () => { | ||
expect(setTypeAttributeFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = setTypeAttributeFn('compfoo', 'f3', PgType.INT); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "compfoo" ALTER ATTRIBUTE "f3" SET DATA TYPE integer;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = setTypeAttributeFn( | ||
{ name: 'compfoo', schema: 'myschema' }, | ||
'f3', | ||
'int' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER TYPE "myschema"."compfoo" ALTER ATTRIBUTE "f3" SET DATA TYPE integer;' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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