feat: relink moved project folders
This commit is contained in:
@@ -10,6 +10,7 @@ mock.module("@raycast/api", () => ({ environment: { supportPath: tmpdir() },
|
||||
const project = await import("../src/lib/velum-project");
|
||||
const { mappingForRestoration } = await import("../src/lib/mapping-groups");
|
||||
const { mergeMappingGroups } = await import("../src/lib/mapping-groups");
|
||||
const { relocateProject } = await import("../src/lib/project-relocation");
|
||||
const roots: string[] = [];
|
||||
afterEach(async () => { await Promise.all(roots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true }))); });
|
||||
|
||||
@@ -57,6 +58,74 @@ describe("Velum-Projektstände", () => {
|
||||
.toEqual([first.run.id, second.run.id].sort());
|
||||
});
|
||||
|
||||
it("übernimmt nach einem Umzug alle Projektstände, Regeln und verschobenen Kopien", async () => {
|
||||
const root = await fs.mkdtemp(join(tmpdir(), "velum-relocate-test-"));
|
||||
roots.push(root);
|
||||
const oldParent = join(root, "Alt");
|
||||
const newParent = join(root, "Neu");
|
||||
const oldPath = join(oldParent, "Projekt");
|
||||
const newPath = join(newParent, "Projekt");
|
||||
const support = join(root, "Raycast");
|
||||
await fs.mkdir(oldPath, { recursive: true });
|
||||
await fs.writeFile(join(oldPath, "Notiz.txt"), "PERSON_01");
|
||||
await project.saveProjectRules(oldPath, [{ type: "BEGRIFF", value: "Testsystem" }], support);
|
||||
await project.saveProjectWhitelist(oldPath, [{ type: "PERSON", original: "Kein Name" }], support);
|
||||
await project.saveProjectEntityTypes(oldPath, ["PERSON", "ORG"], support);
|
||||
await project.saveProjectFileExclusions(oldPath, ["Ausnahme.txt"], support);
|
||||
const first = await project.createRun(oldPath, support);
|
||||
first.run.mapping = { PERSON_01: { original: "Erika Beispiel", type: "PERSON" } };
|
||||
first.run.files = [{ source: "Notiz.txt", output: "Notiz.txt", kind: "text" }];
|
||||
first.run.inPlace = true;
|
||||
await fs.writeFile(join(first.directory, "files", "Notiz.txt"), "PERSON_01");
|
||||
const oldCopy = join(oldParent, `Projekt-Velum-${first.run.id}`);
|
||||
await fs.mkdir(oldCopy);
|
||||
await fs.writeFile(join(oldCopy, "Notiz.txt"), "PERSON_01");
|
||||
first.run.copyPath = oldCopy;
|
||||
await project.saveRun(first.directory, first.run);
|
||||
const second = await project.createRun(oldPath, support);
|
||||
second.run.createdAt = new Date(Date.parse(first.run.createdAt) + 1000).toISOString();
|
||||
second.run.mapping = first.run.mapping;
|
||||
second.run.files = first.run.files;
|
||||
second.run.inPlace = true;
|
||||
await fs.writeFile(join(second.directory, "files", "Notiz.txt"), "PERSON_01");
|
||||
await project.saveRun(second.directory, second.run);
|
||||
|
||||
await fs.rename(oldParent, newParent);
|
||||
expect(await relocateProject(oldPath, newPath, support))
|
||||
.toEqual({ runsMoved: 2, copiesRelinked: 1, copiesMissing: 0 });
|
||||
expect(await project.listRuns(oldPath, support)).toHaveLength(0);
|
||||
const moved = await project.listRuns(newPath, support);
|
||||
expect(moved.map(({ run }) => run.id)).toEqual([second.run.id, first.run.id]);
|
||||
expect(moved.every(({ run }) => run.projectPath === newPath && run.projectName === "Projekt")).toBe(true);
|
||||
expect(moved[1].run.copyPath).toBe(join(newParent, `Projekt-Velum-${first.run.id}`));
|
||||
expect(moved[0].run.mapping).toEqual(first.run.mapping);
|
||||
expect(await project.loadProjectRules(newPath, support)).toEqual([{ type: "BEGRIFF", value: "Testsystem" }]);
|
||||
expect(await project.loadProjectWhitelist(newPath, support)).toEqual([{ type: "PERSON", original: "Kein Name" }]);
|
||||
expect(await project.loadProjectEntityTypes(newPath, support)).toEqual(["PERSON", "ORG"]);
|
||||
expect(await project.loadProjectFileExclusions(newPath, support)).toEqual(["Ausnahme.txt"]);
|
||||
expect((await project.scanRestorableCopyFiles(moved[0].run, moved[0].directory)).root).toBe(newPath);
|
||||
expect((await project.listAllRuns(support)).filter(({ run }) => run.projectPath === newPath)).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("verhindert das Umhängen auf einen bereits belegten Projektordner", async () => {
|
||||
const root = await fs.mkdtemp(join(tmpdir(), "velum-relocate-conflict-test-"));
|
||||
roots.push(root);
|
||||
const oldPath = join(root, "Alt");
|
||||
const newPath = join(root, "Neu");
|
||||
const support = join(root, "Raycast");
|
||||
await fs.mkdir(oldPath);
|
||||
await fs.mkdir(newPath);
|
||||
const oldRun = await project.createRun(oldPath, support);
|
||||
const targetRun = await project.createRun(newPath, support);
|
||||
await project.saveRun(oldRun.directory, oldRun.run);
|
||||
await project.saveRun(targetRun.directory, targetRun.run);
|
||||
await expect(relocateProject(oldPath, oldPath, support)).rejects.toThrow("bereits der Projektordner");
|
||||
await expect(relocateProject(oldPath, join(root, "Fehlt"), support)).rejects.toThrow("nicht vorhanden");
|
||||
await expect(relocateProject(oldPath, newPath, support)).rejects.toThrow("bereits ein Velum-Projekt");
|
||||
expect(await project.listRuns(oldPath, support)).toHaveLength(1);
|
||||
expect(await project.listRuns(newPath, support)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("legt pseudonymisierte Kopien neben dem Projekt ab und behält die Tabelle privat", async () => {
|
||||
const root = await fs.mkdtemp(join(tmpdir(), "velum-sibling-copy-test-"));
|
||||
roots.push(root);
|
||||
|
||||
Reference in New Issue
Block a user