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 sql unit tests #1025

Merged
merged 1 commit into from
Mar 9, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/operations/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export function sql(mOptions: MigrationOptions): Sql {

return (sqlStr, args) => {
// applies some very basic templating using the utils.p
let s: string = t(sqlStr, args);
let statement: string = t(sqlStr, args);

// add trailing ; if not present
if (s.lastIndexOf(';') !== s.length - 1) {
s += ';';
if (statement.lastIndexOf(';') !== statement.length - 1) {
statement += ';';
}

return s;
return statement;
};
}
22 changes: 22 additions & 0 deletions test/operations/sql.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest';
import { sql } from '../../src/operations/other';
import { options1 } from '../utils';

describe('operations', () => {
describe('sql', () => {
const sqlFn = sql(options1);

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

it('should return sql statement', () => {
const statement = sqlFn('SELECT * FROM users WHERE id = {id}', {
id: 1,
});

expect(statement).toBeTypeOf('string');
expect(statement).toStrictEqual('SELECT * FROM users WHERE id = 1;');
});
});
});