mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
* chore: Prune redundant comments and normalize lint directives Removes comments that restate the following line and stale TODOs, drops the passive event listener feature check now that all supported browsers support it, and renames eslint directives to oxlint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH * fix: Evaluate restricted team domains at validation time The restricted email provider list was captured when the model loaded, so it could not follow the hosting environment and the tests that covered it never reached the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH * chore: Replace type suppressions with accurate types Adds a Concrete helper type for registries of abstract classes, declares missing Sequelize and refractor typings, uses public ProseMirror APIs, a typed mock context helper in middleware tests, and a StaticLink component for sidebar rows being edited. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BehTjuZwKbN5csMCp3H4QH --------- Co-authored-by: Claude <noreply@anthropic.com>
95 lines
2.5 KiB
TypeScript
95 lines
2.5 KiB
TypeScript
import type { Socket } from "net";
|
|
import { buildMockContext } from "@server/test/support";
|
|
import timeout from "./timeout";
|
|
|
|
describe("Timeout middleware", () => {
|
|
it("should set request timeout and restore it after request", async () => {
|
|
const originalTimeout = 10000;
|
|
const newTimeout = 1800000; // 30 minutes
|
|
|
|
const setTimeout = vi.fn();
|
|
const mockSocket = {
|
|
timeout: originalTimeout,
|
|
setTimeout,
|
|
} as unknown as Socket;
|
|
|
|
const ctx = {
|
|
req: {
|
|
socket: mockSocket,
|
|
},
|
|
};
|
|
|
|
const next = vi.fn();
|
|
const middleware = timeout(newTimeout);
|
|
|
|
await middleware(buildMockContext(ctx), next);
|
|
|
|
// Should have set the new timeout
|
|
expect(setTimeout).toHaveBeenCalledWith(newTimeout);
|
|
// Should have called next
|
|
expect(next).toHaveBeenCalled();
|
|
// Should have restored the original timeout
|
|
expect(setTimeout).toHaveBeenCalledWith(originalTimeout);
|
|
});
|
|
|
|
it("should restore original timeout even if next throws", async () => {
|
|
const originalTimeout = 10000;
|
|
const newTimeout = 1800000; // 30 minutes
|
|
|
|
const setTimeout = vi.fn();
|
|
const mockSocket = {
|
|
timeout: originalTimeout,
|
|
setTimeout,
|
|
} as unknown as Socket;
|
|
|
|
const ctx = {
|
|
req: {
|
|
socket: mockSocket,
|
|
},
|
|
};
|
|
|
|
const error = new Error("Test error");
|
|
const next = vi.fn().mockRejectedValue(error);
|
|
const middleware = timeout(newTimeout);
|
|
|
|
await expect(middleware(buildMockContext(ctx), next)).rejects.toThrow(
|
|
"Test error"
|
|
);
|
|
|
|
// Should have set the new timeout
|
|
expect(setTimeout).toHaveBeenCalledWith(newTimeout);
|
|
// Should have called next
|
|
expect(next).toHaveBeenCalled();
|
|
// Should have restored the original timeout even after error
|
|
expect(setTimeout).toHaveBeenCalledWith(originalTimeout);
|
|
});
|
|
|
|
it("should handle undefined original timeout", async () => {
|
|
const newTimeout = 1800000; // 30 minutes
|
|
|
|
const setTimeout = vi.fn();
|
|
const mockSocket = {
|
|
timeout: undefined,
|
|
setTimeout,
|
|
} as unknown as Socket;
|
|
|
|
const ctx = {
|
|
req: {
|
|
socket: mockSocket,
|
|
},
|
|
};
|
|
|
|
const next = vi.fn();
|
|
const middleware = timeout(newTimeout);
|
|
|
|
await middleware(buildMockContext(ctx), next);
|
|
|
|
// Should have set the new timeout
|
|
expect(setTimeout).toHaveBeenCalledWith(newTimeout);
|
|
// Should have called next
|
|
expect(next).toHaveBeenCalled();
|
|
// Should have restored timeout to 0 when original was undefined
|
|
expect(setTimeout).toHaveBeenCalledWith(0);
|
|
});
|
|
});
|