Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add tests for SQL fragment generation
- Loading branch information
Showing
9 changed files
with
136 additions
and
21 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @flow | ||
|
||
import test from 'ava'; | ||
import createRawSqlSqlFragment from '../../../src/templateTags/createRawSqlSqlFragment'; | ||
|
||
test('creates a tuple with a single parameter', (t) => { | ||
const sqlFragment = createRawSqlSqlFragment({ | ||
sql: 'foo', | ||
type: 'RAW_SQL', | ||
values: [] | ||
}, 0); | ||
|
||
t.true(sqlFragment.sql === 'foo'); | ||
t.deepEqual(sqlFragment.parameters, []); | ||
}); | ||
|
||
test('offsets parameter position', (t) => { | ||
const sqlFragment = createRawSqlSqlFragment({ | ||
sql: '($1)', | ||
type: 'RAW_SQL', | ||
values: [ | ||
'foo' | ||
] | ||
}, 1); | ||
|
||
t.true(sqlFragment.sql === '($2)'); | ||
t.deepEqual(sqlFragment.parameters, ['foo']); | ||
}); | ||
|
||
test('throws an erorr if the greatest parameter position is greater than the number of parameter values', (t) => { | ||
t.throws(() => { | ||
createRawSqlSqlFragment({ | ||
sql: '($1, $2)', | ||
type: 'RAW_SQL', | ||
values: [ | ||
'foo' | ||
] | ||
}, 0); | ||
}, 'The greatest parameter position is greater than the number of parameter values.'); | ||
}); | ||
|
||
test('throws an erorr if least parameter is greater than 1', (t) => { | ||
t.throws(() => { | ||
createRawSqlSqlFragment({ | ||
sql: '($2)', | ||
type: 'RAW_SQL', | ||
values: [ | ||
'foo', | ||
'bar' | ||
] | ||
}, 0); | ||
}, 'Parameter position must start at 1.'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @flow | ||
|
||
import test from 'ava'; | ||
import createTupleSqlFragment from '../../../src/templateTags/createTupleSqlFragment'; | ||
|
||
test('creates a tuple with a single parameter', (t) => { | ||
const sqlFragment = createTupleSqlFragment({ | ||
type: 'TUPLE', | ||
values: ['foo'] | ||
}, 0); | ||
|
||
t.true(sqlFragment.sql === '($1)'); | ||
t.deepEqual(sqlFragment.parameters, ['foo']); | ||
}); | ||
|
||
test('creates a tuple multiple parameters', (t) => { | ||
const sqlFragment = createTupleSqlFragment({ | ||
type: 'TUPLE', | ||
values: ['foo', 'bar', 'baz'] | ||
}, 0); | ||
|
||
t.true(sqlFragment.sql === '($1, $2, $3)'); | ||
t.deepEqual(sqlFragment.parameters, ['foo', 'bar', 'baz']); | ||
}); | ||
|
||
test('offsets parameter', (t) => { | ||
const sqlFragment = createTupleSqlFragment({ | ||
type: 'TUPLE', | ||
values: ['foo'] | ||
}, 1); | ||
|
||
t.true(sqlFragment.sql === '($2)'); | ||
t.deepEqual(sqlFragment.parameters, ['foo']); | ||
}); | ||
|
||
test('throws an error if tuple is empty', (t) => { | ||
t.throws(() => { | ||
createTupleSqlFragment({ | ||
type: 'TUPLE', | ||
values: [] | ||
}, 1); | ||
}, 'Tuple must have values.'); | ||
}); |