diff --git a/test/operations/domains/alterDomain.spec.ts b/test/operations/domains/alterDomain.spec.ts index b38bfcee..c71e11a0 100644 --- a/test/operations/domains/alterDomain.spec.ts +++ b/test/operations/domains/alterDomain.spec.ts @@ -3,72 +3,74 @@ import { alterDomain } from '../../../src/operations/domains'; import { options1 } from '../../utils'; describe('operations', () => { - describe('alterDomain', () => { - const alterDomainFn = alterDomain(options1); + describe('domains', () => { + describe('alterDomain', () => { + const alterDomainFn = alterDomain(options1); - it('should return a function', () => { - expect(alterDomainFn).toBeTypeOf('function'); - }); - - it('should return sql statement with domainOptions default', () => { - const statement = alterDomainFn('zipcode', { - default: '12345', + it('should return a function', () => { + expect(alterDomainFn).toBeTypeOf('function'); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe( - 'ALTER DOMAIN "zipcode" SET DEFAULT $pga$12345$pga$;' - ); - }); + it('should return sql statement with domainOptions default', () => { + const statement = alterDomainFn('zipcode', { + default: '12345', + }); - it('should return sql statement with domainOptions default null', () => { - const statement = alterDomainFn('zipcode', { - default: null, + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'ALTER DOMAIN "zipcode" SET DEFAULT $pga$12345$pga$;' + ); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('ALTER DOMAIN "zipcode" DROP DEFAULT;'); - }); + it('should return sql statement with domainOptions default null', () => { + const statement = alterDomainFn('zipcode', { + default: null, + }); - it('should return sql statement with domainOptions notNull', () => { - const statement = alterDomainFn('zipcode', { - notNull: true, + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('ALTER DOMAIN "zipcode" DROP DEFAULT;'); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('ALTER DOMAIN "zipcode" SET NOT NULL;'); - }); + it('should return sql statement with domainOptions notNull', () => { + const statement = alterDomainFn('zipcode', { + notNull: true, + }); - it('should return sql statement with domainOptions allowNull', () => { - const statement = alterDomainFn('zipcode', { - allowNull: true, + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('ALTER DOMAIN "zipcode" SET NOT NULL;'); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('ALTER DOMAIN "zipcode" DROP NOT NULL;'); - }); + it('should return sql statement with domainOptions allowNull', () => { + const statement = alterDomainFn('zipcode', { + allowNull: true, + }); - it('should return sql statement with domainOptions check', () => { - const statement = alterDomainFn('zipcode', { - check: 'char_length(VALUE) = 5', + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('ALTER DOMAIN "zipcode" DROP NOT NULL;'); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe( - 'ALTER DOMAIN "zipcode" CHECK (char_length(VALUE) = 5);' - ); - }); + it('should return sql statement with domainOptions check', () => { + const statement = alterDomainFn('zipcode', { + check: 'char_length(VALUE) = 5', + }); - it('should return sql statement with domainOptions check and constraintName', () => { - const statement = alterDomainFn('zipcode', { - check: 'char_length(VALUE) = 5', - constraintName: 'zipchk', + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'ALTER DOMAIN "zipcode" CHECK (char_length(VALUE) = 5);' + ); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe( - 'ALTER DOMAIN "zipcode" CONSTRAINT "zipchk" CHECK (char_length(VALUE) = 5);' - ); + it('should return sql statement with domainOptions check and constraintName', () => { + const statement = alterDomainFn('zipcode', { + check: 'char_length(VALUE) = 5', + constraintName: 'zipchk', + }); + + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'ALTER DOMAIN "zipcode" CONSTRAINT "zipchk" CHECK (char_length(VALUE) = 5);' + ); + }); }); }); }); diff --git a/test/operations/domains/createDomain.spec.ts b/test/operations/domains/createDomain.spec.ts index eb387453..475c10f4 100644 --- a/test/operations/domains/createDomain.spec.ts +++ b/test/operations/domains/createDomain.spec.ts @@ -4,95 +4,97 @@ import { createDomain } from '../../../src/operations/domains'; import { options1 } from '../../utils'; describe('operations', () => { - describe('createDomain', () => { - const createDomainFn = createDomain(options1); + describe('domains', () => { + describe('createDomain', () => { + const createDomainFn = createDomain(options1); - it('should return a function', () => { - expect(createDomainFn).toBeTypeOf('function'); - }); - - it('should return sql statement with string', () => { - const statement = createDomainFn('us_postal_code', 'TEXT'); + it('should return a function', () => { + expect(createDomainFn).toBeTypeOf('function'); + }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('CREATE DOMAIN "us_postal_code" AS TEXT;'); - }); + it('should return sql statement with string', () => { + const statement = createDomainFn('us_postal_code', 'TEXT'); - it('should return sql statement with PgType', () => { - const statement = createDomainFn('us_postal_code', PgType.TEXT); + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('CREATE DOMAIN "us_postal_code" AS TEXT;'); + }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('CREATE DOMAIN "us_postal_code" AS text;'); - }); + it('should return sql statement with PgType', () => { + const statement = createDomainFn('us_postal_code', PgType.TEXT); - it('should return sql statement with schema', () => { - const statement = createDomainFn( - { schema: 'myschema', name: 'us_postal_code' }, - 'TEXT' - ); + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('CREATE DOMAIN "us_postal_code" AS text;'); + }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe( - 'CREATE DOMAIN "myschema"."us_postal_code" AS TEXT;' - ); - }); + it('should return sql statement with schema', () => { + const statement = createDomainFn( + { schema: 'myschema', name: 'us_postal_code' }, + 'TEXT' + ); - it('should return sql statement with domainOptions collation and default', () => { - const statement = createDomainFn('us_postal_code', 'TEXT', { - collation: 'en_US', - default: '12345', + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'CREATE DOMAIN "myschema"."us_postal_code" AS TEXT;' + ); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe( - 'CREATE DOMAIN "us_postal_code" AS TEXT COLLATE en_US DEFAULT $pga$12345$pga$;' - ); - }); + it('should return sql statement with domainOptions collation and default', () => { + const statement = createDomainFn('us_postal_code', 'TEXT', { + collation: 'en_US', + default: '12345', + }); - it('should return sql statement with domainOptions check', () => { - const statement = createDomainFn('us_postal_code', 'TEXT', { - check: "VALUE ~ '^d{5}$'", + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'CREATE DOMAIN "us_postal_code" AS TEXT COLLATE en_US DEFAULT $pga$12345$pga$;' + ); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe( - 'CREATE DOMAIN "us_postal_code" AS TEXT CHECK (VALUE ~ \'^d{5}$\');' - ); - }); + it('should return sql statement with domainOptions check', () => { + const statement = createDomainFn('us_postal_code', 'TEXT', { + check: "VALUE ~ '^d{5}$'", + }); - it('should return sql statement with domainOptions constraintName and notNull', () => { - const statement = createDomainFn('us_postal_code', 'TEXT', { - constraintName: 'us_postal_code_check', - notNull: true, + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'CREATE DOMAIN "us_postal_code" AS TEXT CHECK (VALUE ~ \'^d{5}$\');' + ); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe( - 'CREATE DOMAIN "us_postal_code" AS TEXT CONSTRAINT "us_postal_code_check" NOT NULL;' - ); - }); - - it('should throw when notNull and check are passed', () => { - expect(() => - createDomainFn('us_postal_code', 'TEXT', { - check: "VALUE ~ '^d{5}$'", + it('should return sql statement with domainOptions constraintName and notNull', () => { + const statement = createDomainFn('us_postal_code', 'TEXT', { + constraintName: 'us_postal_code_check', notNull: true, - }) - ).toThrow( - new Error('"notNull" and "check" can\'t be specified together') - ); - }); + }); + + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'CREATE DOMAIN "us_postal_code" AS TEXT CONSTRAINT "us_postal_code_check" NOT NULL;' + ); + }); - describe('reverse', () => { - it('should contain a reverse function', () => { - expect(createDomainFn.reverse).toBeTypeOf('function'); + it('should throw when notNull and check are passed', () => { + expect(() => + createDomainFn('us_postal_code', 'TEXT', { + check: "VALUE ~ '^d{5}$'", + notNull: true, + }) + ).toThrow( + new Error('"notNull" and "check" can\'t be specified together') + ); }); - it('should return sql statement', () => { - const statement = createDomainFn.reverse('us_postal_code', 'TEXT'); + describe('reverse', () => { + it('should contain a reverse function', () => { + expect(createDomainFn.reverse).toBeTypeOf('function'); + }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('DROP DOMAIN "us_postal_code";'); + it('should return sql statement', () => { + const statement = createDomainFn.reverse('us_postal_code', 'TEXT'); + + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('DROP DOMAIN "us_postal_code";'); + }); }); }); }); diff --git a/test/operations/domains/dropDomain.spec.ts b/test/operations/domains/dropDomain.spec.ts index 3d5a0e75..a86ad972 100644 --- a/test/operations/domains/dropDomain.spec.ts +++ b/test/operations/domains/dropDomain.spec.ts @@ -3,38 +3,42 @@ import { dropDomain } from '../../../src/operations/domains'; import { options1 } from '../../utils'; describe('operations', () => { - describe('dropDomain', () => { - const dropDomainFn = dropDomain(options1); + describe('domains', () => { + describe('dropDomain', () => { + const dropDomainFn = dropDomain(options1); - it('should return a function', () => { - expect(dropDomainFn).toBeTypeOf('function'); - }); - - it('should return sql statement', () => { - const statement = dropDomainFn('us_postal_code'); + it('should return a function', () => { + expect(dropDomainFn).toBeTypeOf('function'); + }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('DROP DOMAIN "us_postal_code";'); - }); + it('should return sql statement', () => { + const statement = dropDomainFn('us_postal_code'); - it('should return sql statement with dropOptions', () => { - const statement = dropDomainFn('us_postal_code', { - ifExists: true, - cascade: true, + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('DROP DOMAIN "us_postal_code";'); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('DROP DOMAIN IF EXISTS "us_postal_code" CASCADE;'); - }); + it('should return sql statement with dropOptions', () => { + const statement = dropDomainFn('us_postal_code', { + ifExists: true, + cascade: true, + }); - it('should return sql statement with schema', () => { - const statement = dropDomainFn({ - schema: 'myschema', - name: 'us_postal_code', + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'DROP DOMAIN IF EXISTS "us_postal_code" CASCADE;' + ); }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('DROP DOMAIN "myschema"."us_postal_code";'); + it('should return sql statement with schema', () => { + const statement = dropDomainFn({ + schema: 'myschema', + name: 'us_postal_code', + }); + + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('DROP DOMAIN "myschema"."us_postal_code";'); + }); }); }); }); diff --git a/test/operations/domains/renameDomain.spec.ts b/test/operations/domains/renameDomain.spec.ts index 7b8509c6..9296edd3 100644 --- a/test/operations/domains/renameDomain.spec.ts +++ b/test/operations/domains/renameDomain.spec.ts @@ -3,30 +3,34 @@ import { renameDomain } from '../../../src/operations/domains'; import { options1 } from '../../utils'; describe('operations', () => { - describe('renameDomain', () => { - const renameDomainFn = renameDomain(options1); + describe('domains', () => { + describe('renameDomain', () => { + const renameDomainFn = renameDomain(options1); - it('should return a function', () => { - expect(renameDomainFn).toBeTypeOf('function'); - }); - - it('should return sql statement with domainOptions default', () => { - const statement = renameDomainFn('zipcode', 'zip_code'); + it('should return a function', () => { + expect(renameDomainFn).toBeTypeOf('function'); + }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('ALTER DOMAIN "zipcode" RENAME TO "zip_code";'); - }); + it('should return sql statement with domainOptions default', () => { + const statement = renameDomainFn('zipcode', 'zip_code'); - describe('reverse', () => { - it('should contain a reverse function', () => { - expect(renameDomainFn.reverse).toBeTypeOf('function'); + expect(statement).toBeTypeOf('string'); + expect(statement).toBe('ALTER DOMAIN "zipcode" RENAME TO "zip_code";'); }); - it('should return sql statement', () => { - const statement = renameDomainFn.reverse('zipcode', 'zip_code'); + describe('reverse', () => { + it('should contain a reverse function', () => { + expect(renameDomainFn.reverse).toBeTypeOf('function'); + }); - expect(statement).toBeTypeOf('string'); - expect(statement).toBe('ALTER DOMAIN "zip_code" RENAME TO "zipcode";'); + it('should return sql statement', () => { + const statement = renameDomainFn.reverse('zipcode', 'zip_code'); + + expect(statement).toBeTypeOf('string'); + expect(statement).toBe( + 'ALTER DOMAIN "zip_code" RENAME TO "zipcode";' + ); + }); }); }); });