36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, expect, test } from "vitest";
|
|
import { readBulkZipResponseBytes } from "./fileService.server";
|
|
|
|
describe("bulk ZIP response bounds", () => {
|
|
test("reads a response up to the declared file size", async () => {
|
|
const response = new Response(new Uint8Array([1, 2, 3]), {
|
|
headers: { "content-length": "3" },
|
|
});
|
|
|
|
await expect(readBulkZipResponseBytes(response, 3)).resolves.toEqual(new Uint8Array([1, 2, 3]));
|
|
});
|
|
|
|
test("rejects an oversized content-length before buffering", async () => {
|
|
const response = new Response(new Uint8Array([1, 2, 3]), {
|
|
headers: { "content-length": "3" },
|
|
});
|
|
|
|
await expect(readBulkZipResponseBytes(response, 2)).rejects.toMatchObject({
|
|
name: "FileServiceError",
|
|
messageKey: "files.errors.downloadFailed",
|
|
});
|
|
});
|
|
|
|
test("rejects actual streamed bytes when content-length understates the body", async () => {
|
|
const response = new Response(new Uint8Array([1, 2, 3]), {
|
|
headers: { "content-length": "2" },
|
|
});
|
|
|
|
await expect(readBulkZipResponseBytes(response, 2)).rejects.toMatchObject({
|
|
name: "FileServiceError",
|
|
messageKey: "files.errors.downloadFailed",
|
|
});
|
|
});
|
|
});
|