mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-30 01:06:11 +00:00
test(msteams): cover upload and webhook helpers
This commit is contained in:
84
extensions/msteams/src/pending-uploads.test.ts
Normal file
84
extensions/msteams/src/pending-uploads.test.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
clearPendingUploads,
|
||||
getPendingUpload,
|
||||
getPendingUploadCount,
|
||||
removePendingUpload,
|
||||
storePendingUpload,
|
||||
} from "./pending-uploads.js";
|
||||
|
||||
describe("msteams pending uploads", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
clearPendingUploads();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clearPendingUploads();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("stores uploads, exposes them by id, and tracks count", () => {
|
||||
const id = storePendingUpload({
|
||||
buffer: Buffer.from("hello"),
|
||||
filename: "hello.txt",
|
||||
contentType: "text/plain",
|
||||
conversationId: "conv-1",
|
||||
});
|
||||
|
||||
expect(getPendingUploadCount()).toBe(1);
|
||||
expect(getPendingUpload(id)).toEqual(
|
||||
expect.objectContaining({
|
||||
id,
|
||||
filename: "hello.txt",
|
||||
contentType: "text/plain",
|
||||
conversationId: "conv-1",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("removes uploads explicitly and ignores empty ids", () => {
|
||||
const id = storePendingUpload({
|
||||
buffer: Buffer.from("hello"),
|
||||
filename: "hello.txt",
|
||||
conversationId: "conv-1",
|
||||
});
|
||||
|
||||
removePendingUpload(undefined);
|
||||
expect(getPendingUploadCount()).toBe(1);
|
||||
|
||||
removePendingUpload(id);
|
||||
expect(getPendingUpload(id)).toBeUndefined();
|
||||
expect(getPendingUploadCount()).toBe(0);
|
||||
});
|
||||
|
||||
it("expires uploads by ttl even if the timeout callback has not been observed yet", () => {
|
||||
const id = storePendingUpload({
|
||||
buffer: Buffer.from("hello"),
|
||||
filename: "hello.txt",
|
||||
conversationId: "conv-1",
|
||||
});
|
||||
|
||||
vi.advanceTimersByTime(5 * 60 * 1000 + 1);
|
||||
|
||||
expect(getPendingUpload(id)).toBeUndefined();
|
||||
expect(getPendingUploadCount()).toBe(0);
|
||||
});
|
||||
|
||||
it("clears all uploads for test cleanup", () => {
|
||||
storePendingUpload({
|
||||
buffer: Buffer.from("a"),
|
||||
filename: "a.txt",
|
||||
conversationId: "conv-1",
|
||||
});
|
||||
storePendingUpload({
|
||||
buffer: Buffer.from("b"),
|
||||
filename: "b.txt",
|
||||
conversationId: "conv-2",
|
||||
});
|
||||
|
||||
clearPendingUploads();
|
||||
|
||||
expect(getPendingUploadCount()).toBe(0);
|
||||
});
|
||||
});
|
||||
36
extensions/msteams/src/webhook-timeouts.test.ts
Normal file
36
extensions/msteams/src/webhook-timeouts.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { applyMSTeamsWebhookTimeouts } from "./webhook-timeouts.js";
|
||||
|
||||
describe("applyMSTeamsWebhookTimeouts", () => {
|
||||
it("applies default timeouts and header clamp", () => {
|
||||
const httpServer = {
|
||||
setTimeout: vi.fn(),
|
||||
requestTimeout: 0,
|
||||
headersTimeout: 0,
|
||||
} as never;
|
||||
|
||||
applyMSTeamsWebhookTimeouts(httpServer);
|
||||
|
||||
expect(httpServer.setTimeout).toHaveBeenCalledWith(30_000);
|
||||
expect(httpServer.requestTimeout).toBe(30_000);
|
||||
expect(httpServer.headersTimeout).toBe(15_000);
|
||||
});
|
||||
|
||||
it("uses explicit overrides and clamps headers timeout to request timeout", () => {
|
||||
const httpServer = {
|
||||
setTimeout: vi.fn(),
|
||||
requestTimeout: 0,
|
||||
headersTimeout: 0,
|
||||
} as never;
|
||||
|
||||
applyMSTeamsWebhookTimeouts(httpServer, {
|
||||
inactivityTimeoutMs: 12_000,
|
||||
requestTimeoutMs: 9_000,
|
||||
headersTimeoutMs: 15_000,
|
||||
});
|
||||
|
||||
expect(httpServer.setTimeout).toHaveBeenCalledWith(12_000);
|
||||
expect(httpServer.requestTimeout).toBe(9_000);
|
||||
expect(httpServer.headersTimeout).toBe(9_000);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user