|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | + |
| 3 | +process.env.DATABASE_URL = ":memory:"; |
| 4 | +const { queries } = await import("../src/services/db"); |
| 5 | + |
| 6 | +describe("MIME type defaults", () => { |
| 7 | + test("stored mime type matches insert", () => { |
| 8 | + queries.insertDrop.run({ |
| 9 | + $id: "mime-test", $rootHash: "0xm", $fileName: "m.pdf", |
| 10 | + $fileSize: 100, $mimeType: "application/pdf", $passwordHash: null, |
| 11 | + $maxDownloads: null, $expiresAt: null, $ipAddress: null, |
| 12 | + }); |
| 13 | + const d = queries.getDrop.get("mime-test"); |
| 14 | + expect(d!.mime_type).toBe("application/pdf"); |
| 15 | + }); |
| 16 | + |
| 17 | + test("text/plain is preserved", () => { |
| 18 | + queries.insertDrop.run({ |
| 19 | + $id: "mime-txt", $rootHash: "0xmt", $fileName: "t.txt", |
| 20 | + $fileSize: 10, $mimeType: "text/plain", $passwordHash: null, |
| 21 | + $maxDownloads: null, $expiresAt: null, $ipAddress: null, |
| 22 | + }); |
| 23 | + expect(queries.getDrop.get("mime-txt")!.mime_type).toBe("text/plain"); |
| 24 | + }); |
| 25 | + |
| 26 | + test("octet-stream for unknown types", () => { |
| 27 | + queries.insertDrop.run({ |
| 28 | + $id: "mime-bin", $rootHash: "0xmb", $fileName: "b.bin", |
| 29 | + $fileSize: 10, $mimeType: "application/octet-stream", $passwordHash: null, |
| 30 | + $maxDownloads: null, $expiresAt: null, $ipAddress: null, |
| 31 | + }); |
| 32 | + expect(queries.getDrop.get("mime-bin")!.mime_type).toBe("application/octet-stream"); |
| 33 | + }); |
| 34 | +}); |
0 commit comments