@@ -50,7 +50,7 @@ describe('Test "rest_api" filter', () => {
5050 extensions : { rest_api : path . join ( __dirname , '..' , 'src' ) } ,
5151 } ) ;
5252
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 }}` ;
5454
5555 // Act
5656 await compileAndLoad ( sql ) ;
@@ -155,7 +155,7 @@ describe('Test "rest_api" filter', () => {
155155 extensions : { rest_api : path . join ( __dirname , '..' , 'src' ) } ,
156156 } ) ;
157157
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 }}` ;
159159
160160 // Act
161161 await compileAndLoad ( sql ) ;
@@ -183,7 +183,35 @@ describe('Test "rest_api" filter', () => {
183183 extensions : { rest_api : path . join ( __dirname , '..' , 'src' ) } ,
184184 } ) ;
185185
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 }}` ;
187215
188216 // Act
189217 await compileAndLoad ( sql ) ;
0 commit comments