File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
src/lib/functional-extensions
test/functional-extensions Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ export interface FunctionalFilterOptions {
1616
1717export type FunctionalFilter = (
1818 options : FunctionalFilterOptions
19- ) => Promise < string > ;
19+ ) => Promise < any > ;
2020
2121export const createFilterExtension = (
2222 name : string ,
Original file line number Diff line number Diff line change @@ -43,3 +43,31 @@ it('The extensions created by createFilter function should work with template en
4343 expect ( queries [ 0 ] ) . toBe ( 'SELECT $1' ) ;
4444 expect ( bindings [ 0 ] . get ( '$1' ) ) . toBe ( 'QAQ3QQQQ' ) ;
4545} ) ;
46+
47+ it ( 'The extensions can return arbitrary value' , async ( ) => {
48+ // Arrange
49+ const testFilter : FunctionalFilter = async ( { args, value } ) =>
50+ ( { id : args [ 'aa' ] , text : `QAQ${ args [ 'aa' ] } ${ value } ` } ) ;
51+ const [ Builder , Runner ] = createFilterExtension ( 'test' , testFilter ) ;
52+ const builder = new Builder ( { } , '' ) ;
53+ const runner = new Runner ( { } , '' ) ;
54+ const {
55+ compiler,
56+ loader,
57+ executeTemplate,
58+ getCreatedQueries,
59+ getCreatedBinding,
60+ } = await createTestCompiler ( { additionalExtensions : [ builder , runner ] } ) ;
61+ const { compiledData } = await compiler . compile (
62+ `SELECT {{ (context.params.id | test(aa=3)).id }}, {{ (context.params.id | test(aa=3)).text }}`
63+ ) ;
64+ loader . setSource ( 'test' , compiledData ) ;
65+ // Act
66+ await executeTemplate ( 'test' , { id : 'QQQQ' } ) ;
67+ const queries = await getCreatedQueries ( ) ;
68+ const bindings = await getCreatedBinding ( ) ;
69+ // Assert
70+ expect ( queries [ 0 ] ) . toBe ( 'SELECT $1 $2' ) ;
71+ expect ( bindings [ 0 ] . get ( '$1' ) ) . toBe ( 3 ) ;
72+ expect ( bindings [ 0 ] . get ( '$2' ) ) . toBe ( 'QAQ3QQQQ' ) ;
73+ } ) ;
You can’t perform that action at this time.
0 commit comments