Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: indent domains tests #1010

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 50 additions & 48 deletions test/operations/domains/alterDomain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);'
);
});
});
});
});
140 changes: 71 additions & 69 deletions test/operations/domains/createDomain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";');
});
});
});
});
Expand Down
52 changes: 28 additions & 24 deletions test/operations/domains/dropDomain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";');
});
});
});
});
Loading