Skip to content

Commit 0f5b640

Browse files
committed
Add test
1 parent d7836b9 commit 0f5b640

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/serviceClientTests.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,79 @@ describe("ServiceClient", function () {
219219
assert.deepStrictEqual(res.slice(), [1, 2, 3]);
220220
});
221221

222+
it("should deserialize response bodies with undefined array", async function () {
223+
let request: WebResourceLike;
224+
const httpClient: HttpClient = {
225+
sendRequest: (req) => {
226+
request = req;
227+
return Promise.resolve({
228+
request,
229+
status: 200,
230+
headers: new HttpHeaders(),
231+
bodyAsText: JSON.stringify({ nextLink: "mockLink" }),
232+
});
233+
},
234+
};
235+
236+
const client1 = new ServiceClient(undefined, {
237+
httpClient,
238+
requestPolicyFactories: [deserializationPolicy()],
239+
});
240+
241+
const res = (await client1.sendOperationRequest(
242+
{},
243+
{
244+
serializer: new Serializer(),
245+
httpMethod: "GET",
246+
baseUrl: "httpbin.org",
247+
responses: {
248+
"200": {
249+
bodyMapper: {
250+
type: {
251+
name: "Composite",
252+
modelProperties: {
253+
value: {
254+
serializedName: "",
255+
type: {
256+
name: "Sequence",
257+
element: {
258+
type: { name: "String" },
259+
},
260+
},
261+
},
262+
nextLink: {
263+
serializedName: "nextLink",
264+
type: { name: "String" },
265+
},
266+
},
267+
},
268+
},
269+
},
270+
default: {
271+
bodyMapper: {
272+
serializedName: "ErrorResponse",
273+
type: {
274+
name: "Composite",
275+
className: "ErrorResponse",
276+
modelProperties: {
277+
code: { serializedName: "code", type: { name: "String" } },
278+
message: {
279+
serializedName: "message",
280+
type: { name: "String" },
281+
},
282+
},
283+
},
284+
},
285+
},
286+
},
287+
}
288+
)) as any;
289+
290+
assert.strictEqual(res._response.status, 200);
291+
assert.deepStrictEqual(res.nextLink, "mockLink");
292+
assert.deepStrictEqual(res, []);
293+
});
294+
222295
it("should use userAgent header name value from options", async function () {
223296
const httpClient: HttpClient = {
224297
sendRequest: (request: WebResourceLike) => {

0 commit comments

Comments
 (0)