Files
STCourses/packages/feature-import/test/roots.test.ts
T

27 lines
1.6 KiB
TypeScript

import { expect, test } from "bun:test";
import { mkdir, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { importCodeRepo } from "../src/jobs/code-repo";
import { importPdfDeck } from "../src/jobs/pdf-deck";
import { importVideoFolder } from "../src/jobs/video-folder";
import { importPacktVideo } from "../src/jobs/packt-video";
import { makeEnv } from "./harness";
import { makePdf, tmp } from "./fixtures";
test("every job re-checks its path against the roots", async () => {
const inbox = await tmp("stc-inbox-");
const outside = await tmp("stc-outside-");
await makePdf(join(outside, "a.pdf"));
await symlink(outside, join(inbox, "link"));
const env = await makeEnv({ STC_IMPORT_ROOTS: inbox });
const msg = /outside the allowed import folders/;
await expect(importVideoFolder(env.deps, { path: outside }, env.jc)).rejects.toThrow(msg);
await expect(importVideoFolder(env.deps, { path: join(inbox, "link") }, env.jc)).rejects.toThrow(msg);
await expect(importPacktVideo(env.deps, { path: join(outside, "x.zip") }, env.jc)).rejects.toThrow(msg);
await expect(importPdfDeck(env.deps, { path: join(outside, "a.pdf"), options: {} }, env.jc)).rejects.toThrow(msg);
await expect(importCodeRepo(env.deps, { path: outside, options: { courseId: "x" } }, env.jc)).rejects.toThrow(/created|outside/);
await mkdir(join(inbox, "empty"));
await writeFile(join(inbox, "empty", "n.txt"), "");
await expect(importVideoFolder(env.deps, { path: join(inbox, "empty") }, env.jc)).rejects.toThrow(/no video files/); // allowed, then fails on content
});