@onlineapps/conn-base-hub 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/clover.xml +86 -53
- package/coverage/coverage-final.json +3 -1
- package/coverage/lcov-report/config.js.html +217 -0
- package/coverage/lcov-report/defaults.js.html +169 -0
- package/coverage/lcov-report/index.html +49 -19
- package/coverage/lcov-report/index.js.html +175 -61
- package/coverage/lcov.info +203 -132
- package/logs/app.2025-12-21.log +0 -0
- package/package.json +6 -6
- package/src/config.js +44 -0
- package/src/defaults.js +28 -0
- package/src/index.js +53 -25
- package/tests/component/hub-integration.test.js +30 -28
- package/tests/unit/hub.test.js +47 -41
|
@@ -1,52 +1,54 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// Mock
|
|
4
|
-
jest.mock('@onlineapps/
|
|
5
|
-
|
|
3
|
+
// Mock actual external dependencies used by conn-base-hub (component-level wiring, no real infra)
|
|
4
|
+
jest.mock('@onlineapps/conn-infra-mq', () =>
|
|
5
|
+
jest.fn().mockImplementation(() => ({
|
|
6
6
|
connect: jest.fn().mockResolvedValue(),
|
|
7
7
|
publish: jest.fn().mockResolvedValue(),
|
|
8
8
|
subscribe: jest.fn().mockResolvedValue(),
|
|
9
|
-
close: jest.fn().mockResolvedValue()
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
close: jest.fn().mockResolvedValue(),
|
|
10
|
+
disconnect: jest.fn().mockResolvedValue(),
|
|
11
|
+
}))
|
|
12
|
+
);
|
|
12
13
|
|
|
13
|
-
jest.mock('@onlineapps/
|
|
14
|
+
jest.mock('@onlineapps/conn-orch-registry', () => ({
|
|
14
15
|
ServiceRegistryClient: jest.fn().mockImplementation(() => ({
|
|
16
|
+
initialize: jest.fn().mockResolvedValue(true),
|
|
15
17
|
register: jest.fn().mockResolvedValue(),
|
|
16
18
|
deregister: jest.fn().mockResolvedValue(),
|
|
17
19
|
discover: jest.fn().mockResolvedValue([]),
|
|
20
|
+
subscribeToChanges: jest.fn().mockResolvedValue(true),
|
|
21
|
+
startHeartbeat: jest.fn(),
|
|
22
|
+
dispose: jest.fn().mockResolvedValue(true),
|
|
18
23
|
emit: jest.fn()
|
|
19
24
|
}))
|
|
20
|
-
})
|
|
25
|
+
}));
|
|
21
26
|
|
|
22
|
-
jest.mock('@onlineapps/
|
|
27
|
+
jest.mock('@onlineapps/conn-orch-cookbook', () => ({
|
|
23
28
|
validateCookbook: jest.fn(),
|
|
24
|
-
|
|
29
|
+
parseCookbookFromObject: jest.fn(),
|
|
25
30
|
executeCookbook: jest.fn()
|
|
26
|
-
})
|
|
31
|
+
}));
|
|
27
32
|
|
|
28
|
-
jest.mock('@onlineapps/
|
|
29
|
-
|
|
33
|
+
jest.mock('@onlineapps/conn-base-storage', () =>
|
|
34
|
+
jest.fn().mockImplementation(() => ({
|
|
35
|
+
initialize: jest.fn().mockResolvedValue(true),
|
|
30
36
|
upload: jest.fn().mockResolvedValue({ etag: '123' }),
|
|
31
37
|
download: jest.fn().mockResolvedValue(Buffer.from('test')),
|
|
32
38
|
delete: jest.fn().mockResolvedValue(),
|
|
33
39
|
list: jest.fn().mockResolvedValue([])
|
|
34
|
-
}))
|
|
35
|
-
|
|
40
|
+
}))
|
|
41
|
+
);
|
|
36
42
|
|
|
37
|
-
jest.mock('@onlineapps/
|
|
38
|
-
|
|
43
|
+
jest.mock('@onlineapps/conn-base-monitoring', () => ({
|
|
44
|
+
init: jest.fn().mockResolvedValue({
|
|
39
45
|
info: jest.fn(),
|
|
40
46
|
error: jest.fn(),
|
|
41
47
|
warn: jest.fn(),
|
|
42
48
|
debug: jest.fn(),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
registry: { info: jest.fn(), error: jest.fn() },
|
|
47
|
-
close: jest.fn().mockResolvedValue()
|
|
48
|
-
}));
|
|
49
|
-
}, { virtual: true });
|
|
49
|
+
shutdown: jest.fn().mockResolvedValue(true),
|
|
50
|
+
})
|
|
51
|
+
}));
|
|
50
52
|
|
|
51
53
|
describe('Hub Connector Component Tests @component', () => {
|
|
52
54
|
let hub;
|
|
@@ -97,7 +99,7 @@ describe('Hub Connector Component Tests @component', () => {
|
|
|
97
99
|
|
|
98
100
|
it('should export cookbook functions', () => {
|
|
99
101
|
expect(hub.validateCookbook).toBeDefined();
|
|
100
|
-
expect(hub.
|
|
102
|
+
expect(hub.parseCookbookFromObject).toBeDefined();
|
|
101
103
|
expect(hub.executeCookbook).toBeDefined();
|
|
102
104
|
});
|
|
103
105
|
});
|
|
@@ -271,19 +273,19 @@ describe('Hub Connector Component Tests @component', () => {
|
|
|
271
273
|
describe('Cookbook Integration', () => {
|
|
272
274
|
it('should provide cookbook functions', () => {
|
|
273
275
|
expect(hub.validateCookbook).toBeDefined();
|
|
274
|
-
expect(hub.
|
|
276
|
+
expect(hub.parseCookbookFromObject).toBeDefined();
|
|
275
277
|
expect(hub.executeCookbook).toBeDefined();
|
|
276
278
|
});
|
|
277
279
|
|
|
278
280
|
it('should handle cookbook operations', () => {
|
|
279
281
|
const cookbook = {
|
|
280
|
-
version: '1.0',
|
|
282
|
+
version: '2.1.0',
|
|
281
283
|
name: 'test-cookbook',
|
|
282
284
|
steps: []
|
|
283
285
|
};
|
|
284
286
|
|
|
285
287
|
expect(() => hub.validateCookbook(cookbook)).not.toThrow();
|
|
286
|
-
expect(() => hub.
|
|
288
|
+
expect(() => hub.parseCookbookFromObject(cookbook)).not.toThrow();
|
|
287
289
|
expect(() => hub.executeCookbook(cookbook, {})).not.toThrow();
|
|
288
290
|
});
|
|
289
291
|
});
|
package/tests/unit/hub.test.js
CHANGED
|
@@ -2,50 +2,54 @@
|
|
|
2
2
|
* Tests for @onlineapps/connector-hub
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// Mock all dependencies
|
|
8
|
-
jest.mock('@onlineapps/connector-registry-client', () => ({
|
|
5
|
+
// Mock actual dependencies used by conn-base-hub
|
|
6
|
+
jest.mock('@onlineapps/conn-orch-registry', () => ({
|
|
9
7
|
ServiceRegistryClient: jest.fn().mockImplementation(() => ({
|
|
10
8
|
initialize: jest.fn().mockResolvedValue(true),
|
|
11
9
|
dispose: jest.fn().mockResolvedValue(true),
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
register: jest.fn().mockResolvedValue(true),
|
|
11
|
+
deregister: jest.fn().mockResolvedValue(true),
|
|
14
12
|
startHeartbeat: jest.fn(),
|
|
15
13
|
subscribeToChanges: jest.fn().mockResolvedValue(true)
|
|
16
14
|
}))
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
jest.mock('@onlineapps/
|
|
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
|
-
jest.
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock('@onlineapps/conn-infra-mq', () =>
|
|
18
|
+
jest.fn().mockImplementation(() => ({
|
|
19
|
+
connect: jest.fn().mockResolvedValue(true),
|
|
20
|
+
disconnect: jest.fn().mockResolvedValue(true),
|
|
21
|
+
publish: jest.fn().mockResolvedValue(true),
|
|
22
|
+
consume: jest.fn().mockResolvedValue(true),
|
|
23
|
+
}))
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
jest.mock('@onlineapps/conn-base-storage', () =>
|
|
27
|
+
jest.fn().mockImplementation(() => ({
|
|
28
|
+
initialize: jest.fn().mockResolvedValue(true),
|
|
29
|
+
upload: jest.fn().mockResolvedValue({ etag: 'abc123' }),
|
|
30
|
+
download: jest.fn().mockResolvedValue(Buffer.from('test')),
|
|
31
|
+
delete: jest.fn().mockResolvedValue(true),
|
|
32
|
+
list: jest.fn().mockResolvedValue([]),
|
|
33
|
+
}))
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
jest.mock('@onlineapps/conn-base-monitoring', () => ({
|
|
37
|
+
init: jest.fn().mockResolvedValue({
|
|
38
|
+
info: jest.fn(),
|
|
39
|
+
warn: jest.fn(),
|
|
40
|
+
error: jest.fn(),
|
|
41
|
+
debug: jest.fn(),
|
|
42
|
+
shutdown: jest.fn().mockResolvedValue(true),
|
|
43
|
+
})
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
jest.mock('@onlineapps/conn-orch-cookbook', () => ({
|
|
45
47
|
validateCookbook: jest.fn(),
|
|
46
|
-
|
|
48
|
+
parseCookbookFromObject: jest.fn(),
|
|
47
49
|
executeCookbook: jest.fn()
|
|
48
|
-
})
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const ConnectorHub = require('../../src/index');
|
|
49
53
|
|
|
50
54
|
describe('ConnectorHub @unit', () => {
|
|
51
55
|
beforeEach(() => {
|
|
@@ -59,7 +63,7 @@ describe('ConnectorHub @unit', () => {
|
|
|
59
63
|
expect(ConnectorHub.StorageConnector).toBeDefined();
|
|
60
64
|
expect(ConnectorHub.createLogger).toBeDefined();
|
|
61
65
|
expect(ConnectorHub.validateCookbook).toBeDefined();
|
|
62
|
-
expect(ConnectorHub.
|
|
66
|
+
expect(ConnectorHub.parseCookbookFromObject).toBeDefined();
|
|
63
67
|
expect(ConnectorHub.executeCookbook).toBeDefined();
|
|
64
68
|
});
|
|
65
69
|
|
|
@@ -83,7 +87,7 @@ describe('ConnectorHub @unit', () => {
|
|
|
83
87
|
queue: 'test-queue'
|
|
84
88
|
},
|
|
85
89
|
storage: {
|
|
86
|
-
|
|
90
|
+
endPoint: 'localhost',
|
|
87
91
|
port: 9000,
|
|
88
92
|
accessKey: 'minioadmin',
|
|
89
93
|
secretKey: 'minioadmin'
|
|
@@ -135,7 +139,7 @@ describe('ConnectorHub @unit', () => {
|
|
|
135
139
|
queue: 'test-queue'
|
|
136
140
|
},
|
|
137
141
|
storage: {
|
|
138
|
-
|
|
142
|
+
endPoint: 'localhost',
|
|
139
143
|
port: 9000,
|
|
140
144
|
accessKey: 'minioadmin',
|
|
141
145
|
secretKey: 'minioadmin'
|
|
@@ -163,7 +167,7 @@ describe('ConnectorHub @unit', () => {
|
|
|
163
167
|
queue: 'test-queue'
|
|
164
168
|
},
|
|
165
169
|
storage: {
|
|
166
|
-
|
|
170
|
+
endPoint: 'localhost',
|
|
167
171
|
port: 9000,
|
|
168
172
|
accessKey: 'minioadmin',
|
|
169
173
|
secretKey: 'minioadmin'
|
|
@@ -172,11 +176,13 @@ describe('ConnectorHub @unit', () => {
|
|
|
172
176
|
|
|
173
177
|
const microservice = ConnectorHub.createMicroservice(config);
|
|
174
178
|
await microservice.init();
|
|
179
|
+
|
|
180
|
+
const closeSpy = jest.spyOn(microservice.logger, 'close');
|
|
175
181
|
await microservice.shutdown();
|
|
176
182
|
|
|
177
183
|
expect(microservice.registry.dispose).toHaveBeenCalled();
|
|
178
184
|
expect(microservice.mq.disconnect).toHaveBeenCalled();
|
|
179
|
-
expect(
|
|
185
|
+
expect(closeSpy).toHaveBeenCalled();
|
|
180
186
|
});
|
|
181
187
|
|
|
182
188
|
test('should handle initialization errors gracefully', async () => {
|