@@ -75,6 +75,77 @@ testSuite({
75
75
assertElementsEquals ( DEFAULT_UNARY_HEADER_VALUES , Object . values ( headers ) ) ;
76
76
} ,
77
77
78
+ async testRpcFalsyResponse_ForNonProtobufDescriptor ( ) {
79
+ const xhr = new XhrIo ( ) ;
80
+ const client = new GrpcWebClientBase ( /* options= */ { } , xhr ) ;
81
+ const methodDescriptor = createMethodDescriptor ( ( bytes ) => {
82
+ assertElementsEquals ( DEFAULT_RPC_RESPONSE_DATA , [ ] . slice . call ( bytes ) ) ;
83
+ return 0 ;
84
+ } ) ;
85
+
86
+ const response = await new Promise ( ( resolve , reject ) => {
87
+ client . rpcCall (
88
+ 'url' , new MockRequest ( ) , /* metadata= */ { } , methodDescriptor ,
89
+ ( error , response ) => {
90
+ assertNull ( error ) ;
91
+ resolve ( response ) ;
92
+ } ) ;
93
+ xhr . simulatePartialResponse (
94
+ googCrypt . encodeByteArray ( new Uint8Array ( DEFAULT_RPC_RESPONSE ) ) ,
95
+ DEFAULT_RESPONSE_HEADERS ) ;
96
+ xhr . simulateReadyStateChange ( ReadyState . COMPLETE ) ;
97
+ } ) ;
98
+
99
+ assertEquals ( 0 , response ) ;
100
+ const headers = /** @type {!Object } */ ( xhr . getLastRequestHeaders ( ) ) ;
101
+ assertElementsEquals ( DEFAULT_UNARY_HEADERS , Object . keys ( headers ) ) ;
102
+ assertElementsEquals ( DEFAULT_UNARY_HEADER_VALUES , Object . values ( headers ) ) ;
103
+ } ,
104
+
105
+ async testRpcResponseThenableCall ( ) {
106
+ const xhr = new XhrIo ( ) ;
107
+ const client = new GrpcWebClientBase ( /* options= */ { } , xhr ) ;
108
+ const methodDescriptor = createMethodDescriptor ( ( bytes ) => {
109
+ assertElementsEquals ( DEFAULT_RPC_RESPONSE_DATA , [ ] . slice . call ( bytes ) ) ;
110
+ return new MockReply ( 'value' ) ;
111
+ } ) ;
112
+
113
+ const responsePromise = client . thenableCall (
114
+ 'url' , new MockRequest ( ) , /* metadata= */ { } , methodDescriptor ) ;
115
+ xhr . simulatePartialResponse (
116
+ googCrypt . encodeByteArray ( new Uint8Array ( DEFAULT_RPC_RESPONSE ) ) ,
117
+ DEFAULT_RESPONSE_HEADERS ) ;
118
+ xhr . simulateReadyStateChange ( ReadyState . COMPLETE ) ;
119
+ const response = await responsePromise ;
120
+
121
+ assertEquals ( 'value' , response . data ) ;
122
+ const headers = /** @type {!Object } */ ( xhr . getLastRequestHeaders ( ) ) ;
123
+ assertElementsEquals ( DEFAULT_UNARY_HEADERS , Object . keys ( headers ) ) ;
124
+ assertElementsEquals ( DEFAULT_UNARY_HEADER_VALUES , Object . values ( headers ) ) ;
125
+ } ,
126
+
127
+ async testRpcFalsyResponseThenableCall_ForNonProtobufDescriptor ( ) {
128
+ const xhr = new XhrIo ( ) ;
129
+ const client = new GrpcWebClientBase ( /* options= */ { } , xhr ) ;
130
+ const methodDescriptor = createMethodDescriptor ( ( bytes ) => {
131
+ assertElementsEquals ( DEFAULT_RPC_RESPONSE_DATA , [ ] . slice . call ( bytes ) ) ;
132
+ return 0 ;
133
+ } ) ;
134
+
135
+ const responsePromise = client . thenableCall (
136
+ 'url' , new MockRequest ( ) , /* metadata= */ { } , methodDescriptor ) ;
137
+ xhr . simulatePartialResponse (
138
+ googCrypt . encodeByteArray ( new Uint8Array ( DEFAULT_RPC_RESPONSE ) ) ,
139
+ DEFAULT_RESPONSE_HEADERS ) ;
140
+ xhr . simulateReadyStateChange ( ReadyState . COMPLETE ) ;
141
+ const response = await responsePromise ;
142
+
143
+ assertEquals ( 0 , response ) ;
144
+ const headers = /** @type {!Object } */ ( xhr . getLastRequestHeaders ( ) ) ;
145
+ assertElementsEquals ( DEFAULT_UNARY_HEADERS , Object . keys ( headers ) ) ;
146
+ assertElementsEquals ( DEFAULT_UNARY_HEADER_VALUES , Object . values ( headers ) ) ;
147
+ } ,
148
+
78
149
async testDeadline ( ) {
79
150
const xhr = new XhrIo ( ) ;
80
151
const client = new GrpcWebClientBase ( /* options= */ { } , xhr ) ;
0 commit comments