@app-connect/core 1.7.0-beta.3 → 1.7.0-beta.5
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 +77 -77
- package/{adapter → connector}/registry.js +66 -66
- package/handlers/admin.js +14 -4
- package/handlers/auth.js +8 -5
- package/handlers/contact.js +4 -4
- package/handlers/disposition.js +3 -3
- package/handlers/log.js +5 -5
- package/handlers/user.js +2 -2
- package/index.js +36 -36
- package/lib/analytics.js +3 -3
- package/lib/callLogComposer.js +2 -2
- package/lib/oauth.js +2 -2
- package/models/adminConfigModel.js +1 -0
- package/package.json +1 -1
- package/test/adapter/registry.test.js +109 -109
- package/test/handlers/auth.test.js +21 -21
- package/test/setup.js +9 -9
- /package/{adapter → connector}/mock.js +0 -0
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
const
|
|
1
|
+
const connectorRegistry = require('../../connector/registry');
|
|
2
2
|
|
|
3
|
-
describe('
|
|
3
|
+
describe('ConnectorRegistry Interface Registration with Composition', () => {
|
|
4
4
|
beforeEach(() => {
|
|
5
5
|
// Clear the registry before each test
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
connectorRegistry.connectors.clear();
|
|
7
|
+
connectorRegistry.manifests.clear();
|
|
8
|
+
connectorRegistry.platformInterfaces.clear();
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
test('should register interface functions for a platform', () => {
|
|
12
12
|
const mockFunction = jest.fn();
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'testInterface', mockFunction);
|
|
15
15
|
|
|
16
|
-
expect(
|
|
17
|
-
expect(
|
|
16
|
+
expect(connectorRegistry.hasPlatformInterface('testPlatform', 'testInterface')).toBe(true);
|
|
17
|
+
expect(connectorRegistry.getPlatformInterfaces('testPlatform').get('testInterface')).toBe(mockFunction);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
test('should throw error when registering non-function as interface', () => {
|
|
21
21
|
expect(() => {
|
|
22
|
-
|
|
22
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'testInterface', 'not a function');
|
|
23
23
|
}).toThrow('Interface function must be a function, got: string');
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
test('should return original
|
|
27
|
-
const
|
|
26
|
+
test('should return original connector when no interfaces are registered', () => {
|
|
27
|
+
const mockConnector = {
|
|
28
28
|
getAuthType: () => 'apiKey',
|
|
29
29
|
createCallLog: jest.fn(),
|
|
30
30
|
updateCallLog: jest.fn()
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
connectorRegistry.registerConnector('testPlatform', mockConnector);
|
|
34
34
|
|
|
35
|
-
const
|
|
36
|
-
expect(
|
|
35
|
+
const retrievedConnector = connectorRegistry.getConnector('testPlatform');
|
|
36
|
+
expect(retrievedConnector).toBe(mockConnector);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
test('should return composed
|
|
39
|
+
test('should return composed connector with interface functions when interfaces are registered', () => {
|
|
40
40
|
const mockInterface = jest.fn();
|
|
41
|
-
const
|
|
41
|
+
const mockConnector = {
|
|
42
42
|
getAuthType: () => 'apiKey',
|
|
43
43
|
createCallLog: jest.fn(),
|
|
44
44
|
updateCallLog: jest.fn()
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
// Register interface function first
|
|
48
|
-
|
|
48
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'customMethod', mockInterface);
|
|
49
49
|
|
|
50
|
-
// Register
|
|
51
|
-
|
|
50
|
+
// Register connector
|
|
51
|
+
connectorRegistry.registerConnector('testPlatform', mockConnector);
|
|
52
52
|
|
|
53
|
-
// Get composed
|
|
54
|
-
const
|
|
53
|
+
// Get composed connector
|
|
54
|
+
const composedConnector = connectorRegistry.getConnector('testPlatform');
|
|
55
55
|
|
|
56
56
|
// Should be a different object (composed)
|
|
57
|
-
expect(
|
|
57
|
+
expect(composedConnector).not.toBe(mockConnector);
|
|
58
58
|
|
|
59
59
|
// Should have the interface function
|
|
60
|
-
expect(
|
|
60
|
+
expect(composedConnector.customMethod).toBe(mockInterface);
|
|
61
61
|
|
|
62
62
|
// Should still have original methods
|
|
63
|
-
expect(
|
|
64
|
-
expect(
|
|
63
|
+
expect(composedConnector.getAuthType).toBe(mockConnector.getAuthType);
|
|
64
|
+
expect(composedConnector.createCallLog).toBe(mockConnector.createCallLog);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
test('should not override existing
|
|
67
|
+
test('should not override existing connector methods when composing interfaces', () => {
|
|
68
68
|
const existingMethod = jest.fn();
|
|
69
|
-
const
|
|
69
|
+
const mockConnector = {
|
|
70
70
|
getAuthType: () => 'apiKey',
|
|
71
71
|
createCallLog: jest.fn(),
|
|
72
72
|
updateCallLog: jest.fn(),
|
|
73
73
|
existingMethod: existingMethod
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
// Register
|
|
77
|
-
|
|
76
|
+
// Register connector first
|
|
77
|
+
connectorRegistry.registerConnector('testPlatform', mockConnector);
|
|
78
78
|
|
|
79
79
|
// Try to register interface with same name as existing method
|
|
80
80
|
const newMethod = jest.fn();
|
|
81
|
-
|
|
81
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'existingMethod', newMethod);
|
|
82
82
|
|
|
83
|
-
// Get composed
|
|
84
|
-
const
|
|
83
|
+
// Get composed connector
|
|
84
|
+
const composedConnector = connectorRegistry.getConnector('testPlatform');
|
|
85
85
|
|
|
86
86
|
// Should not override the existing method
|
|
87
|
-
expect(
|
|
88
|
-
expect(
|
|
87
|
+
expect(composedConnector.existingMethod).toBe(existingMethod);
|
|
88
|
+
expect(composedConnector.existingMethod).not.toBe(newMethod);
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
test('should preserve original
|
|
91
|
+
test('should preserve original connector when composing interfaces', () => {
|
|
92
92
|
const mockInterface = jest.fn();
|
|
93
|
-
const
|
|
93
|
+
const mockConnector = {
|
|
94
94
|
getAuthType: () => 'apiKey',
|
|
95
95
|
createCallLog: jest.fn(),
|
|
96
96
|
updateCallLog: jest.fn()
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'customMethod', mockInterface);
|
|
100
|
+
connectorRegistry.registerConnector('testPlatform', mockConnector);
|
|
101
101
|
|
|
102
|
-
// Get original
|
|
103
|
-
const
|
|
102
|
+
// Get original connector
|
|
103
|
+
const originalConnector = connectorRegistry.getOriginalConnector('testPlatform');
|
|
104
104
|
|
|
105
|
-
// Original
|
|
106
|
-
expect(
|
|
107
|
-
expect(
|
|
105
|
+
// Original connector should be unchanged
|
|
106
|
+
expect(originalConnector).toBe(mockConnector);
|
|
107
|
+
expect(originalConnector.customMethod).toBeUndefined();
|
|
108
108
|
|
|
109
|
-
// Composed
|
|
110
|
-
const
|
|
111
|
-
expect(
|
|
109
|
+
// Composed connector should have the interface
|
|
110
|
+
const composedConnector = connectorRegistry.getConnector('testPlatform');
|
|
111
|
+
expect(composedConnector.customMethod).toBe(mockInterface);
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
test('should unregister interface functions', () => {
|
|
115
115
|
const mockFunction = jest.fn();
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
expect(
|
|
117
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'testInterface', mockFunction);
|
|
118
|
+
expect(connectorRegistry.hasPlatformInterface('testPlatform', 'testInterface')).toBe(true);
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
expect(
|
|
120
|
+
connectorRegistry.unregisterConnectorInterface('testPlatform', 'testInterface');
|
|
121
|
+
expect(connectorRegistry.hasPlatformInterface('testPlatform', 'testInterface')).toBe(false);
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
test('should return empty map for non-existent platform interfaces', () => {
|
|
125
|
-
const interfaces =
|
|
125
|
+
const interfaces = connectorRegistry.getPlatformInterfaces('nonExistentPlatform');
|
|
126
126
|
expect(interfaces).toBeInstanceOf(Map);
|
|
127
127
|
expect(interfaces.size).toBe(0);
|
|
128
128
|
});
|
|
129
129
|
|
|
130
130
|
test('should return false for non-existent platform interface', () => {
|
|
131
|
-
expect(
|
|
131
|
+
expect(connectorRegistry.hasPlatformInterface('nonExistentPlatform', 'anyInterface')).toBe(false);
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
test('should handle multiple interface functions for same platform', () => {
|
|
135
135
|
const mockFunction1 = jest.fn();
|
|
136
136
|
const mockFunction2 = jest.fn();
|
|
137
|
-
const
|
|
137
|
+
const mockConnector = {
|
|
138
138
|
getAuthType: () => 'apiKey',
|
|
139
139
|
createCallLog: jest.fn(),
|
|
140
140
|
updateCallLog: jest.fn()
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'interface1', mockFunction1);
|
|
144
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'interface2', mockFunction2);
|
|
145
|
+
connectorRegistry.registerConnector('testPlatform', mockConnector);
|
|
146
146
|
|
|
147
|
-
const platformInterfaces =
|
|
147
|
+
const platformInterfaces = connectorRegistry.getPlatformInterfaces('testPlatform');
|
|
148
148
|
expect(platformInterfaces.size).toBe(2);
|
|
149
149
|
expect(platformInterfaces.get('interface1')).toBe(mockFunction1);
|
|
150
150
|
expect(platformInterfaces.get('interface2')).toBe(mockFunction2);
|
|
151
151
|
|
|
152
|
-
// Check composed
|
|
153
|
-
const
|
|
154
|
-
expect(
|
|
155
|
-
expect(
|
|
152
|
+
// Check composed connector has both interfaces
|
|
153
|
+
const composedConnector = connectorRegistry.getConnector('testPlatform');
|
|
154
|
+
expect(composedConnector.interface1).toBe(mockFunction1);
|
|
155
|
+
expect(composedConnector.interface2).toBe(mockFunction2);
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
test('should clean up platform interfaces when unregistering
|
|
158
|
+
test('should clean up platform interfaces when unregistering connector', () => {
|
|
159
159
|
const mockFunction = jest.fn();
|
|
160
|
-
const
|
|
160
|
+
const mockConnector = {
|
|
161
161
|
getAuthType: () => 'apiKey',
|
|
162
162
|
createCallLog: jest.fn(),
|
|
163
163
|
updateCallLog: jest.fn()
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'testInterface', mockFunction);
|
|
167
|
+
connectorRegistry.registerConnector('testPlatform', mockConnector);
|
|
168
168
|
|
|
169
|
-
expect(
|
|
169
|
+
expect(connectorRegistry.hasPlatformInterface('testPlatform', 'testInterface')).toBe(true);
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
connectorRegistry.unregisterConnector('testPlatform');
|
|
172
172
|
|
|
173
|
-
expect(
|
|
173
|
+
expect(connectorRegistry.hasPlatformInterface('testPlatform', 'testInterface')).toBe(false);
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
-
test('should get
|
|
176
|
+
test('should get connector capabilities correctly', () => {
|
|
177
177
|
const mockInterface = jest.fn();
|
|
178
|
-
const
|
|
178
|
+
const mockConnector = {
|
|
179
179
|
getAuthType: () => 'apiKey',
|
|
180
180
|
createCallLog: jest.fn(),
|
|
181
181
|
updateCallLog: jest.fn()
|
|
182
182
|
};
|
|
183
183
|
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'customMethod', mockInterface);
|
|
185
|
+
connectorRegistry.registerConnector('testPlatform', mockConnector);
|
|
186
186
|
|
|
187
|
-
const capabilities =
|
|
187
|
+
const capabilities = connectorRegistry.getConnectorCapabilities('testPlatform');
|
|
188
188
|
|
|
189
189
|
expect(capabilities.platform).toBe('testPlatform');
|
|
190
190
|
expect(capabilities.originalMethods).toContain('getAuthType');
|
|
@@ -195,77 +195,77 @@ describe('AdapterRegistry Interface Registration with Composition', () => {
|
|
|
195
195
|
expect(capabilities.authType).toBe('apiKey');
|
|
196
196
|
});
|
|
197
197
|
|
|
198
|
-
test('should handle interface registration after
|
|
199
|
-
const
|
|
198
|
+
test('should handle interface registration after connector registration', () => {
|
|
199
|
+
const mockConnector = {
|
|
200
200
|
getAuthType: () => 'apiKey',
|
|
201
201
|
createCallLog: jest.fn(),
|
|
202
202
|
updateCallLog: jest.fn()
|
|
203
203
|
};
|
|
204
204
|
|
|
205
|
-
// Register
|
|
206
|
-
|
|
205
|
+
// Register connector first
|
|
206
|
+
connectorRegistry.registerConnector('testPlatform', mockConnector);
|
|
207
207
|
|
|
208
208
|
// Register interface function after
|
|
209
209
|
const mockInterface = jest.fn();
|
|
210
|
-
|
|
210
|
+
connectorRegistry.registerConnectorInterface('testPlatform', 'customMethod', mockInterface);
|
|
211
211
|
|
|
212
|
-
// Get composed
|
|
213
|
-
const
|
|
212
|
+
// Get composed connector
|
|
213
|
+
const composedConnector = connectorRegistry.getConnector('testPlatform');
|
|
214
214
|
|
|
215
215
|
// Should have the interface function
|
|
216
|
-
expect(
|
|
216
|
+
expect(composedConnector.customMethod).toBe(mockInterface);
|
|
217
217
|
|
|
218
|
-
// Original
|
|
219
|
-
const
|
|
220
|
-
expect(
|
|
218
|
+
// Original connector should be unchanged
|
|
219
|
+
const originalConnector = connectorRegistry.getOriginalConnector('testPlatform');
|
|
220
|
+
expect(originalConnector.customMethod).toBeUndefined();
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
-
test('should return interface-only
|
|
223
|
+
test('should return interface-only connector when no base connector is registered', () => {
|
|
224
224
|
const mockInterface1 = jest.fn();
|
|
225
225
|
const mockInterface2 = jest.fn();
|
|
226
226
|
|
|
227
|
-
// Register only interface functions, no base
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
// Register only interface functions, no base connector
|
|
228
|
+
connectorRegistry.registerConnectorInterface('interfaceOnlyPlatform', 'method1', mockInterface1);
|
|
229
|
+
connectorRegistry.registerConnectorInterface('interfaceOnlyPlatform', 'method2', mockInterface2);
|
|
230
230
|
|
|
231
|
-
// Get
|
|
232
|
-
const
|
|
231
|
+
// Get connector - should return interface-only object
|
|
232
|
+
const interfaceOnlyConnector = connectorRegistry.getConnector('interfaceOnlyPlatform');
|
|
233
233
|
|
|
234
234
|
// Should have interface functions
|
|
235
|
-
expect(
|
|
236
|
-
expect(
|
|
235
|
+
expect(interfaceOnlyConnector.method1).toBe(mockInterface1);
|
|
236
|
+
expect(interfaceOnlyConnector.method2).toBe(mockInterface2);
|
|
237
237
|
|
|
238
|
-
// Should not have base
|
|
239
|
-
expect(
|
|
238
|
+
// Should not have base connector methods
|
|
239
|
+
expect(interfaceOnlyConnector.getAuthType).toBeUndefined();
|
|
240
240
|
|
|
241
|
-
// Should be a plain object, not inherited from any
|
|
242
|
-
expect(Object.getPrototypeOf(
|
|
241
|
+
// Should be a plain object, not inherited from any connector
|
|
242
|
+
expect(Object.getPrototypeOf(interfaceOnlyConnector)).toBe(Object.prototype);
|
|
243
243
|
});
|
|
244
244
|
|
|
245
|
-
test('should throw error when no
|
|
245
|
+
test('should throw error when no connector and no interfaces are registered', () => {
|
|
246
246
|
expect(() => {
|
|
247
|
-
|
|
248
|
-
}).toThrow('
|
|
247
|
+
connectorRegistry.getConnector('nonExistentPlatform');
|
|
248
|
+
}).toThrow('Connector not found for platform: nonExistentPlatform');
|
|
249
249
|
});
|
|
250
250
|
|
|
251
251
|
test('should handle mixed scenarios correctly', () => {
|
|
252
|
-
// Scenario 1: Only interfaces, no
|
|
253
|
-
|
|
254
|
-
const interfaceOnly =
|
|
252
|
+
// Scenario 1: Only interfaces, no connector
|
|
253
|
+
connectorRegistry.registerConnectorInterface('mixedPlatform', 'interfaceMethod', jest.fn());
|
|
254
|
+
const interfaceOnly = connectorRegistry.getConnector('mixedPlatform');
|
|
255
255
|
expect(interfaceOnly.interfaceMethod).toBeDefined();
|
|
256
256
|
expect(interfaceOnly.getAuthType).toBeUndefined();
|
|
257
257
|
|
|
258
|
-
// Scenario 2: Add
|
|
259
|
-
const
|
|
258
|
+
// Scenario 2: Add connector later
|
|
259
|
+
const mockConnector = {
|
|
260
260
|
getAuthType: () => 'apiKey',
|
|
261
261
|
createCallLog: jest.fn(),
|
|
262
262
|
updateCallLog: jest.fn()
|
|
263
263
|
};
|
|
264
|
-
|
|
264
|
+
connectorRegistry.registerConnector('mixedPlatform', mockConnector);
|
|
265
265
|
|
|
266
|
-
const
|
|
267
|
-
expect(
|
|
268
|
-
expect(
|
|
269
|
-
expect(
|
|
266
|
+
const composedConnector = connectorRegistry.getConnector('mixedPlatform');
|
|
267
|
+
expect(composedConnector.interfaceMethod).toBeDefined();
|
|
268
|
+
expect(composedConnector.getAuthType).toBeDefined();
|
|
269
|
+
expect(composedConnector.getAuthType()).toBe('apiKey');
|
|
270
270
|
});
|
|
271
271
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
const authHandler = require('../../handlers/auth');
|
|
2
|
-
const
|
|
2
|
+
const connectorRegistry = require('../../connector/registry');
|
|
3
3
|
|
|
4
|
-
// Mock the
|
|
5
|
-
jest.mock('../../
|
|
4
|
+
// Mock the connector registry
|
|
5
|
+
jest.mock('../../connector/registry');
|
|
6
6
|
|
|
7
7
|
describe('Auth Handler', () => {
|
|
8
8
|
beforeEach(() => {
|
|
9
9
|
// Reset mocks
|
|
10
10
|
jest.clearAllMocks();
|
|
11
|
-
global.testUtils.
|
|
11
|
+
global.testUtils.resetConnectorRegistry();
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
describe('onApiKeyLogin', () => {
|
|
@@ -30,12 +30,12 @@ describe('Auth Handler', () => {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
const mockConnector = global.testUtils.createMockConnector({
|
|
34
34
|
getBasicAuth: jest.fn().mockReturnValue('dGVzdC1hcGkta2V5Og=='),
|
|
35
35
|
getUserInfo: jest.fn().mockResolvedValue(mockUserInfo)
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
39
39
|
|
|
40
40
|
const requestData = {
|
|
41
41
|
platform: 'testCRM',
|
|
@@ -52,8 +52,8 @@ describe('Auth Handler', () => {
|
|
|
52
52
|
expect(result.userInfo.id).toBe('test-user-id');
|
|
53
53
|
expect(result.userInfo.name).toBe('Test User');
|
|
54
54
|
expect(result.returnMessage).toEqual(mockUserInfo.returnMessage);
|
|
55
|
-
expect(
|
|
56
|
-
expect(
|
|
55
|
+
expect(mockConnector.getBasicAuth).toHaveBeenCalledWith({ apiKey: 'test-api-key' });
|
|
56
|
+
expect(mockConnector.getUserInfo).toHaveBeenCalledWith({
|
|
57
57
|
authHeader: 'Basic dGVzdC1hcGkta2V5Og==',
|
|
58
58
|
hostname: 'test.example.com',
|
|
59
59
|
additionalInfo: {},
|
|
@@ -73,12 +73,12 @@ describe('Auth Handler', () => {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
const
|
|
76
|
+
const mockConnector = global.testUtils.createMockConnector({
|
|
77
77
|
getBasicAuth: jest.fn().mockReturnValue('dGVzdC1hcGkta2V5Og=='),
|
|
78
78
|
getUserInfo: jest.fn().mockResolvedValue(mockUserInfo)
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
82
82
|
|
|
83
83
|
const requestData = {
|
|
84
84
|
platform: 'testCRM',
|
|
@@ -95,10 +95,10 @@ describe('Auth Handler', () => {
|
|
|
95
95
|
expect(result.returnMessage).toEqual(mockUserInfo.returnMessage);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
test('should throw error when
|
|
98
|
+
test('should throw error when connector not found', async () => {
|
|
99
99
|
// Arrange
|
|
100
|
-
|
|
101
|
-
throw new Error('
|
|
100
|
+
connectorRegistry.getConnector.mockImplementation(() => {
|
|
101
|
+
throw new Error('Connector not found for platform: testCRM');
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
const requestData = {
|
|
@@ -110,7 +110,7 @@ describe('Auth Handler', () => {
|
|
|
110
110
|
|
|
111
111
|
// Act & Assert
|
|
112
112
|
await expect(authHandler.onApiKeyLogin(requestData))
|
|
113
|
-
.rejects.toThrow('
|
|
113
|
+
.rejects.toThrow('Connector not found for platform: testCRM');
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
|
|
@@ -128,12 +128,12 @@ describe('Auth Handler', () => {
|
|
|
128
128
|
status: 200
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
-
const
|
|
131
|
+
const mockConnector = global.testUtils.createMockConnector({
|
|
132
132
|
getOauthInfo: jest.fn().mockResolvedValue({}),
|
|
133
133
|
authValidation: jest.fn().mockResolvedValue(mockValidationResponse)
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
137
137
|
|
|
138
138
|
// Mock UserModel.findOne to return a user
|
|
139
139
|
const { UserModel } = require('../../models/userModel');
|
|
@@ -156,13 +156,13 @@ describe('Auth Handler', () => {
|
|
|
156
156
|
...mockValidationResponse,
|
|
157
157
|
failReason: ''
|
|
158
158
|
});
|
|
159
|
-
expect(
|
|
159
|
+
expect(mockConnector.authValidation).toHaveBeenCalledWith({ user: mockUser });
|
|
160
160
|
});
|
|
161
161
|
|
|
162
162
|
test('should handle user not found in database', async () => {
|
|
163
163
|
// Arrange
|
|
164
|
-
const
|
|
165
|
-
|
|
164
|
+
const mockConnector = global.testUtils.createMockConnector();
|
|
165
|
+
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
166
166
|
|
|
167
167
|
// Mock UserModel.findOne to return null (user not found)
|
|
168
168
|
const { UserModel } = require('../../models/userModel');
|
|
@@ -197,12 +197,12 @@ describe('Auth Handler', () => {
|
|
|
197
197
|
status: 401
|
|
198
198
|
};
|
|
199
199
|
|
|
200
|
-
const
|
|
200
|
+
const mockConnector = global.testUtils.createMockConnector({
|
|
201
201
|
getOauthInfo: jest.fn().mockResolvedValue({}),
|
|
202
202
|
authValidation: jest.fn().mockResolvedValue(mockValidationResponse)
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
206
206
|
|
|
207
207
|
// Mock UserModel.findOne to return a user
|
|
208
208
|
const { UserModel } = require('../../models/userModel');
|
package/test/setup.js
CHANGED
|
@@ -106,17 +106,17 @@ global.testUtils = {
|
|
|
106
106
|
...overrides
|
|
107
107
|
}),
|
|
108
108
|
|
|
109
|
-
// Helper to reset
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
// Helper to reset connector registry
|
|
110
|
+
resetConnectorRegistry: () => {
|
|
111
|
+
const connectorRegistry = require('../connector/registry');
|
|
112
|
+
connectorRegistry.connectors.clear();
|
|
113
|
+
connectorRegistry.manifests.clear();
|
|
114
|
+
connectorRegistry.platformInterfaces.clear();
|
|
115
|
+
connectorRegistry.releaseNotes = {};
|
|
116
116
|
},
|
|
117
117
|
|
|
118
|
-
// Helper to create mock
|
|
119
|
-
|
|
118
|
+
// Helper to create mock connector
|
|
119
|
+
createMockConnector: (overrides = {}) => ({
|
|
120
120
|
getAuthType: jest.fn().mockReturnValue('apiKey'),
|
|
121
121
|
getUserInfo: jest.fn().mockResolvedValue({
|
|
122
122
|
successful: true,
|
|
File without changes
|