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: add extensions unit tests #1009

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
44 changes: 44 additions & 0 deletions test/operations/extensions/createExtension.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it } from 'vitest';
import { createExtension } from '../../../src/operations/extensions';
import { options1 } from '../../utils';

describe('operations', () => {
describe('extensions', () => {
describe('createExtension', () => {
const createExtensionFn = createExtension(options1);

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

it('should return sql statement', () => {
const statement = createExtensionFn('hstore');

expect(statement).toBeTypeOf('object');
expect(statement).toStrictEqual(['CREATE EXTENSION "hstore";']);
});

it('should return sql statement with dropOptions', () => {
const statement = createExtensionFn('hstore', {
ifNotExists: true,
schema: 'my_schema',
});

expect(statement).toBeTypeOf('object');
expect(statement).toStrictEqual([
'CREATE EXTENSION IF NOT EXISTS "hstore" SCHEMA "my_schema";',
]);
});

it('should return sql statement with array', () => {
const statement = createExtensionFn(['hstore', 'uuid-ossp']);

expect(statement).toBeTypeOf('object');
expect(statement).toStrictEqual([
'CREATE EXTENSION "hstore";',
'CREATE EXTENSION "uuid-ossp";',
]);
});
});
});
});
44 changes: 44 additions & 0 deletions test/operations/extensions/dropExtension.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it } from 'vitest';
import { dropExtension } from '../../../src/operations/extensions';
import { options1 } from '../../utils';

describe('operations', () => {
describe('extensions', () => {
describe('dropExtension', () => {
const dropExtensionFn = dropExtension(options1);

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

it('should return sql statement', () => {
const statement = dropExtensionFn('hstore');

expect(statement).toBeTypeOf('object');
expect(statement).toStrictEqual(['DROP EXTENSION "hstore";']);
});

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

expect(statement).toBeTypeOf('object');
expect(statement).toStrictEqual([
'DROP EXTENSION IF EXISTS "hstore" CASCADE;',
]);
});

it('should return sql statement with array', () => {
const statement = dropExtensionFn(['hstore', 'uuid-ossp']);

expect(statement).toBeTypeOf('object');
expect(statement).toStrictEqual([
'DROP EXTENSION "hstore";',
'DROP EXTENSION "uuid-ossp";',
]);
});
});
});
});