Skip to content

Commit

Permalink
test: add sql unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Mar 9, 2024
1 parent 928773e commit b2a3482
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
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;');
});
});
});

0 comments on commit b2a3482

Please sign in to comment.