Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
fix(cache): prevent cache creation to break old data (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgrasset authored Nov 4, 2023
1 parent bdb87ec commit 5b1c98d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 16 deletions.
11 changes: 0 additions & 11 deletions src/helpers/cache/__tests__/create-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { access } from "fs/promises";

import { INSTANCE_ID } from "../../../constants.js";
import { createCacheFile } from "../create-cache.js";
import { getCache } from "../get-cache.js";
import { writeToCacheFile } from "../write-to-cache-file.js";

jest.mock("fs/promises", () => ({
Expand All @@ -19,14 +18,6 @@ jest.mock("../../../constants.js", () => {
};
});

jest.mock("../get-cache.js", () => ({
getCache: jest.fn().mockResolvedValue({
instance: {
id: INSTANCE_ID,
},
}),
}));

jest.mock("../write-to-cache-file.js", () => ({
writeToCacheFile: jest.fn(),
}));
Expand All @@ -46,7 +37,6 @@ describe("createCache", () => {
await createCacheFile();

expect(promiseAccessMock).toHaveBeenCalledTimes(1);
expect(getCache).toHaveBeenCalledTimes(1);
expect(writeToCacheFile).not.toHaveBeenCalled();
});
});
Expand All @@ -60,7 +50,6 @@ describe("createCache", () => {
await createCacheFile();

expect(promiseAccessMock).toHaveBeenCalledTimes(1);
expect(getCache).not.toHaveBeenCalled();
expect(writeToCacheFile).toHaveBeenCalledWith({
version: "0.2",
instance: { id: INSTANCE_ID },
Expand Down
5 changes: 0 additions & 5 deletions src/helpers/cache/create-cache.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { access, constants } from "fs/promises";

import { CACHE_PATH, INSTANCE_ID } from "../../constants.js";
import { getCache } from "./get-cache.js";
import { writeToCacheFile } from "./write-to-cache-file.js";

export const createCacheFile = async () => {
try {
// Check if the file exists
await access(CACHE_PATH, constants.F_OK);
const cache = await getCache();
if (cache.instance.id !== INSTANCE_ID) {
throw new Error(`Cache for instance ${INSTANCE_ID} not found`);
}
} catch {
writeToCacheFile({
version: "0.2",
Expand Down

0 comments on commit 5b1c98d

Please sign in to comment.