1- import { getNormalizedBindingData , toRpcHttp , getBindingDefinitions } from '../src/converters' ;
1+ import { getNormalizedBindingData , toRpcHttp , getBindingDefinitions , fromTypedData } from '../src/converters' ;
22import { FunctionInfo } from '../src/FunctionInfo' ;
33import { expect } from 'chai' ;
44import * as sinon from 'sinon' ;
55import { AzureFunctionsRpcMessages as rpc } from '../azure-functions-language-worker-protobuf/src/rpc' ;
66import 'mocha' ;
7+ import { fromString } from 'long' ;
78
89describe ( 'Binding Converters' , ( ) => {
910 it ( 'normalizes binding trigger metadata for HTTP' , ( ) => {
@@ -127,4 +128,46 @@ describe('Binding Converters', () => {
127128 expect ( bindingDefinitions [ 3 ] . direction ) . to . be . undefined ;
128129 expect ( bindingDefinitions [ 3 ] . type ) . to . equal ( "queue" ) ;
129130 } ) ;
131+
132+ it ( 'deserializes string data with fromTypedData' , ( ) => {
133+ let data = fromTypedData ( { string : "foo" } ) ;
134+ expect ( data ) . to . equal ( "foo" ) ;
135+ } ) ;
136+
137+ it ( 'deserializes json data with fromTypedData' , ( ) => {
138+ let data = fromTypedData ( { json : "\{ \"foo\": \"bar\" }" } ) ;
139+ expect ( data && data [ "foo" ] ) . to . equal ( "bar" ) ;
140+ } ) ;
141+
142+ it ( 'deserializes byte data with fromTypedData' , ( ) => {
143+ let buffer = Buffer . from ( "hello" ) ;
144+ let data = fromTypedData ( { bytes : buffer } ) ;
145+ expect ( data && data [ "buffer" ] ) . to . equal ( buffer . buffer ) ;
146+ } ) ;
147+
148+ it ( 'deserializes collectionBytes data with fromTypedData' , ( ) => {
149+ let fooBuffer = Buffer . from ( "foo" ) ;
150+ let barBuffer = Buffer . from ( "bar" ) ;
151+ let data = fromTypedData ( { collectionBytes : { bytes : [ fooBuffer , barBuffer ] } } ) ;
152+ expect ( data && data [ 0 ] && data [ 0 ] [ "buffer" ] ) . to . equal ( fooBuffer . buffer ) ;
153+ expect ( data && data [ 1 ] && data [ 1 ] [ "buffer" ] ) . to . equal ( barBuffer . buffer ) ;
154+ } ) ;
155+
156+ it ( 'deserializes collectionString data with fromTypedData' , ( ) => {
157+ let data = fromTypedData ( { collectionString : { string : [ "foo" , "bar" ] } } ) ;
158+ expect ( data && data [ 0 ] ) . to . equal ( "foo" ) ;
159+ expect ( data && data [ 1 ] ) . to . equal ( "bar" ) ;
160+ } ) ;
161+
162+ it ( 'deserializes collectionDouble data with fromTypedData' , ( ) => {
163+ let data = fromTypedData ( { collectionDouble : { double : [ 1.1 , 2.2 ] } } ) ;
164+ expect ( data && data [ 0 ] ) . to . equal ( 1.1 ) ;
165+ expect ( data && data [ 1 ] ) . to . equal ( 2.2 ) ;
166+ } ) ;
167+
168+ it ( 'deserializes collectionSint64 data with fromTypedData' , ( ) => {
169+ let data = fromTypedData ( { collectionSint64 : { sint64 : [ 123 , fromString ( "9007199254740992" ) ] } } ) ;
170+ expect ( data && data [ 0 ] ) . to . equal ( 123 ) ;
171+ expect ( data && data [ 1 ] ) . to . equal ( "9007199254740992" ) ;
172+ } ) ;
130173} )
0 commit comments