From 5ee0681cf91cb740130c3338bbefaead7145990d Mon Sep 17 00:00:00 2001 From: Warren He Date: Mon, 24 Oct 2022 15:09:38 -0700 Subject: [PATCH] GrpcWebClientBase: add thenableCall test --- .../net/grpc/web/grpcwebclientbase_test.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/javascript/net/grpc/web/grpcwebclientbase_test.js b/javascript/net/grpc/web/grpcwebclientbase_test.js index 2738a7c9..970ae26e 100644 --- a/javascript/net/grpc/web/grpcwebclientbase_test.js +++ b/javascript/net/grpc/web/grpcwebclientbase_test.js @@ -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);