-
Notifications
You must be signed in to change notification settings - Fork 94
/
updateMetadata.test.js
48 lines (35 loc) · 1.47 KB
/
updateMetadata.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
describe("Update Metadata", () => {
const { updateMetadata, getMetadata } = require("../../../../../src/utils/common.js");
const fs = require("fs");
const path = require("path");
const { PYTHAGORA_METADATA_DIR, METADATA_FILENAME } = require("../../../../../src/const/common");
afterEach(() => {
fs.writeFileSync(path.join(".", PYTHAGORA_METADATA_DIR, METADATA_FILENAME), "{}");
});
test("should update metadata with given object", () => {
const objectIdRegex = /^[0-9a-fA-F]{24}$/;
const newMetadata = { key: "value", validId: "5f43cec373fa0a9c8147a9b6" };
updateMetadata(newMetadata);
const metadata = getMetadata();
expect(metadata).toMatchObject({ key: "value" });
// Check if validId is ObjectId string
expect(metadata.validId).toEqual(expect.stringMatching(objectIdRegex));
});
test("should update metadata with an empty object", () => {
updateMetadata({});
const metadata = getMetadata();
expect(metadata).toMatchObject({});
});
test("should update metadata with nested object", () => {
const newMetadata = { nested: { key: "value" } };
updateMetadata(newMetadata);
const metadata = getMetadata();
expect(metadata).toMatchObject({ nested: { key: "value" } });
});
test("should update metadata with array value", () => {
const newMetadata = { array: [1, 2, 3] };
updateMetadata(newMetadata);
const metadata = getMetadata();
expect(metadata).toMatchObject({ array: [1, 2, 3] });
});
});