Skip to content

Commit

Permalink
Use assetFoldersHandler in asset folder diff tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriLojda committed Sep 3, 2024
1 parent dbb4aa8 commit ccca59f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/modules/sync/diff/assetFolder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssetFolderSyncModel } from "../types/syncModel.js";
import { baseHandler, Handler, makeArrayHandler, makeObjectHandler } from "./combinators.js";

export const assetFolderHandler: Handler<AssetFolderSyncModel> = makeObjectHandler({
const assetFolderHandler: Handler<AssetFolderSyncModel> = makeObjectHandler({
name: baseHandler,
folders: { contextfulHandler: () => makeArrayHandler(f => f.codename, assetFolderHandler) },
});
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/syncModel/diff/assetFolder.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";

import { assetFolderHandler } from "../../../../src/modules/sync/diff/assetFolder.js";
import { assetFoldersHandler } from "../../../../src/modules/sync/diff/assetFolder.js";
import { AssetFolderSyncModel } from "../../../../src/modules/sync/types/syncModel.js";

const createFolder = (
Expand All @@ -15,41 +15,41 @@ const createFolder = (

describe("assetFolderHandler", () => {
it("creates addInto operation for nested folders", () => {
const source = createFolder("root", [createFolder("folder1", [createFolder("folder2")])]);
const target = createFolder("root", [createFolder("folder1")]);
const source = [createFolder("root", [createFolder("folder1", [createFolder("folder2")])])];
const target = [createFolder("root", [createFolder("folder1")])];

const operations = assetFolderHandler(source, target);
const operations = assetFoldersHandler(source, target);

expect(operations).toStrictEqual([
{ op: "addInto", path: "/folders/codename:folder1/folders", value: createFolder("folder2") },
{ op: "addInto", path: "/codename:root/folders/codename:folder1/folders", value: createFolder("folder2") },
]);
});

it("creates remove operation for nested folders", () => {
const source = createFolder("root", [createFolder("folder1")]);
const target = createFolder("root", [createFolder("folder1", [createFolder("folder2")])]);
const source = [createFolder("root", [createFolder("folder1")])];
const target = [createFolder("root", [createFolder("folder1", [createFolder("folder2")])])];

const operations = assetFolderHandler(source, target);
const operations = assetFoldersHandler(source, target);

expect(operations).toStrictEqual([
{
op: "remove",
path: "/folders/codename:folder1/folders/codename:folder2",
path: "/codename:root/folders/codename:folder1/folders/codename:folder2",
oldValue: createFolder("folder2"),
},
]);
});

it("creates replace operation for rename in nested folders", () => {
const source = createFolder("root", [createFolder("folder 1", [], "fCodename")]);
const target = createFolder("root", [createFolder("folder 2", [], "fCodename")]);
const source = [createFolder("root", [createFolder("folder 1", [], "fCodename")])];
const target = [createFolder("root", [createFolder("folder 2", [], "fCodename")])];

const operations = assetFolderHandler(source, target);
const operations = assetFoldersHandler(source, target);

expect(operations).toStrictEqual([
{
op: "replace",
path: "/folders/codename:fCodename/name",
path: "/codename:root/folders/codename:fCodename/name",
value: "folder 1",
oldValue: "folder 2",
},
Expand Down

0 comments on commit ccca59f

Please sign in to comment.