@onlineapps/service-wrapper 2.0.7 → 2.0.9
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/README.md +76 -38
- package/docs/API_STRUCTURE_STANDARD.md +132 -0
- package/docs/ARCHITECTURE_DECISION.md +200 -0
- package/docs/CONFIGURATION_GUIDE.md +261 -0
- package/docs/FINAL_ARCHITECTURE.md +271 -0
- package/docs/HANDLER_VS_HTTP_COMPARISON.md +269 -0
- package/docs/INSTALLATION_GUIDE.md +353 -0
- package/docs/OPERATIONS_SCHEMA.md +405 -0
- package/docs/SERVICE_TESTING_STANDARD.md +389 -0
- package/docs/WRAPPER_ARCHITECTURE.md +218 -0
- package/onlineapps-service-wrapper-2.0.8.tgz +0 -0
- package/package.json +4 -3
- package/src/ServiceWrapper.js +433 -270
- package/test/monitoring-integration.test.js +150 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test monitoring integration in service-wrapper
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
describe('ServiceWrapper Monitoring Integration', () => {
|
|
6
|
+
let ServiceWrapper;
|
|
7
|
+
let express;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
// Reset modules
|
|
11
|
+
jest.resetModules();
|
|
12
|
+
|
|
13
|
+
// Mock dependencies
|
|
14
|
+
jest.mock('@onlineapps/conn-infra-mq', () => {
|
|
15
|
+
return jest.fn().mockImplementation(() => ({
|
|
16
|
+
connect: jest.fn().mockResolvedValue(true),
|
|
17
|
+
disconnect: jest.fn().mockResolvedValue(true),
|
|
18
|
+
consume: jest.fn().mockResolvedValue(true),
|
|
19
|
+
isConnected: jest.fn().mockReturnValue(true)
|
|
20
|
+
}));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
jest.mock('@onlineapps/conn-orch-registry', () => ({
|
|
24
|
+
ServiceRegistryClient: jest.fn().mockImplementation(() => ({
|
|
25
|
+
register: jest.fn().mockResolvedValue(true),
|
|
26
|
+
unregister: jest.fn().mockResolvedValue(true),
|
|
27
|
+
sendHeartbeat: jest.fn().mockResolvedValue(true),
|
|
28
|
+
isConnected: jest.fn().mockReturnValue(true)
|
|
29
|
+
}))
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
jest.mock('@onlineapps/conn-base-monitoring', () => ({
|
|
33
|
+
init: jest.fn().mockResolvedValue({
|
|
34
|
+
info: jest.fn(),
|
|
35
|
+
warn: jest.fn(),
|
|
36
|
+
error: jest.fn(),
|
|
37
|
+
debug: jest.fn()
|
|
38
|
+
}),
|
|
39
|
+
info: jest.fn(),
|
|
40
|
+
warn: jest.fn(),
|
|
41
|
+
error: jest.fn(),
|
|
42
|
+
debug: jest.fn()
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
jest.mock('@onlineapps/conn-orch-orchestrator', () => ({
|
|
46
|
+
create: jest.fn().mockReturnValue({
|
|
47
|
+
processWorkflowMessage: jest.fn().mockResolvedValue({ success: true })
|
|
48
|
+
})
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
jest.mock('@onlineapps/conn-orch-api-mapper', () => ({
|
|
52
|
+
create: jest.fn().mockReturnValue({})
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
jest.mock('@onlineapps/conn-orch-cookbook', () => ({}));
|
|
56
|
+
jest.mock('@onlineapps/conn-base-cache', () => jest.fn());
|
|
57
|
+
jest.mock('@onlineapps/conn-infra-error-handler', () => jest.fn());
|
|
58
|
+
|
|
59
|
+
ServiceWrapper = require('../src/ServiceWrapper');
|
|
60
|
+
express = require('express');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should initialize monitoring on start', async () => {
|
|
64
|
+
const app = express();
|
|
65
|
+
const monitoring = require('@onlineapps/conn-base-monitoring');
|
|
66
|
+
|
|
67
|
+
const wrapper = new ServiceWrapper({
|
|
68
|
+
service: app,
|
|
69
|
+
serviceName: 'test-service',
|
|
70
|
+
openApiSpec: { info: { version: '1.0.0' } },
|
|
71
|
+
config: {}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
await wrapper.start();
|
|
75
|
+
|
|
76
|
+
expect(monitoring.init).toHaveBeenCalledWith({
|
|
77
|
+
serviceName: 'test-service'
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(wrapper.logger).toBeDefined();
|
|
81
|
+
expect(wrapper.monitoring).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('should use monitoring for logging', async () => {
|
|
85
|
+
const app = express();
|
|
86
|
+
const wrapper = new ServiceWrapper({
|
|
87
|
+
service: app,
|
|
88
|
+
serviceName: 'test-service',
|
|
89
|
+
openApiSpec: { info: { version: '1.0.0' } },
|
|
90
|
+
config: {}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
await wrapper.start();
|
|
94
|
+
|
|
95
|
+
// Test logger methods are available
|
|
96
|
+
expect(wrapper.logger.info).toBeDefined();
|
|
97
|
+
expect(wrapper.logger.error).toBeDefined();
|
|
98
|
+
expect(wrapper.logger.warn).toBeDefined();
|
|
99
|
+
expect(wrapper.logger.debug).toBeDefined();
|
|
100
|
+
|
|
101
|
+
// Test logger is used
|
|
102
|
+
wrapper.logger.info('Test message', { data: 'test' });
|
|
103
|
+
wrapper.logger.error('Error message', { error: 'test' });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('should pass monitoring to orchestrator', async () => {
|
|
107
|
+
const app = express();
|
|
108
|
+
const OrchestratorConnector = require('@onlineapps/conn-orch-orchestrator');
|
|
109
|
+
|
|
110
|
+
const wrapper = new ServiceWrapper({
|
|
111
|
+
service: app,
|
|
112
|
+
serviceName: 'test-service',
|
|
113
|
+
openApiSpec: { info: { version: '1.0.0' } },
|
|
114
|
+
config: {}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
await wrapper.start();
|
|
118
|
+
|
|
119
|
+
expect(OrchestratorConnector.create).toHaveBeenCalledWith(
|
|
120
|
+
expect.objectContaining({
|
|
121
|
+
logger: expect.objectContaining({
|
|
122
|
+
info: expect.any(Function),
|
|
123
|
+
error: expect.any(Function),
|
|
124
|
+
warn: expect.any(Function),
|
|
125
|
+
debug: expect.any(Function)
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('should handle monitoring mode from config', async () => {
|
|
132
|
+
const app = express();
|
|
133
|
+
const monitoring = require('@onlineapps/conn-base-monitoring');
|
|
134
|
+
|
|
135
|
+
const wrapper = new ServiceWrapper({
|
|
136
|
+
service: app,
|
|
137
|
+
serviceName: 'test-service',
|
|
138
|
+
openApiSpec: { info: { version: '1.0.0' } },
|
|
139
|
+
config: {
|
|
140
|
+
monitoringMode: 'debug'
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await wrapper.start();
|
|
145
|
+
|
|
146
|
+
// Monitoring should be initialized but mode is not passed
|
|
147
|
+
// because ServiceWrapper doesn't pass it through yet
|
|
148
|
+
expect(monitoring.init).toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
});
|