From 1fe1438cccf114c9d90a3de6167b142c4a185659 Mon Sep 17 00:00:00 2001 From: Boris Besemer Date: Mon, 1 Jul 2024 15:47:53 +0200 Subject: [PATCH] test(cache): test the cacher --- src/write.test.ts | 82 +++++++++++++++++++++++++++++++++++++++++++++-- src/write.ts | 2 +- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/write.test.ts b/src/write.test.ts index 4439474..699b47e 100644 --- a/src/write.test.ts +++ b/src/write.test.ts @@ -1,7 +1,83 @@ import { describe, expect, test } from "vitest"; +import { updateCache } from "./write"; -describe("write to file", () => { - test("Hello", () => { - expect(true).toBeTruthy(); +describe("cache", () => { + test("writes output to empty cache", () => { + const cache = {}; + + updateCache({ + cache, + data: { + Test: new Set(["hello"]), + "Test.NestedNamespace": new Set(["foobar"]), + }, + source: {}, + }); + + expect(cache).toEqual({ + Test: { + hello: "Test.hello", + NestedNamespace: { + foobar: "Test.NestedNamespace.foobar", + }, + }, + }); + }); + + test("writes output to existing cache", () => { + const cache = { + Test: { + hello: "Test.hello", + NestedNamespace: { + foobar: "Test.NestedNamespace.foobar", + }, + }, + }; + + updateCache({ + cache, + data: { + Test: new Set(["test"]), + "Test.NestedNamespace": new Set(["test"]), + }, + source: {}, + }); + + expect(cache).toEqual({ + Test: { + hello: "Test.hello", + test: "Test.test", + NestedNamespace: { + foobar: "Test.NestedNamespace.foobar", + test: "Test.NestedNamespace.test", + }, + }, + }); + }); + + test("updates labels with existing source", () => { + const cache = {}; + + updateCache({ + cache, + data: { + Test: new Set(["hello"]), + "Test.NestedNamespace": new Set(["foobar"]), + }, + source: { + Test: { + hello: "Hello", + }, + }, + }); + + expect(cache).toEqual({ + Test: { + hello: "Hello", + NestedNamespace: { + foobar: "Test.NestedNamespace.foobar", + }, + }, + }); }); }); diff --git a/src/write.ts b/src/write.ts index 3cf749b..7117126 100644 --- a/src/write.ts +++ b/src/write.ts @@ -63,7 +63,7 @@ export async function processFiles( /** * Update existing cache based on given data and source labels */ -function updateCache({ +export function updateCache({ cache, source, data,