Skip to content

Commit

Permalink
GrpcWebClientBase: add falsy response test
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed May 16, 2022
1 parent cdae121 commit a6051f1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions javascript/net/grpc/web/grpcwebclientbase_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ testSuite({
assertElementsEquals(DEFAULT_UNARY_HEADER_VALUES, Object.values(headers));
},

async testRpcFalsyResponse() {
const xhr = new XhrIo();
const client = new GrpcWebClientBase(/* options= */ {}, xhr);
const methodDescriptor = createMethodDescriptor((bytes) => {
assertElementsEquals(DEFAULT_RPC_RESPONSE_DATA, [].slice.call(bytes));
return 0;
});

const response = await new Promise((resolve, reject) => {
client.rpcCall(
'url', new MockRequest(), /* metadata= */ {}, methodDescriptor,
(error, response) => {
assertNull(error);
resolve(response);
});
xhr.simulatePartialResponse(
googCrypt.encodeByteArray(new Uint8Array(DEFAULT_RPC_RESPONSE)),
DEFAULT_RESPONSE_HEADERS);
xhr.simulateReadyStateChange(ReadyState.COMPLETE);
});

assertEquals(0, response);
const headers = /** @type {!Object} */ (xhr.getLastRequestHeaders());
assertElementsEquals(DEFAULT_UNARY_HEADERS, Object.keys(headers));
assertElementsEquals(DEFAULT_UNARY_HEADER_VALUES, Object.values(headers));
},

async testDeadline() {
const xhr = new XhrIo();
const client = new GrpcWebClientBase(/* options= */ {}, xhr);
Expand Down

0 comments on commit a6051f1

Please sign in to comment.