@@ -677,19 +677,28 @@ describe('GrpcService', function() {
677677
678678 describe ( 'convertValue_' , function ( ) {
679679 it ( 'should convert primitive values correctly' , function ( ) {
680- var convertedValues = extend (
681- GrpcService . convertValue_ ( null ) ,
682- GrpcService . convertValue_ ( 1 ) ,
683- GrpcService . convertValue_ ( 'Hi' ) ,
684- GrpcService . convertValue_ ( true )
685- ) ;
680+ var buffer = new Buffer ( 'Value' ) ;
686681
687- assert . deepEqual ( convertedValues , {
688- nullValue : null ,
689- numberValue : 1 ,
690- stringValue : 'Hi' ,
682+ assert . deepEqual ( GrpcService . convertValue_ ( null ) , {
683+ nullValue : null
684+ } ) ;
685+
686+ assert . deepEqual ( GrpcService . convertValue_ ( 1 ) , {
687+ numberValue : 1
688+ } ) ;
689+
690+ assert . deepEqual ( GrpcService . convertValue_ ( 'Hi' ) , {
691+ stringValue : 'Hi'
692+ } ) ;
693+
694+ assert . deepEqual ( GrpcService . convertValue_ ( true ) , {
691695 booleanValue : true
692696 } ) ;
697+
698+ assert . strictEqual (
699+ GrpcService . convertValue_ ( buffer ) . blobValue . toString ( ) ,
700+ 'Value'
701+ ) ;
693702 } ) ;
694703
695704 it ( 'should convert objects' , function ( ) {
@@ -699,11 +708,26 @@ describe('GrpcService', function() {
699708 return value ;
700709 } ;
701710
702- var convertedValue = GrpcService . convertValue_ ( { } ) ;
711+ var convertedValue = GrpcService . convertValue_ ( value ) ;
703712
704713 assert . strictEqual ( convertedValue , value ) ;
705714 } ) ;
706715
716+ it ( 'should convert dates' , function ( ) {
717+ var value = new Date ( ) ;
718+ var seconds = value . getTime ( ) / 1000 ;
719+ var secondsRounded = Math . floor ( seconds ) ;
720+
721+ var convertedValue = GrpcService . convertValue_ ( value ) ;
722+
723+ assert . deepEqual ( convertedValue , {
724+ timestampValue : {
725+ seconds : secondsRounded ,
726+ nanos : Math . floor ( ( seconds - secondsRounded ) * 1e9 )
727+ }
728+ } ) ;
729+ } ) ;
730+
707731 it ( 'should convert arrays' , function ( ) {
708732 var convertedValue = GrpcService . convertValue_ ( [ 1 , 2 , 3 ] ) ;
709733
@@ -716,8 +740,8 @@ describe('GrpcService', function() {
716740
717741 it ( 'should throw if a type is not recognized' , function ( ) {
718742 assert . throws ( function ( ) {
719- GrpcService . convertValue_ ( new Date ( ) ) ;
720- } , 'Value of type Date not recognized.' ) ;
743+ GrpcService . convertValue_ ( ) ;
744+ } , 'Value of type undefined not recognized.' ) ;
721745 } ) ;
722746 } ) ;
723747
0 commit comments