Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test(web): exercise missing content type on proxied storage responses

Richie McIlroy49a257ad6f88
diff --git a/apps/web/__tests__/unit/storage-object-response-headers.test.ts b/apps/web/__tests__/unit/storage-object-response-headers.test.ts
index 61fa903ef..315b17069 100644
--- a/apps/web/__tests__/unit/storage-object-response-headers.test.ts
+++ b/apps/web/__tests__/unit/storage-object-response-headers.test.ts
@@ -50,8 +50,16 @@ const objectUrl = (key: string) =>
const upstream = (contentType: string | null, init: ResponseInit = {}) => {
const headers = new Headers(init.headers);
- if (contentType) headers.set("Content-Type", contentType);
- return new Response("data", { status: init.status ?? 200, headers });
+ const response = new Response("data", {
+ status: init.status ?? 200,
+ headers,
+ });
+ if (contentType) {
+ response.headers.set("Content-Type", contentType);
+ } else {
+ response.headers.delete("Content-Type");
+ }
+ return response;
};
const expectContentHeaders = (response: Response) => {
@@ -99,7 +107,6 @@ describe("storage object content headers", () => {
"application/pdf",
"text/plain",
"application/javascript",
- null,
])("serves %s as an attachment", async (contentType) => {
mocks.read.mockReturnValue(Effect.succeed(upstream(contentType)));
const response = await GET(
@@ -113,6 +120,21 @@ describe("storage object content headers", () => {
expectContentHeaders(response);
});
+ it("serves an upstream without a Content-Type as an attachment", async () => {
+ const source = upstream(null);
+ expect(source.headers.get("Content-Type")).toBeNull();
+ mocks.read.mockReturnValue(Effect.succeed(source));
+ const response = await GET(
+ new NextRequest(objectUrl("owner/video/upload.bin")),
+ );
+ expect(response.status).toBe(200);
+ expect(response.headers.get("Content-Type")).toBe(
+ "application/octet-stream",
+ );
+ expect(response.headers.get("Content-Disposition")).toBe("attachment");
+ expectContentHeaders(response);
+ });
+
it("keeps byte-range responses intact", async () => {
mocks.read.mockReturnValue(
Effect.succeed(