mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 09:11:20 +00:00
test: consolidate media store header extension coverage
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const realOs = await vi.importActual<typeof import("node:os")>("node:os");
|
||||
const HOME = path.join(realOs.tmpdir(), "openclaw-home-header-ext-test");
|
||||
|
||||
vi.mock("node:os", () => ({
|
||||
default: { homedir: () => HOME, tmpdir: () => realOs.tmpdir() },
|
||||
homedir: () => HOME,
|
||||
tmpdir: () => realOs.tmpdir(),
|
||||
}));
|
||||
|
||||
vi.mock("./mime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./mime.js")>("./mime.js");
|
||||
return {
|
||||
...actual,
|
||||
detectMime: vi.fn(async () => "audio/opus"),
|
||||
};
|
||||
});
|
||||
|
||||
const store = await import("./store.js");
|
||||
|
||||
describe("media store header extensions", () => {
|
||||
beforeAll(async () => {
|
||||
await fs.rm(HOME, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await fs.rm(HOME, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("prefers header mime extension when sniffed mime lacks mapping", async () => {
|
||||
const buf = Buffer.from("fake-audio");
|
||||
const saved = await store.saveMediaBuffer(buf, "audio/ogg; codecs=opus");
|
||||
expect(path.extname(saved.path)).toBe(".ogg");
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import sharp from "sharp";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { isPathWithinBase } from "../../test/helpers/paths.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
|
||||
@@ -155,6 +155,29 @@ describe("media store", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("prefers header mime extension when sniffed mime lacks mapping", async () => {
|
||||
await withTempStore(async (_store, home) => {
|
||||
vi.resetModules();
|
||||
vi.doMock("./mime.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./mime.js")>("./mime.js");
|
||||
return {
|
||||
...actual,
|
||||
detectMime: vi.fn(async () => "audio/opus"),
|
||||
};
|
||||
});
|
||||
|
||||
try {
|
||||
const storeWithMock = await import("./store.js");
|
||||
const buf = Buffer.from("fake-audio");
|
||||
const saved = await storeWithMock.saveMediaBuffer(buf, "audio/ogg; codecs=opus");
|
||||
expect(path.extname(saved.path)).toBe(".ogg");
|
||||
expect(saved.path.startsWith(home)).toBe(true);
|
||||
} finally {
|
||||
vi.doUnmock("./mime.js");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("extractOriginalFilename", () => {
|
||||
it("extracts original filename from embedded pattern", async () => {
|
||||
await withTempStore(async (store) => {
|
||||
|
||||
Reference in New Issue
Block a user