Skip to content

Commit 7d11f6c

Browse files
committed
test(msteams): cover upload and webhook helpers
1 parent 1ea2593 commit 7d11f6c

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2+
import {
3+
clearPendingUploads,
4+
getPendingUpload,
5+
getPendingUploadCount,
6+
removePendingUpload,
7+
storePendingUpload,
8+
} from "./pending-uploads.js";
9+
10+
describe("msteams pending uploads", () => {
11+
beforeEach(() => {
12+
vi.useFakeTimers();
13+
clearPendingUploads();
14+
});
15+
16+
afterEach(() => {
17+
clearPendingUploads();
18+
vi.useRealTimers();
19+
});
20+
21+
it("stores uploads, exposes them by id, and tracks count", () => {
22+
const id = storePendingUpload({
23+
buffer: Buffer.from("hello"),
24+
filename: "hello.txt",
25+
contentType: "text/plain",
26+
conversationId: "conv-1",
27+
});
28+
29+
expect(getPendingUploadCount()).toBe(1);
30+
expect(getPendingUpload(id)).toEqual(
31+
expect.objectContaining({
32+
id,
33+
filename: "hello.txt",
34+
contentType: "text/plain",
35+
conversationId: "conv-1",
36+
}),
37+
);
38+
});
39+
40+
it("removes uploads explicitly and ignores empty ids", () => {
41+
const id = storePendingUpload({
42+
buffer: Buffer.from("hello"),
43+
filename: "hello.txt",
44+
conversationId: "conv-1",
45+
});
46+
47+
removePendingUpload(undefined);
48+
expect(getPendingUploadCount()).toBe(1);
49+
50+
removePendingUpload(id);
51+
expect(getPendingUpload(id)).toBeUndefined();
52+
expect(getPendingUploadCount()).toBe(0);
53+
});
54+
55+
it("expires uploads by ttl even if the timeout callback has not been observed yet", () => {
56+
const id = storePendingUpload({
57+
buffer: Buffer.from("hello"),
58+
filename: "hello.txt",
59+
conversationId: "conv-1",
60+
});
61+
62+
vi.advanceTimersByTime(5 * 60 * 1000 + 1);
63+
64+
expect(getPendingUpload(id)).toBeUndefined();
65+
expect(getPendingUploadCount()).toBe(0);
66+
});
67+
68+
it("clears all uploads for test cleanup", () => {
69+
storePendingUpload({
70+
buffer: Buffer.from("a"),
71+
filename: "a.txt",
72+
conversationId: "conv-1",
73+
});
74+
storePendingUpload({
75+
buffer: Buffer.from("b"),
76+
filename: "b.txt",
77+
conversationId: "conv-2",
78+
});
79+
80+
clearPendingUploads();
81+
82+
expect(getPendingUploadCount()).toBe(0);
83+
});
84+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { applyMSTeamsWebhookTimeouts } from "./webhook-timeouts.js";
3+
4+
describe("applyMSTeamsWebhookTimeouts", () => {
5+
it("applies default timeouts and header clamp", () => {
6+
const httpServer = {
7+
setTimeout: vi.fn(),
8+
requestTimeout: 0,
9+
headersTimeout: 0,
10+
} as never;
11+
12+
applyMSTeamsWebhookTimeouts(httpServer);
13+
14+
expect(httpServer.setTimeout).toHaveBeenCalledWith(30_000);
15+
expect(httpServer.requestTimeout).toBe(30_000);
16+
expect(httpServer.headersTimeout).toBe(15_000);
17+
});
18+
19+
it("uses explicit overrides and clamps headers timeout to request timeout", () => {
20+
const httpServer = {
21+
setTimeout: vi.fn(),
22+
requestTimeout: 0,
23+
headersTimeout: 0,
24+
} as never;
25+
26+
applyMSTeamsWebhookTimeouts(httpServer, {
27+
inactivityTimeoutMs: 12_000,
28+
requestTimeoutMs: 9_000,
29+
headersTimeoutMs: 15_000,
30+
});
31+
32+
expect(httpServer.setTimeout).toHaveBeenCalledWith(12_000);
33+
expect(httpServer.requestTimeout).toBe(9_000);
34+
expect(httpServer.headersTimeout).toBe(9_000);
35+
});
36+
});

0 commit comments

Comments
 (0)