Skip to content

Commit 620e3e4

Browse files
add tests and fix test running command
1 parent 413f64c commit 620e3e4

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
},
106106
"scripts": {
107107
"lint": "eslint . --max-warnings=0",
108-
"test:unit": "node --experimental-test-module-mocks --test ./test/**/*.spec.js",
108+
"test:unit": "node --experimental-test-module-mocks --test-reporter dot --test ./test",
109109
"package": "node esbuild.package.js",
110110
"postinstall": "npx simple-git-hooks"
111111
},
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const { describe, it } = require('node:test');
2+
const { deepStrictEqual } = require('node:assert');
3+
const { generateIdToNameMap } = require('../../../forward_engineering/helpers/generateIdToNameMap');
4+
5+
describe('generateIdToNameMap', () => {
6+
it('should return an empty map for an empty or undefined schema', () => {
7+
const result = generateIdToNameMap({});
8+
deepStrictEqual(result, {});
9+
});
10+
11+
it('should return an empty map for an undefined schema', () => {
12+
const result = generateIdToNameMap();
13+
deepStrictEqual(result, {});
14+
});
15+
16+
it('should map GUIDs to names for a simple schema', () => {
17+
const schema = {
18+
Entity1: { GUID: '123' },
19+
Entity2: { GUID: '456' },
20+
};
21+
const expected = {
22+
'123': 'Entity1',
23+
'456': 'Entity2',
24+
};
25+
const result = generateIdToNameMap(schema);
26+
deepStrictEqual(result, expected);
27+
});
28+
29+
it('should ignore system names', () => {
30+
const schema = {
31+
Scalars: { GUID: '123', properties: {} },
32+
Entity1: { GUID: '456', properties: {} },
33+
};
34+
const expected = {
35+
'456': 'Entity1',
36+
};
37+
const result = generateIdToNameMap(schema);
38+
deepStrictEqual(result, expected);
39+
});
40+
41+
it('should handle nested properties', () => {
42+
const schema = {
43+
Entity1: {
44+
GUID: '123',
45+
properties: {
46+
SubEntity1: {
47+
GUID: '456',
48+
},
49+
},
50+
},
51+
};
52+
const expected = {
53+
'123': 'Entity1',
54+
'456': 'SubEntity1',
55+
};
56+
const result = generateIdToNameMap(schema);
57+
deepStrictEqual(result, expected);
58+
});
59+
60+
it('should handle complex nested properties inside system name', () => {
61+
const schema = {
62+
Scalars: {
63+
GUID: '123',
64+
properties: {
65+
SubEntity1: {
66+
GUID: '456',
67+
properties: {
68+
SubSubEntity1: { GUID: '789', properties: {} },
69+
},
70+
},
71+
},
72+
},
73+
};
74+
const expected = {
75+
'456': 'SubEntity1',
76+
'789': 'SubSubEntity1',
77+
};
78+
const result = generateIdToNameMap(schema);
79+
deepStrictEqual(result, expected);
80+
});
81+
});

0 commit comments

Comments
 (0)