39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { LIMITS, validate, validateMany, mention, removeMention } from "../mod/ovis-composer/attachments.js";
|
|
|
|
test("validate rejects over 32 MiB", () => {
|
|
const r = validate({ bytes: 33 * 2 ** 20 });
|
|
assert.equal(r.ok, false);
|
|
assert.equal(r.reason, "Plik przekracza limit 32 MiB");
|
|
});
|
|
|
|
test("validate accepts a normal file and an image", () => {
|
|
assert.deepEqual(validate({ name: "a.txt", bytes: 10 }), { ok: true });
|
|
assert.deepEqual(validate({ name: "a.png", bytes: 10 }), { ok: true });
|
|
});
|
|
|
|
test("validate rejects junk and unknown kind", () => {
|
|
assert.equal(validate(null).ok, false);
|
|
assert.equal(validate({ bytes: NaN }).ok, false);
|
|
assert.equal(validate({ kind: "video", bytes: 1 }).ok, false);
|
|
});
|
|
|
|
test("validateMany enforces count limit", () => {
|
|
assert.equal(LIMITS.filesPerAction, 100);
|
|
const files = Array.from({ length: 101 }, () => ({ name: "a", bytes: 1 }));
|
|
assert.equal(validateMany(files).ok, false);
|
|
assert.equal(validateMany(files.slice(0, 100)).ok, true);
|
|
});
|
|
|
|
test("mention", () => {
|
|
assert.equal(mention(" /a/b "), "@/a/b");
|
|
assert.equal(mention(""), "");
|
|
assert.equal(mention(5), "");
|
|
});
|
|
|
|
test("removeMention removes only the standalone token", () => {
|
|
assert.equal(removeMention("see @src/a.rs now", "src/a.rs"), "see now");
|
|
assert.equal(removeMention("see @src/a.rsx now", "src/a.rs"), "see @src/a.rsx now");
|
|
});
|