From 0198b5c04eb574491929f098416d66c96f9cc7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Tue, 24 Oct 2023 15:13:02 +0200 Subject: [PATCH] Adds tests for --- .../projects/CachingProjectDataSource.test.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 __test__/projects/CachingProjectDataSource.test.ts diff --git a/__test__/projects/CachingProjectDataSource.test.ts b/__test__/projects/CachingProjectDataSource.test.ts new file mode 100644 index 00000000..8e458c3c --- /dev/null +++ b/__test__/projects/CachingProjectDataSource.test.ts @@ -0,0 +1,42 @@ +import Project from "../../src/features/projects/domain/Project" +import CachingProjectDataSource from "../../src/features/projects/domain/CachingProjectDataSource" + +test("It caches projects read from the data source", async () => { + const projects = [{ + id: "foo", + name: "foo", + versions: [{ + id: "bar", + name: "bar", + specifications: [{ + id: "baz.yml", + name: "baz.yml", + url: "https://example.com/baz.yml" + }] + }, { + id: "hello", + name: "hello", + specifications: [{ + id: "world.yml", + name: "world.yml", + url: "https://example.com/world.yml" + }] + }] + }] + let cachedProjects: Project[] | undefined + const sut = new CachingProjectDataSource({ + async getProjects() { + return projects + } + }, { + async getProjects() { + return [] + }, + async storeProjects(projects) { + cachedProjects = projects + }, + async deleteProjects() {} + }) + await sut.getProjects() + expect(cachedProjects).toEqual(projects) +})