@@ -50,7 +50,7 @@ describe('Test "rest_api" filter', () => {
50
50
extensions : { rest_api : path . join ( __dirname , '..' , 'src' ) } ,
51
51
} ) ;
52
52
53
- const sql = `{% set value = { "path": { "id": 1 } } %}SELECT {{ value | rest_api(url='https://dummyjson.com/products/:id') }}` ;
53
+ const sql = `{% set value = { "path": { "id": 1 } } %}SELECT {{ value | rest_api(url='https://dummyjson.com/products/:id') | dump }}` ;
54
54
55
55
// Act
56
56
await compileAndLoad ( sql ) ;
@@ -155,7 +155,7 @@ describe('Test "rest_api" filter', () => {
155
155
extensions : { rest_api : path . join ( __dirname , '..' , 'src' ) } ,
156
156
} ) ;
157
157
158
- const sql = `{% set value = { "query": { "q": "phone" } } %}SELECT {{ value | rest_api(url='https://dummyjson.com/products/search') }}` ;
158
+ const sql = `{% set value = { "query": { "q": "phone" } } %}SELECT {{ value | rest_api(url='https://dummyjson.com/products/search') | dump }}` ;
159
159
160
160
// Act
161
161
await compileAndLoad ( sql ) ;
@@ -183,7 +183,35 @@ describe('Test "rest_api" filter', () => {
183
183
extensions : { rest_api : path . join ( __dirname , '..' , 'src' ) } ,
184
184
} ) ;
185
185
186
- const sql = `{% set value = { "body": { "title": "BMW Pencil" }, "headers": { "Content-Type": "application/json" } } %}SELECT {{ value | rest_api(url='https://dummyjson.com/products/add', method='POST') }}` ;
186
+ const sql = `{% set value = { "body": { "title": "BMW Pencil" }, "headers": { "Content-Type": "application/json" } } %}SELECT {{ value | rest_api(url='https://dummyjson.com/products/add', method='POST') | dump }}` ;
187
+
188
+ // Act
189
+ await compileAndLoad ( sql ) ;
190
+ await execute ( { } ) ;
191
+
192
+ // Assert
193
+ const queries = await getExecutedQueries ( ) ;
194
+ const bindings = await getCreatedBinding ( ) ;
195
+
196
+ expect ( queries [ 0 ] ) . toBe ( 'SELECT $1' ) ;
197
+ expect ( bindings [ 0 ] . get ( '$1' ) ) . toEqual ( expected ) ;
198
+ } ,
199
+ 50 * 1000
200
+ )
201
+
202
+ it (
203
+ 'Should work with template engine with field access' ,
204
+ async ( ) => {
205
+ const expected = {
206
+ id : 101 ,
207
+ title : 'BMW Pencil'
208
+ } . id ;
209
+
210
+ const { compileAndLoad, execute, getExecutedQueries, getCreatedBinding } = await getTestCompiler ( {
211
+ extensions : { rest_api : path . join ( __dirname , '..' , 'src' ) } ,
212
+ } ) ;
213
+
214
+ const sql = `{% set value = { "body": { "title": "BMW Pencil" }, "headers": { "Content-Type": "application/json" } } %}SELECT {{ (value | rest_api(url='https://dummyjson.com/products/add', method='POST')).id }}` ;
187
215
188
216
// Act
189
217
await compileAndLoad ( sql ) ;
0 commit comments