Initial import of streamline
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { safeFileName, validateComment, validateStamp, validatePublish, validateUploadMeta } from "@bbbug/shared/ideas";
|
||||
|
||||
describe("validatePublish", () => {
|
||||
test("keeps only in-site / TOS media, first one is the cover", () => {
|
||||
const v = validatePublish({
|
||||
source: "feature", sourceId: "f1", title: " 评论区只看作者 ", summary: "x",
|
||||
media: [{ type: "image", url: "/api/features/f1/evidence-file/a.png" }, { url: "https://evil.example/x.png" }, { type: "video", url: "https://tos/x.mp4" }],
|
||||
}, ["https://tos/"]);
|
||||
expect(v.title).toBe("评论区只看作者");
|
||||
expect(v.media).toEqual([{ type: "image", url: "/api/features/f1/evidence-file/a.png" }, { type: "video", url: "https://tos/x.mp4" }]);
|
||||
});
|
||||
test("rejects a bad source or empty title", () => {
|
||||
expect(() => validatePublish({ source: "eddy", sourceId: "x", title: "t" })).toThrow();
|
||||
expect(() => validatePublish({ source: "bug", sourceId: "x", title: " " })).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateUploadMeta / safeFileName", () => {
|
||||
test("title required, platform normalised", () => {
|
||||
expect(validateUploadMeta({ title: " 老马识图 ", platform: "ios" })).toEqual({ title: "老马识图", summary: "", platform: "ios" });
|
||||
expect(validateUploadMeta({ title: "x", platform: "web" }).platform).toBeNull();
|
||||
expect(() => validateUploadMeta({ title: " " })).toThrow();
|
||||
});
|
||||
test("file names keep only safe characters", () => {
|
||||
expect(safeFileName("demo shot (1).png")).toBe("demo_shot_1_.png");
|
||||
expect(safeFileName("../../etc/passwd")).toBe(".._.._etc_passwd");
|
||||
});
|
||||
});
|
||||
|
||||
test("validateComment trims and bounds", () => {
|
||||
expect(validateComment({ text: " 好想法 " })).toBe("好想法");
|
||||
expect(() => validateComment({ text: " " })).toThrow();
|
||||
expect(() => validateComment({ text: "x".repeat(1001) })).toThrow();
|
||||
});
|
||||
|
||||
test("validateStamp checks kind and bounds", () => {
|
||||
expect(validateStamp({ kind: "pass", x: 0.5, y: 0.2, rot: -8 })).toEqual({ kind: "pass", x: 0.5, y: 0.2, rot: -8 });
|
||||
expect(() => validateStamp({ kind: "gold", x: 0.5, y: 0.5 })).toThrow();
|
||||
expect(() => validateStamp({ kind: "nopass", x: 1.5, y: 0.5 })).toThrow();
|
||||
});
|
||||
Reference in New Issue
Block a user