@@ -2,7 +2,24 @@ import { format } from '../src/sanitization'
22
33describe ( 'sanitization' , ( ) => {
44 describe ( 'format' , ( ) => {
5- test ( 'does nothing with empty values' , ( ) => {
5+ test ( 'does no replacement for missing object key' , ( ) => {
6+ const query = 'select 1 from user where id=:id'
7+ expect ( format ( query , { } ) ) . toEqual ( query )
8+ } )
9+
10+ test ( 'replaces named parameters' , ( ) => {
11+ const query = 'select 1 from user where state in (:state) and deleted_at=:deleted_at'
12+ const expected = "select 1 from user where state in ('active', 'inactive') and deleted_at=true"
13+ expect ( format ( query , { state : [ 'active' , 'inactive' ] , deleted_at : true } ) ) . toEqual ( expected )
14+ } )
15+
16+ test ( 'replaces duplicate named parameters' , ( ) => {
17+ const query = 'select 1 from user where id=:id or actor_id=:id'
18+ const expected = 'select 1 from user where id=42 or actor_id=42'
19+ expect ( format ( query , { id : 42 } ) ) . toEqual ( expected )
20+ } )
21+
22+ test ( 'does nothing with empty values list' , ( ) => {
623 const query = 'select 1 from user where id=?'
724 expect ( format ( query , [ ] ) ) . toEqual ( query )
825 } )
0 commit comments