Skip to content

Commit 66de68b

Browse files
test(node-http-handler): add tests for NodeHttpHandler.create() static method
1 parent 71d0e40 commit 66de68b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

packages/node-http-handler/src/node-http-handler.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,45 @@ describe("NodeHttpHandler", () => {
247247
});
248248
});
249249

250+
describe("create", () => {
251+
const randomRequestTimeout = Math.round(Math.random() * 10000) + 1;
252+
253+
it.each([
254+
["existing handler instance", new NodeHttpHandler()],
255+
["custom HttpHandler object", {
256+
handle: vi.fn(),
257+
metadata: { handlerProtocol: "custom" },
258+
updateHttpClientConfig: vi.fn(),
259+
httpHandlerConfigs: vi.fn(),
260+
}],
261+
])("returns the input handler when passed %s", (_, handler) => {
262+
const result = NodeHttpHandler.create(handler);
263+
expect(result).toBe(handler);
264+
});
265+
266+
it.each([
267+
["undefined", undefined],
268+
["an empty options hash", {}],
269+
["empty provider", async () => undefined],
270+
])("creates new handler instance when input is %s", async (_, input) => {
271+
const result = NodeHttpHandler.create(input);
272+
expect(result).toBeInstanceOf(NodeHttpHandler);
273+
});
274+
275+
it.each([
276+
["an options hash", { requestTimeout: randomRequestTimeout }],
277+
["a provider", async () => ({ requestTimeout: randomRequestTimeout })],
278+
])("creates new handler instance with config when input is %s", async (_, input) => {
279+
const result = NodeHttpHandler.create(input);
280+
expect(result).toBeInstanceOf(NodeHttpHandler);
281+
282+
// Verify configuration by calling handle
283+
await result.handle({} as any);
284+
285+
expect(result.httpHandlerConfigs().requestTimeout).toBe(randomRequestTimeout);
286+
});
287+
});
288+
250289
describe("#destroy", () => {
251290
it("should be callable and return nothing", () => {
252291
const nodeHttpHandler = new NodeHttpHandler();

0 commit comments

Comments
 (0)