forked from Pythagora-io/pythagora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisLegacyObjectId.test.js
43 lines (36 loc) · 1.32 KB
/
isLegacyObjectId.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
describe("isLegacyObjectId tests", () => {
const { isLegacyObjectId, ObjectId } = require('../../../../../src/utils/common.js')
test("should return false for null value", () => {
const value = null;
expect(isLegacyObjectId(value)).toBeFalsy();
});
test("should return false for undefined value", () => {
const value = undefined;
expect(isLegacyObjectId(value)).toBeFalsy();
});
test("should return false for empty object", () => {
const value = {};
expect(isLegacyObjectId(value)).toBeFalsy();
});
test("should return false for object with no constructor", () => {
const value = Object.create(null);
expect(isLegacyObjectId(value)).toBeFalsy();
});
test("should return false for non-ObjectID constructor", () => {
const value = { constructor: { name: "NotObjectID" } };
expect(isLegacyObjectId(value)).toBeFalsy();
});
test("should return false for non-ID object inside ObjectID constructor", () => {
const value = new ObjectId();
value.id = "InvalidID";
expect(isLegacyObjectId(value)).toBeFalsy();
});
test("should return true for valid ObjectId with valid JSON ID", () => {
const objectId = new ObjectId();
const value = {
constructor: { name: "ObjectID" },
id: objectId
};
expect(isLegacyObjectId(value)).toBeTruthy();
});
});