-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow empty sql tags (fixes #93)
- Loading branch information
Showing
4 changed files
with
70 additions
and
32 deletions.
There are no files selected for viewing
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
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,61 @@ | ||
// @flow | ||
|
||
import Roarr from 'roarr'; | ||
import test, { | ||
beforeEach, | ||
} from 'ava'; | ||
import executeQuery from '../../../src/routines/executeQuery'; | ||
import { | ||
InvalidInputError, | ||
} from '../../../src/errors'; | ||
import createClientConfiguration from '../../helpers/createClientConfiguration'; | ||
|
||
const createConnectionStub = () => { | ||
return { | ||
connection: { | ||
slonik: { | ||
terminated: false, | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
beforeEach((t) => { | ||
t.context.logger = Roarr; | ||
t.context.connection = createConnectionStub(); | ||
t.context.executionRoutine = () => {}; | ||
}); | ||
|
||
test('throws a descriptive error if query is empty', async (t) => { | ||
const error = await t.throwsAsync(() => { | ||
return executeQuery( | ||
t.context.logger, | ||
t.context.connection, | ||
createClientConfiguration(), | ||
'', | ||
[], | ||
'foo', | ||
t.context.executionRoutine | ||
); | ||
}); | ||
|
||
t.assert(error instanceof InvalidInputError); | ||
t.assert(error.message === 'Unexpected SQL input. Query cannot be empty.'); | ||
}); | ||
|
||
test('throws a descriptive error if the entire query is a value binding', async (t) => { | ||
const error = await t.throwsAsync(() => { | ||
return executeQuery( | ||
t.context.logger, | ||
t.context.connection, | ||
createClientConfiguration(), | ||
'$1', | ||
[], | ||
'foo', | ||
t.context.executionRoutine | ||
); | ||
}); | ||
|
||
t.assert(error instanceof InvalidInputError); | ||
t.assert(error.message === 'Unexpected SQL input. Query cannot be empty. Found only value binding.'); | ||
}); |
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