Skip to content

Commit

Permalink
test: add schemas unit tests (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Mar 11, 2024
1 parent 3a631b0 commit a5b2f36
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/operations/schemas/createSchema.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, expect, it } from 'vitest';
import { createSchema } from '../../../src/operations/schemas';
import { options1 } from '../../utils';

describe('operations', () => {
describe('schemas', () => {
describe('createSchema', () => {
const createSchemaFn = createSchema(options1);

it('should return a function', () => {
expect(createSchemaFn).toBeTypeOf('function');
});

it('should return sql statement', () => {
const statement = createSchemaFn('myschema');

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual('CREATE SCHEMA "myschema";');
});

it('should return sql statement with schemaOptions', () => {
const statement = createSchemaFn('test', {
ifNotExists: true,
authorization: 'joe',
});

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual(
'CREATE SCHEMA IF NOT EXISTS "test" AUTHORIZATION joe;'
);
});

describe('reverse', () => {
it('should contain a reverse function', () => {
expect(createSchemaFn.reverse).toBeTypeOf('function');
});

it('should return sql statement', () => {
const statement = createSchemaFn.reverse('myschema');

expect(statement).toBeTypeOf('string');
expect(statement).toBe('DROP SCHEMA "myschema";');
});
});
});
});
});
34 changes: 34 additions & 0 deletions test/operations/schemas/dropPolicy.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest';
import { dropSchema } from '../../../src/operations/schemas';
import { options1 } from '../../utils';

describe('operations', () => {
describe('schemas', () => {
describe('dropSchema', () => {
const dropSchemaFn = dropSchema(options1);

it('should return a function', () => {
expect(dropSchemaFn).toBeTypeOf('function');
});

it('should return sql statement', () => {
const statement = dropSchemaFn('mystuff');

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual('DROP SCHEMA "mystuff";');
});

it('should return sql statement with dropOptions', () => {
const statement = dropSchemaFn('mystuff', {
ifExists: true,
cascade: true,
});

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual(
'DROP SCHEMA IF EXISTS "mystuff" CASCADE;'
);
});
});
});
});
37 changes: 37 additions & 0 deletions test/operations/schemas/renameSchema.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, expect, it } from 'vitest';
import { renameSchema } from '../../../src/operations/schemas';
import { options1 } from '../../utils';

describe('operations', () => {
describe('schemas', () => {
describe('renameSchema', () => {
const renameSchemaFn = renameSchema(options1);

it('should return a function', () => {
expect(renameSchemaFn).toBeTypeOf('function');
});

it('should return sql statement', () => {
const statement = renameSchemaFn('test', 'myschema');

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual(
'ALTER SCHEMA "test" RENAME TO "myschema";'
);
});

describe('reverse', () => {
it('should contain a reverse function', () => {
expect(renameSchemaFn.reverse).toBeTypeOf('function');
});

it('should return sql statement', () => {
const statement = renameSchemaFn.reverse('test', 'myschema');

expect(statement).toBeTypeOf('string');
expect(statement).toBe('ALTER SCHEMA "myschema" RENAME TO "test";');
});
});
});
});
});

0 comments on commit a5b2f36

Please sign in to comment.