Skip to content

Commit

Permalink
GrpcWebClientBase: add thenableCall test
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Oct 24, 2022
1 parent f880bfd commit 5ee0681
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions javascript/net/grpc/web/grpcwebclientbase_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ testSuite({
assertElementsEquals(DEFAULT_UNARY_HEADER_VALUES, Object.values(headers));
},

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

const responsePromise = client.thenableCall(
'url', new MockRequest(), /* metadata= */ {}, methodDescriptor);
xhr.simulatePartialResponse(
googCrypt.encodeByteArray(new Uint8Array(DEFAULT_RPC_RESPONSE)),
DEFAULT_RESPONSE_HEADERS);
xhr.simulateReadyStateChange(ReadyState.COMPLETE);
const response = await responsePromise;

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

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

0 comments on commit 5ee0681

Please sign in to comment.