@app-connect/core 1.7.36 → 1.7.38
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 +17 -16
- package/dist/connector/developerPortal.d.ts +6 -0
- package/{connector → dist/connector}/developerPortal.js +29 -12
- package/dist/connector/mock.d.ts +1 -0
- package/{connector → dist/connector}/mock.js +33 -17
- package/dist/connector/proxy/engine.d.ts +10 -0
- package/dist/connector/proxy/engine.js +222 -0
- package/dist/connector/proxy/index.d.ts +5 -0
- package/dist/connector/proxy/index.js +511 -0
- package/dist/connector/registry.d.ts +1 -0
- package/dist/connector/registry.js +243 -0
- package/dist/handlers/admin.d.ts +1 -0
- package/{handlers → dist/handlers}/admin.js +137 -78
- package/dist/handlers/appointment.d.ts +9 -0
- package/{handlers → dist/handlers}/appointment.js +58 -29
- package/dist/handlers/auth.d.ts +9 -0
- package/{handlers → dist/handlers}/auth.js +68 -40
- package/dist/handlers/calldown.d.ts +10 -0
- package/dist/handlers/calldown.js +134 -0
- package/dist/handlers/contact.d.ts +1 -0
- package/{handlers → dist/handlers}/contact.js +61 -39
- package/dist/handlers/disposition.d.ts +1 -0
- package/{handlers → dist/handlers}/disposition.js +20 -10
- package/dist/handlers/log.d.ts +1 -0
- package/{handlers → dist/handlers}/log.js +91 -124
- package/dist/handlers/managedAuth.d.ts +1 -0
- package/{handlers → dist/handlers}/managedAuth.js +134 -61
- package/dist/handlers/managedOAuth.d.ts +13 -0
- package/{handlers → dist/handlers}/managedOAuth.js +102 -30
- package/dist/handlers/plugin.d.ts +1 -0
- package/{handlers → dist/handlers}/plugin.js +59 -27
- package/dist/handlers/user.d.ts +1 -0
- package/{handlers → dist/handlers}/user.js +45 -27
- package/dist/index.d.ts +1 -0
- package/{index.js → dist/index.js} +548 -450
- package/dist/jest.config.d.ts +1 -0
- package/dist/jest.config.js +65 -0
- package/dist/lib/analytics.d.ts +4 -0
- package/{lib → dist/lib}/analytics.js +8 -6
- package/dist/lib/authSession.d.ts +5 -0
- package/{lib → dist/lib}/authSession.js +15 -43
- package/dist/lib/cacheCleanup.d.ts +4 -0
- package/{lib → dist/lib}/cacheCleanup.js +5 -17
- package/dist/lib/callLogComposer.d.ts +109 -0
- package/{lib → dist/lib}/callLogComposer.js +157 -197
- package/dist/lib/callLogLookup.d.ts +6 -0
- package/{lib → dist/lib}/callLogLookup.js +12 -34
- package/dist/lib/constants.d.ts +6 -0
- package/dist/lib/constants.js +9 -0
- package/dist/lib/debugTracer.d.ts +17 -0
- package/{lib → dist/lib}/debugTracer.js +7 -83
- package/dist/lib/encode.d.ts +3 -0
- package/dist/lib/encode.js +50 -0
- package/dist/lib/errorHandler.d.ts +7 -0
- package/dist/lib/errorHandler.js +161 -0
- package/dist/lib/generalErrorMessage.d.ts +7 -0
- package/{lib → dist/lib}/generalErrorMessage.js +6 -6
- package/dist/lib/jwt.d.ts +4 -0
- package/dist/lib/jwt.js +18 -0
- package/dist/lib/logger.d.ts +24 -0
- package/dist/lib/logger.js +126 -0
- package/dist/lib/migrateCallLogsSchema.d.ts +32 -0
- package/dist/lib/migrateCallLogsSchema.js +339 -0
- package/dist/lib/oauth.d.ts +4 -0
- package/{lib → dist/lib}/oauth.js +157 -160
- package/dist/lib/ringcentral.d.ts +24 -0
- package/dist/lib/ringcentral.js +226 -0
- package/dist/lib/s3ErrorLogReport.d.ts +4 -0
- package/{lib → dist/lib}/s3ErrorLogReport.js +11 -23
- package/dist/lib/sharedSMSComposer.d.ts +7 -0
- package/{lib → dist/lib}/sharedSMSComposer.js +21 -107
- package/dist/lib/util.d.ts +7 -0
- package/{lib → dist/lib}/util.js +9 -20
- package/dist/mcp/lib/oauthError.d.ts +1 -0
- package/dist/mcp/lib/oauthError.js +25 -0
- package/dist/mcp/lib/validator.d.ts +1 -0
- package/{mcp → dist/mcp}/lib/validator.js +16 -20
- package/dist/mcp/lib/widgetSessionToken.d.ts +1 -0
- package/dist/mcp/lib/widgetSessionToken.js +46 -0
- package/dist/mcp/mcpHandler.d.ts +8 -0
- package/{mcp → dist/mcp}/mcpHandler.js +98 -88
- package/dist/mcp/tools/cancelAppointment.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/cancelAppointment.js +7 -16
- package/dist/mcp/tools/checkAuthStatus.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/checkAuthStatus.js +21 -14
- package/dist/mcp/tools/confirmAppointment.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/confirmAppointment.js +7 -16
- package/dist/mcp/tools/createAppointment.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/createAppointment.js +7 -19
- package/dist/mcp/tools/createCallLog.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/createCallLog.js +18 -29
- package/dist/mcp/tools/createContact.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/createContact.js +8 -20
- package/dist/mcp/tools/createMessageLog.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/createMessageLog.js +14 -26
- package/dist/mcp/tools/doAuth.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/doAuth.js +17 -13
- package/dist/mcp/tools/findContactByName.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/findContactByName.js +9 -15
- package/dist/mcp/tools/findContactByPhone.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/findContactByPhone.js +8 -15
- package/dist/mcp/tools/getCallLog.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getCallLog.js +12 -21
- package/dist/mcp/tools/getGoogleFilePicker.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getGoogleFilePicker.js +9 -18
- package/dist/mcp/tools/getHelp.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getHelp.js +5 -6
- package/dist/mcp/tools/getPublicConnectors.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getPublicConnectors.js +19 -18
- package/dist/mcp/tools/getSessionInfo.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getSessionInfo.js +10 -16
- package/dist/mcp/tools/index.d.ts +8 -0
- package/dist/mcp/tools/index.js +50 -0
- package/dist/mcp/tools/listAppointments.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/listAppointments.js +7 -19
- package/dist/mcp/tools/logout.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/logout.js +16 -14
- package/dist/mcp/tools/rcGetCallLogs.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/rcGetCallLogs.js +10 -8
- package/dist/mcp/tools/updateAppointment.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/updateAppointment.js +17 -22
- package/dist/mcp/tools/updateCallLog.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/updateCallLog.js +16 -26
- package/dist/models/accountDataModel.d.ts +3 -0
- package/dist/models/accountDataModel.js +39 -0
- package/dist/models/adminConfigModel.d.ts +2 -0
- package/dist/models/adminConfigModel.js +39 -0
- package/dist/models/cacheModel.d.ts +2 -0
- package/{models → dist/models}/cacheModel.js +7 -3
- package/dist/models/callDownListModel.d.ts +2 -0
- package/{models → dist/models}/callDownListModel.js +8 -4
- package/dist/models/callLogModel.d.ts +2 -0
- package/dist/models/callLogModel.js +43 -0
- package/dist/models/dynamo/connectorSchema.d.ts +2 -0
- package/dist/models/dynamo/connectorSchema.js +141 -0
- package/dist/models/dynamo/lockSchema.d.ts +2 -0
- package/{models → dist/models}/dynamo/lockSchema.js +5 -7
- package/dist/models/dynamo/noteCacheSchema.d.ts +2 -0
- package/{models → dist/models}/dynamo/noteCacheSchema.js +4 -6
- package/dist/models/llmSessionModel.d.ts +2 -0
- package/dist/models/llmSessionModel.js +21 -0
- package/dist/models/messageLogModel.d.ts +2 -0
- package/{models → dist/models}/messageLogModel.js +8 -4
- package/dist/models/sequelize.d.ts +2 -0
- package/dist/models/sequelize.js +68 -0
- package/dist/models/userModel.d.ts +2 -0
- package/dist/models/userModel.js +49 -0
- package/dist/package.json +100 -0
- package/dist/releaseNotes.json +1222 -0
- package/dist/tsconfig.json +14 -0
- package/dist/types/admin.d.ts +141 -0
- package/dist/types/analytics.d.ts +14 -0
- package/dist/types/appointment.d.ts +50 -0
- package/dist/types/auth.d.ts +137 -0
- package/dist/types/authSession.d.ts +35 -0
- package/dist/types/cacheCleanup.d.ts +12 -0
- package/dist/types/calldown.d.ts +54 -0
- package/dist/types/common.d.ts +46 -0
- package/dist/types/connector.d.ts +165 -0
- package/dist/types/contact.d.ts +125 -0
- package/dist/types/errorHandler.d.ts +60 -0
- package/dist/types/index.d.ts +76 -0
- package/dist/types/json.d.ts +9 -0
- package/dist/types/jwt.d.ts +8 -0
- package/dist/types/logging.d.ts +224 -0
- package/dist/types/managedAuth.d.ts +114 -0
- package/dist/types/managedOAuth.d.ts +59 -0
- package/dist/types/manifest.d.ts +120 -0
- package/dist/types/migration.d.ts +15 -0
- package/dist/types/plugin.d.ts +74 -0
- package/dist/types/ringcentral.d.ts +61 -0
- package/dist/types/s3ErrorLogReport.d.ts +16 -0
- package/dist/types/sharedSMSComposer.d.ts +105 -0
- package/dist/types/user.d.ts +46 -0
- package/dist/types/util.d.ts +7 -0
- package/package.json +34 -6
- package/releaseNotes.json +13 -1
- package/.env.test +0 -5
- package/connector/proxy/engine.js +0 -165
- package/connector/proxy/index.js +0 -500
- package/connector/registry.js +0 -252
- package/docs/README.md +0 -50
- package/docs/architecture.md +0 -94
- package/docs/connectors.md +0 -116
- package/docs/handlers.md +0 -128
- package/docs/libraries.md +0 -98
- package/docs/models.md +0 -146
- package/docs/routes.md +0 -119
- package/docs/tests.md +0 -73
- package/handlers/calldown.js +0 -99
- package/jest.config.js +0 -57
- package/lib/constants.js +0 -9
- package/lib/encode.js +0 -30
- package/lib/errorHandler.js +0 -218
- package/lib/jwt.js +0 -18
- package/lib/logger.js +0 -190
- package/lib/migrateCallLogsSchema.js +0 -237
- package/lib/ringcentral.js +0 -267
- package/mcp/README.md +0 -420
- package/mcp/tools/index.js +0 -51
- package/mcp/ui/App/App.tsx +0 -358
- package/mcp/ui/App/components/AuthInfoForm.tsx +0 -113
- package/mcp/ui/App/components/AuthSuccess.tsx +0 -22
- package/mcp/ui/App/components/ConnectorList.tsx +0 -82
- package/mcp/ui/App/components/DebugPanel.tsx +0 -43
- package/mcp/ui/App/components/OAuthConnect.tsx +0 -270
- package/mcp/ui/App/lib/callTool.ts +0 -130
- package/mcp/ui/App/lib/debugLog.ts +0 -41
- package/mcp/ui/App/lib/developerPortal.ts +0 -111
- package/mcp/ui/App/main.css +0 -6
- package/mcp/ui/App/root.tsx +0 -13
- package/mcp/ui/dist/index.html +0 -53
- package/mcp/ui/vite.config.ts +0 -16
- package/models/accountDataModel.js +0 -34
- package/models/adminConfigModel.js +0 -35
- package/models/callLogModel.js +0 -39
- package/models/dynamo/connectorSchema.js +0 -146
- package/models/llmSessionModel.js +0 -17
- package/models/sequelize.js +0 -17
- package/models/userModel.js +0 -45
- package/test/connector/developerPortal.test.js +0 -166
- package/test/connector/mock.test.js +0 -131
- package/test/connector/proxy/engine.test.js +0 -211
- package/test/connector/proxy/index.test.js +0 -525
- package/test/connector/proxy/sample.json +0 -162
- package/test/connector/registry.test.js +0 -416
- package/test/handlers/admin.test.js +0 -960
- package/test/handlers/appointment.test.js +0 -260
- package/test/handlers/auth.test.js +0 -1096
- package/test/handlers/calldown.test.js +0 -310
- package/test/handlers/contact.test.js +0 -1014
- package/test/handlers/disposition.test.js +0 -396
- package/test/handlers/log.test.js +0 -1847
- package/test/handlers/managedAuth.test.js +0 -458
- package/test/handlers/managedOAuth.test.js +0 -262
- package/test/handlers/plugin.test.js +0 -429
- package/test/handlers/user.test.js +0 -381
- package/test/index.test.js +0 -301
- package/test/lib/analytics.test.js +0 -146
- package/test/lib/authSession.test.js +0 -173
- package/test/lib/cacheCleanup.test.js +0 -127
- package/test/lib/callLogComposer.test.js +0 -1231
- package/test/lib/debugTracer.test.js +0 -328
- package/test/lib/encode.test.js +0 -59
- package/test/lib/errorHandler.test.js +0 -246
- package/test/lib/generalErrorMessage.test.js +0 -82
- package/test/lib/jwt.test.js +0 -176
- package/test/lib/logger.test.js +0 -206
- package/test/lib/oauth.test.js +0 -359
- package/test/lib/ringcentral.test.js +0 -467
- package/test/lib/s3ErrorLogReport.test.js +0 -187
- package/test/lib/sharedSMSComposer.test.js +0 -1084
- package/test/lib/util.test.js +0 -329
- package/test/mcp/mcpHandler.test.js +0 -73
- package/test/mcp/mcpHandlerMore.test.js +0 -384
- package/test/mcp/tools/appointmentTools.test.js +0 -362
- package/test/mcp/tools/checkAuthStatus.test.js +0 -83
- package/test/mcp/tools/createCallLog.test.js +0 -436
- package/test/mcp/tools/createContact.test.js +0 -58
- package/test/mcp/tools/createMessageLog.test.js +0 -595
- package/test/mcp/tools/doAuth.test.js +0 -113
- package/test/mcp/tools/findContactByName.test.js +0 -275
- package/test/mcp/tools/findContactByPhone.test.js +0 -296
- package/test/mcp/tools/getCallLog.test.js +0 -298
- package/test/mcp/tools/getGoogleFilePicker.test.js +0 -281
- package/test/mcp/tools/getPublicConnectors.test.js +0 -107
- package/test/mcp/tools/getSessionInfo.test.js +0 -127
- package/test/mcp/tools/logout.test.js +0 -233
- package/test/mcp/tools/rcGetCallLogs.test.js +0 -56
- package/test/mcp/tools/updateCallLog.test.js +0 -360
- package/test/models/accountDataModel.test.js +0 -98
- package/test/models/callDownListModel.test.js +0 -125
- package/test/models/dynamo/connectorSchema.test.js +0 -189
- package/test/models/dynamo/lockSchema.test.js +0 -37
- package/test/models/dynamo/noteCacheSchema.test.js +0 -45
- package/test/models/llmSessionModel.test.js +0 -91
- package/test/models/models.test.js +0 -660
- package/test/routes/calldownRoutes.test.js +0 -224
- package/test/routes/coreRouterBroadRoutes.test.js +0 -855
- package/test/routes/dispositionRoutes.test.js +0 -192
- package/test/routes/managedAuthRoutes.test.js +0 -386
- package/test/routes/pluginRoutes.test.js +0 -262
- package/test/setup.js +0 -178
- /package/{mcp → dist/mcp}/ui/index.html +0 -0
- /package/{mcp → dist/mcp}/ui/package-lock.json +0 -0
- /package/{mcp → dist/mcp}/ui/package.json +0 -0
- /package/{mcp → dist/mcp}/ui/tsconfig.json +0 -0
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
jest.mock('axios');
|
|
2
|
-
jest.mock('../../models/adminConfigModel', () => ({
|
|
3
|
-
AdminConfigModel: {
|
|
4
|
-
findByPk: jest.fn()
|
|
5
|
-
}
|
|
6
|
-
}));
|
|
7
|
-
jest.mock('../../models/userModel', () => ({
|
|
8
|
-
UserModel: {
|
|
9
|
-
findOne: jest.fn()
|
|
10
|
-
}
|
|
11
|
-
}));
|
|
12
|
-
jest.mock('../../connector/registry', () => ({
|
|
13
|
-
getConnector: jest.fn()
|
|
14
|
-
}));
|
|
15
|
-
jest.mock('../../lib/oauth', () => ({
|
|
16
|
-
getOAuthApp: jest.fn(() => ({ app: true })),
|
|
17
|
-
checkAndRefreshAccessToken: jest.fn()
|
|
18
|
-
}));
|
|
19
|
-
jest.mock('../../lib/util', () => ({
|
|
20
|
-
getHashValue: jest.fn((value) => `hash-${value}`)
|
|
21
|
-
}));
|
|
22
|
-
jest.mock('../../models/dynamo/connectorSchema', () => ({
|
|
23
|
-
Connector: {
|
|
24
|
-
getProxyConfig: jest.fn()
|
|
25
|
-
}
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
const axios = require('axios');
|
|
29
|
-
const userHandler = require('../../handlers/user');
|
|
30
|
-
const { AdminConfigModel } = require('../../models/adminConfigModel');
|
|
31
|
-
const { UserModel } = require('../../models/userModel');
|
|
32
|
-
const connectorRegistry = require('../../connector/registry');
|
|
33
|
-
const oauth = require('../../lib/oauth');
|
|
34
|
-
const { Connector } = require('../../models/dynamo/connectorSchema');
|
|
35
|
-
|
|
36
|
-
describe('User Handler', () => {
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
jest.clearAllMocks();
|
|
39
|
-
process.env.HASH_KEY = 'hash-key';
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('refreshUserInfo returns warning when user is missing or has no access token', async () => {
|
|
43
|
-
UserModel.findOne.mockResolvedValueOnce(null);
|
|
44
|
-
|
|
45
|
-
await expect(userHandler.refreshUserInfo({
|
|
46
|
-
platform: 'testCRM',
|
|
47
|
-
userId: 'user-1'
|
|
48
|
-
})).resolves.toMatchObject({
|
|
49
|
-
successful: false,
|
|
50
|
-
returnMessage: {
|
|
51
|
-
message: 'User not found',
|
|
52
|
-
messageType: 'warning'
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
UserModel.findOne.mockResolvedValueOnce({ id: 'user-2' });
|
|
57
|
-
const noTokenResult = await userHandler.refreshUserInfo({
|
|
58
|
-
platform: 'testCRM',
|
|
59
|
-
userId: 'user-2'
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
expect(noTokenResult.returnMessage.message).toBe('User not found');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('refreshUserInfo handles oauth proxy config and expired refreshed session', async () => {
|
|
66
|
-
const user = {
|
|
67
|
-
id: 'user-1',
|
|
68
|
-
hostname: 'crm.example.com',
|
|
69
|
-
accessToken: 'expired-token',
|
|
70
|
-
platformAdditionalInfo: {
|
|
71
|
-
proxyId: 'proxy-1',
|
|
72
|
-
tokenUrl: 'https://token.example.com'
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const platformModule = {
|
|
76
|
-
getAuthType: jest.fn().mockResolvedValue('oauth'),
|
|
77
|
-
getOauthInfo: jest.fn().mockResolvedValue({ tokenUrl: 'https://token.example.com' })
|
|
78
|
-
};
|
|
79
|
-
UserModel.findOne.mockResolvedValue(user);
|
|
80
|
-
Connector.getProxyConfig.mockResolvedValue({ id: 'proxy-1' });
|
|
81
|
-
connectorRegistry.getConnector.mockReturnValue(platformModule);
|
|
82
|
-
oauth.checkAndRefreshAccessToken.mockResolvedValue(null);
|
|
83
|
-
|
|
84
|
-
const result = await userHandler.refreshUserInfo({
|
|
85
|
-
platform: 'testCRM',
|
|
86
|
-
userId: 'user-1',
|
|
87
|
-
tracer: {
|
|
88
|
-
trace: jest.fn(),
|
|
89
|
-
traceError: jest.fn()
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
expect(platformModule.getOauthInfo).toHaveBeenCalledWith({
|
|
94
|
-
tokenUrl: 'https://token.example.com',
|
|
95
|
-
hostname: 'crm.example.com',
|
|
96
|
-
proxyId: 'proxy-1',
|
|
97
|
-
proxyConfig: { id: 'proxy-1' }
|
|
98
|
-
});
|
|
99
|
-
expect(result).toMatchObject({
|
|
100
|
-
successful: false,
|
|
101
|
-
isRevokeUserSession: true,
|
|
102
|
-
returnMessage: {
|
|
103
|
-
message: 'User session expired. Please connect again.'
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('refreshUserInfo supports apiKey auth and maps platform result', async () => {
|
|
109
|
-
const user = {
|
|
110
|
-
id: 'user-1',
|
|
111
|
-
hostname: 'crm.example.com',
|
|
112
|
-
accessToken: 'api-key',
|
|
113
|
-
platformAdditionalInfo: {}
|
|
114
|
-
};
|
|
115
|
-
const platformModule = {
|
|
116
|
-
getAuthType: jest.fn().mockResolvedValue('apiKey'),
|
|
117
|
-
getBasicAuth: jest.fn(() => 'encoded-key'),
|
|
118
|
-
refreshUserInfo: jest.fn().mockResolvedValue({
|
|
119
|
-
successful: true,
|
|
120
|
-
returnMessage: {
|
|
121
|
-
messageType: 'success',
|
|
122
|
-
message: 'Refreshed'
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
};
|
|
126
|
-
UserModel.findOne.mockResolvedValue(user);
|
|
127
|
-
connectorRegistry.getConnector.mockReturnValue(platformModule);
|
|
128
|
-
|
|
129
|
-
const result = await userHandler.refreshUserInfo({
|
|
130
|
-
platform: 'testCRM',
|
|
131
|
-
userId: 'user-1'
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
expect(platformModule.refreshUserInfo).toHaveBeenCalledWith({
|
|
135
|
-
user,
|
|
136
|
-
authHeader: 'Basic encoded-key',
|
|
137
|
-
proxyConfig: null
|
|
138
|
-
});
|
|
139
|
-
expect(result.successful).toBe(true);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('refreshUserInfo maps unexpected errors through API error handler', async () => {
|
|
143
|
-
UserModel.findOne.mockRejectedValueOnce(new Error('database unavailable'));
|
|
144
|
-
|
|
145
|
-
const result = await userHandler.refreshUserInfo({
|
|
146
|
-
platform: 'testCRM',
|
|
147
|
-
userId: 'user-1'
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
expect(result.successful).toBe(false);
|
|
151
|
-
expect(result.returnMessage.messageType).toBe('warning');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test('getUserSettingsByAdmin resolves account from explicit account id or RC token', async () => {
|
|
155
|
-
AdminConfigModel.findByPk.mockResolvedValueOnce({
|
|
156
|
-
userSettings: {
|
|
157
|
-
theme: { value: 'dark' }
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
await expect(userHandler.getUserSettingsByAdmin({
|
|
162
|
-
rcAccountId: 'hashed-account'
|
|
163
|
-
})).resolves.toEqual({
|
|
164
|
-
userSettings: {
|
|
165
|
-
theme: { value: 'dark' }
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
expect(AdminConfigModel.findByPk).toHaveBeenCalledWith('hashed-account');
|
|
169
|
-
|
|
170
|
-
axios.get.mockResolvedValueOnce({
|
|
171
|
-
data: {
|
|
172
|
-
account: {
|
|
173
|
-
id: 'rc-account-1'
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
AdminConfigModel.findByPk.mockResolvedValueOnce({
|
|
178
|
-
userSettings: {
|
|
179
|
-
language: { value: 'en' }
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const result = await userHandler.getUserSettingsByAdmin({
|
|
184
|
-
rcAccessToken: 'rc-token'
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
expect(axios.get).toHaveBeenCalledWith(
|
|
188
|
-
'https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~',
|
|
189
|
-
{
|
|
190
|
-
headers: {
|
|
191
|
-
Authorization: 'Bearer rc-token'
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
expect(AdminConfigModel.findByPk).toHaveBeenLastCalledWith('hash-rc-account-1');
|
|
196
|
-
expect(result.userSettings.language.value).toBe('en');
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
test('getUserSettings merges admin defaults, user overrides, removed keys, and plugin config rules', async () => {
|
|
200
|
-
AdminConfigModel.findByPk.mockResolvedValueOnce({
|
|
201
|
-
userSettings: {
|
|
202
|
-
removedSetting: { isRemoved: true, value: 'hidden' },
|
|
203
|
-
adminOnly: { value: 'admin-only', customizable: false },
|
|
204
|
-
userEditable: { value: 'admin-default', customizable: true },
|
|
205
|
-
plugin_sample: {
|
|
206
|
-
customizable: true,
|
|
207
|
-
value: {
|
|
208
|
-
config: {
|
|
209
|
-
locked: { value: 'admin-locked', customizable: false },
|
|
210
|
-
fillsEmpty: { value: 'admin-fill', customizable: true },
|
|
211
|
-
staysUserEditable: { value: 'admin-stay', customizable: true }
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
plugin_empty: {
|
|
216
|
-
customizable: true,
|
|
217
|
-
value: {
|
|
218
|
-
config: {
|
|
219
|
-
adminProvided: { value: 'admin-provided', customizable: true }
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
plugin_deleted: {
|
|
224
|
-
customizable: true,
|
|
225
|
-
value: {
|
|
226
|
-
config: null
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const result = await userHandler.getUserSettings({
|
|
233
|
-
user: {
|
|
234
|
-
userSettings: {
|
|
235
|
-
removedSetting: { value: 'user-hidden' },
|
|
236
|
-
userEditable: { value: 'user-value', defaultValue: 'user-default', options: ['a'] },
|
|
237
|
-
userOnly: { value: 'user-only' },
|
|
238
|
-
plugin_sample: {
|
|
239
|
-
value: {
|
|
240
|
-
config: {
|
|
241
|
-
locked: { value: 'user-locked', customizable: true },
|
|
242
|
-
fillsEmpty: { value: '', customizable: true },
|
|
243
|
-
staysUserEditable: { value: 'user-stay', customizable: true }
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
plugin_empty: {
|
|
248
|
-
value: {
|
|
249
|
-
config: {}
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
plugin_deleted: {
|
|
253
|
-
value: {
|
|
254
|
-
config: {}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
rcAccountId: 'hashed-account'
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
expect(result.removedSetting).toBeUndefined();
|
|
263
|
-
expect(result.adminOnly.value).toBe('admin-only');
|
|
264
|
-
expect(result.userOnly.value).toBe('user-only');
|
|
265
|
-
expect(result.userEditable).toEqual({
|
|
266
|
-
customizable: true,
|
|
267
|
-
value: 'user-value',
|
|
268
|
-
defaultValue: 'user-default',
|
|
269
|
-
options: ['a']
|
|
270
|
-
});
|
|
271
|
-
expect(result.plugin_sample.value.config.locked.value).toBe('admin-locked');
|
|
272
|
-
expect(result.plugin_sample.value.config.fillsEmpty.value).toBe('admin-fill');
|
|
273
|
-
expect(result.plugin_sample.value.config.staysUserEditable).toMatchObject({
|
|
274
|
-
value: 'user-stay',
|
|
275
|
-
customizable: true
|
|
276
|
-
});
|
|
277
|
-
expect(result.plugin_empty.value.config.adminProvided.value).toBe('admin-provided');
|
|
278
|
-
expect(result.plugin_deleted).toBeUndefined();
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
test('getUserSettings falls back to user settings when admin lookup fails', async () => {
|
|
282
|
-
AdminConfigModel.findByPk.mockRejectedValueOnce(new Error('admin settings unavailable'));
|
|
283
|
-
|
|
284
|
-
const result = await userHandler.getUserSettings({
|
|
285
|
-
user: {
|
|
286
|
-
userSettings: {
|
|
287
|
-
localOnly: { value: 'local' }
|
|
288
|
-
}
|
|
289
|
-
},
|
|
290
|
-
rcAccountId: 'hashed-account'
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
expect(result).toEqual({
|
|
294
|
-
localOnly: { value: 'local' }
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test('updateUserSettings supports connector hooks, removals, and database error mapping', async () => {
|
|
299
|
-
const user = {
|
|
300
|
-
userSettings: {
|
|
301
|
-
oldKey: { value: 'old' },
|
|
302
|
-
removeMe: { value: 'remove' }
|
|
303
|
-
},
|
|
304
|
-
update: jest.fn().mockImplementation(async function update(values) {
|
|
305
|
-
user.userSettings = values.userSettings;
|
|
306
|
-
})
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
connectorRegistry.getConnector.mockReturnValueOnce({});
|
|
310
|
-
const defaultResult = await userHandler.updateUserSettings({
|
|
311
|
-
user,
|
|
312
|
-
userSettings: {
|
|
313
|
-
newKey: { value: 'new' }
|
|
314
|
-
},
|
|
315
|
-
settingKeysToRemove: ['removeMe'],
|
|
316
|
-
platformName: 'testCRM'
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
expect(defaultResult.userSettings).toEqual({
|
|
320
|
-
oldKey: { value: 'old' },
|
|
321
|
-
newKey: { value: 'new' }
|
|
322
|
-
});
|
|
323
|
-
expect(user.update).toHaveBeenCalledWith({
|
|
324
|
-
userSettings: {
|
|
325
|
-
oldKey: { value: 'old' },
|
|
326
|
-
newKey: { value: 'new' }
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
const hookUser = {
|
|
331
|
-
userSettings: {},
|
|
332
|
-
update: jest.fn()
|
|
333
|
-
};
|
|
334
|
-
connectorRegistry.getConnector.mockReturnValueOnce({
|
|
335
|
-
onUpdateUserSettings: jest.fn().mockResolvedValue({
|
|
336
|
-
successful: false,
|
|
337
|
-
returnMessage: {
|
|
338
|
-
messageType: 'warning',
|
|
339
|
-
message: 'Rejected by connector'
|
|
340
|
-
}
|
|
341
|
-
})
|
|
342
|
-
});
|
|
343
|
-
const rejectedResult = await userHandler.updateUserSettings({
|
|
344
|
-
user: hookUser,
|
|
345
|
-
userSettings: {
|
|
346
|
-
key: { value: 'value' }
|
|
347
|
-
},
|
|
348
|
-
settingKeysToRemove: [],
|
|
349
|
-
platformName: 'testCRM'
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
expect(rejectedResult.successful).toBe(false);
|
|
353
|
-
expect(hookUser.update).not.toHaveBeenCalled();
|
|
354
|
-
|
|
355
|
-
const failingUser = {
|
|
356
|
-
userSettings: {},
|
|
357
|
-
update: jest.fn().mockRejectedValue(new Error('write failed'))
|
|
358
|
-
};
|
|
359
|
-
connectorRegistry.getConnector.mockReturnValueOnce({
|
|
360
|
-
onUpdateUserSettings: jest.fn().mockResolvedValue({
|
|
361
|
-
successful: true,
|
|
362
|
-
returnMessage: {
|
|
363
|
-
messageType: 'success',
|
|
364
|
-
message: 'Allowed'
|
|
365
|
-
}
|
|
366
|
-
})
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
const failedUpdateResult = await userHandler.updateUserSettings({
|
|
370
|
-
user: failingUser,
|
|
371
|
-
userSettings: {
|
|
372
|
-
key: { value: 'value' }
|
|
373
|
-
},
|
|
374
|
-
settingKeysToRemove: [],
|
|
375
|
-
platformName: 'testCRM'
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
expect(failedUpdateResult.successful).toBe(false);
|
|
379
|
-
expect(failedUpdateResult.returnMessage.messageType).toBe('warning');
|
|
380
|
-
});
|
|
381
|
-
});
|
package/test/index.test.js
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
const express = require('express');
|
|
2
|
-
const request = require('supertest');
|
|
3
|
-
|
|
4
|
-
jest.mock('../lib/jwt', () => ({
|
|
5
|
-
decodeJwt: jest.fn(),
|
|
6
|
-
generateJwt: jest.fn(),
|
|
7
|
-
}));
|
|
8
|
-
jest.mock('../handlers/auth', () => ({
|
|
9
|
-
authValidation: jest.fn(),
|
|
10
|
-
}));
|
|
11
|
-
jest.mock('../handlers/log', () => ({
|
|
12
|
-
handleAsyncPluginCallback: jest.fn(),
|
|
13
|
-
}));
|
|
14
|
-
jest.mock('../lib/analytics', () => ({
|
|
15
|
-
init: jest.fn(),
|
|
16
|
-
track: jest.fn(),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
const jwt = require('../lib/jwt');
|
|
20
|
-
const authCore = require('../handlers/auth');
|
|
21
|
-
const logCore = require('../handlers/log');
|
|
22
|
-
const { createCoreRouter, createCoreMiddleware } = require('../index');
|
|
23
|
-
const connectorRegistry = require('../connector/registry');
|
|
24
|
-
|
|
25
|
-
function buildApp() {
|
|
26
|
-
const app = express();
|
|
27
|
-
createCoreMiddleware().forEach((m) => app.use(m));
|
|
28
|
-
app.use('/', createCoreRouter());
|
|
29
|
-
return app;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('Core Router JWT normalization', () => {
|
|
33
|
-
beforeEach(() => {
|
|
34
|
-
jest.clearAllMocks();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('should accept query jwtToken without exp without refreshing it', async () => {
|
|
38
|
-
jwt.decodeJwt.mockReturnValue({ id: 'user-1', platform: 'testCRM' });
|
|
39
|
-
authCore.authValidation.mockResolvedValue({
|
|
40
|
-
successful: true,
|
|
41
|
-
returnMessage: { message: 'ok' },
|
|
42
|
-
failReason: null,
|
|
43
|
-
status: 200,
|
|
44
|
-
});
|
|
45
|
-
const app = buildApp();
|
|
46
|
-
|
|
47
|
-
const response = await request(app).get('/authValidation?jwtToken=query-token');
|
|
48
|
-
|
|
49
|
-
expect(response.status).toBe(200);
|
|
50
|
-
expect(response.headers['x-refreshed-jwt-token']).toBeUndefined();
|
|
51
|
-
expect(authCore.authValidation).toHaveBeenCalledWith({
|
|
52
|
-
platform: 'testCRM',
|
|
53
|
-
userId: 'user-1',
|
|
54
|
-
});
|
|
55
|
-
expect(jwt.generateJwt).not.toHaveBeenCalled();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('should refresh near-expiry query jwtToken and expose header', async () => {
|
|
59
|
-
const nowMs = 1700000000000;
|
|
60
|
-
const nowSeconds = Math.floor(nowMs / 1000);
|
|
61
|
-
const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(nowMs);
|
|
62
|
-
jwt.decodeJwt.mockImplementation((token) => {
|
|
63
|
-
if (token === 'query-token') {
|
|
64
|
-
return { id: 'user-1', platform: 'testCRM', exp: nowSeconds + 60 };
|
|
65
|
-
}
|
|
66
|
-
if (token === 'new-token') {
|
|
67
|
-
return { id: 'user-1', platform: 'testCRM', exp: nowSeconds + (14 * 24 * 60 * 60) };
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
});
|
|
71
|
-
jwt.generateJwt.mockReturnValue('new-token');
|
|
72
|
-
authCore.authValidation.mockResolvedValue({
|
|
73
|
-
successful: true,
|
|
74
|
-
returnMessage: { message: 'ok' },
|
|
75
|
-
failReason: null,
|
|
76
|
-
status: 200,
|
|
77
|
-
});
|
|
78
|
-
const app = buildApp();
|
|
79
|
-
|
|
80
|
-
const response = await request(app)
|
|
81
|
-
.get('/authValidation?jwtToken=query-token')
|
|
82
|
-
.set('Origin', 'https://example.com');
|
|
83
|
-
|
|
84
|
-
expect(response.status).toBe(200);
|
|
85
|
-
expect(response.headers['x-refreshed-jwt-token']).toBe('new-token');
|
|
86
|
-
expect(response.headers['access-control-expose-headers']).toContain('x-refreshed-jwt-token');
|
|
87
|
-
expect(jwt.generateJwt).toHaveBeenCalledWith({ id: 'user-1', platform: 'testCRM' });
|
|
88
|
-
expect(authCore.authValidation).toHaveBeenCalledWith({
|
|
89
|
-
platform: 'testCRM',
|
|
90
|
-
userId: 'user-1',
|
|
91
|
-
});
|
|
92
|
-
expect(jwt.decodeJwt).toHaveBeenCalledWith('new-token');
|
|
93
|
-
nowSpy.mockRestore();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('should not rotate long-lived query jwtToken', async () => {
|
|
97
|
-
const nowMs = 1700000000000;
|
|
98
|
-
const nowSeconds = Math.floor(nowMs / 1000);
|
|
99
|
-
const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(nowMs);
|
|
100
|
-
jwt.decodeJwt.mockReturnValue({
|
|
101
|
-
id: 'user-1',
|
|
102
|
-
platform: 'testCRM',
|
|
103
|
-
exp: nowSeconds + (120 * 365 * 24 * 60 * 60),
|
|
104
|
-
});
|
|
105
|
-
authCore.authValidation.mockResolvedValue({
|
|
106
|
-
successful: true,
|
|
107
|
-
returnMessage: { message: 'ok' },
|
|
108
|
-
failReason: null,
|
|
109
|
-
status: 200,
|
|
110
|
-
});
|
|
111
|
-
const app = buildApp();
|
|
112
|
-
|
|
113
|
-
const response = await request(app).get('/authValidation?jwtToken=query-token');
|
|
114
|
-
|
|
115
|
-
expect(response.status).toBe(200);
|
|
116
|
-
expect(response.headers['x-refreshed-jwt-token']).toBeUndefined();
|
|
117
|
-
expect(jwt.generateJwt).not.toHaveBeenCalled();
|
|
118
|
-
nowSpy.mockRestore();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('should refresh near-expiry bearer token and expose header', async () => {
|
|
122
|
-
const nowMs = 1700000000000;
|
|
123
|
-
const nowSeconds = Math.floor(nowMs / 1000);
|
|
124
|
-
const nowSpy = jest.spyOn(Date, 'now').mockReturnValue(nowMs);
|
|
125
|
-
jwt.decodeJwt.mockImplementation((token) => {
|
|
126
|
-
if (token === 'old-token') {
|
|
127
|
-
return { id: 'user-1', platform: 'testCRM', exp: nowSeconds + 60 };
|
|
128
|
-
}
|
|
129
|
-
if (token === 'new-token') {
|
|
130
|
-
return { id: 'user-1', platform: 'testCRM', exp: nowSeconds + (14 * 24 * 60 * 60) };
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
133
|
-
});
|
|
134
|
-
jwt.generateJwt.mockReturnValue('new-token');
|
|
135
|
-
const app = buildApp();
|
|
136
|
-
|
|
137
|
-
const response = await request(app)
|
|
138
|
-
.get('/isAlive')
|
|
139
|
-
.set('Authorization', 'Bearer old-token')
|
|
140
|
-
.set('Origin', 'https://example.com');
|
|
141
|
-
|
|
142
|
-
expect(response.status).toBe(200);
|
|
143
|
-
expect(response.headers['x-refreshed-jwt-token']).toBe('new-token');
|
|
144
|
-
expect(response.headers['access-control-expose-headers']).toContain('x-refreshed-jwt-token');
|
|
145
|
-
expect(jwt.generateJwt).toHaveBeenCalledWith({ id: 'user-1', platform: 'testCRM' });
|
|
146
|
-
nowSpy.mockRestore();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test('should treat invalid bearer token as unauthenticated for authValidation route', async () => {
|
|
150
|
-
jwt.decodeJwt.mockReturnValue(null);
|
|
151
|
-
const app = buildApp();
|
|
152
|
-
|
|
153
|
-
const response = await request(app)
|
|
154
|
-
.get('/authValidation?jwtToken=query-token')
|
|
155
|
-
.set('Authorization', 'Bearer invalid-token');
|
|
156
|
-
|
|
157
|
-
expect(response.status).toBe(400);
|
|
158
|
-
expect(response.text).toContain('authorize CRM platform');
|
|
159
|
-
expect(authCore.authValidation).not.toHaveBeenCalled();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
test('should bypass normalization for /mcp routes', async () => {
|
|
163
|
-
const app = buildApp();
|
|
164
|
-
|
|
165
|
-
const response = await request(app)
|
|
166
|
-
.get('/mcp')
|
|
167
|
-
.set('Authorization', 'Bearer maybe-token');
|
|
168
|
-
|
|
169
|
-
expect(response.status).toBe(404);
|
|
170
|
-
expect(jwt.decodeJwt).not.toHaveBeenCalled();
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test('should route plugin async callbacks by task id', async () => {
|
|
174
|
-
logCore.handleAsyncPluginCallback.mockResolvedValue({
|
|
175
|
-
statusCode: 200,
|
|
176
|
-
body: { successful: true },
|
|
177
|
-
});
|
|
178
|
-
const app = buildApp();
|
|
179
|
-
|
|
180
|
-
const response = await request(app)
|
|
181
|
-
.post('/plugin/async-callback/task-123')
|
|
182
|
-
.send({
|
|
183
|
-
successful: true,
|
|
184
|
-
message: 'Done',
|
|
185
|
-
note: 'Callback note',
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
expect(response.status).toBe(200);
|
|
189
|
-
expect(response.body).toEqual({ successful: true });
|
|
190
|
-
expect(logCore.handleAsyncPluginCallback).toHaveBeenCalledWith({
|
|
191
|
-
taskId: 'task-123',
|
|
192
|
-
body: {
|
|
193
|
-
successful: true,
|
|
194
|
-
message: 'Done',
|
|
195
|
-
note: 'Callback note',
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
describe('Core Router implementedInterfaces contract', () => {
|
|
201
|
-
const originalUseCache = process.env.USE_CACHE;
|
|
202
|
-
|
|
203
|
-
beforeEach(() => {
|
|
204
|
-
connectorRegistry.connectors.clear();
|
|
205
|
-
connectorRegistry.manifests.clear();
|
|
206
|
-
connectorRegistry.platformInterfaces.clear();
|
|
207
|
-
delete process.env.USE_CACHE;
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
afterEach(() => {
|
|
211
|
-
connectorRegistry.connectors.clear();
|
|
212
|
-
connectorRegistry.manifests.clear();
|
|
213
|
-
connectorRegistry.platformInterfaces.clear();
|
|
214
|
-
if (originalUseCache === undefined) {
|
|
215
|
-
delete process.env.USE_CACHE;
|
|
216
|
-
} else {
|
|
217
|
-
process.env.USE_CACHE = originalUseCache;
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test('returns client capability flags for an oauth platform', async () => {
|
|
222
|
-
connectorRegistry.registerConnector('contractCRM', {
|
|
223
|
-
getAuthType: jest.fn().mockReturnValue('oauth'),
|
|
224
|
-
getOauthInfo: jest.fn(),
|
|
225
|
-
getUserInfo: jest.fn(),
|
|
226
|
-
createCallLog: jest.fn(),
|
|
227
|
-
updateCallLog: jest.fn(),
|
|
228
|
-
createMessageLog: jest.fn(),
|
|
229
|
-
findContactWithName: jest.fn(),
|
|
230
|
-
getLicenseStatus: jest.fn(),
|
|
231
|
-
});
|
|
232
|
-
const app = buildApp();
|
|
233
|
-
|
|
234
|
-
const response = await request(app).get('/implementedInterfaces?platform=contractCRM');
|
|
235
|
-
|
|
236
|
-
expect(response.status).toBe(200);
|
|
237
|
-
expect(response.body).toEqual({
|
|
238
|
-
getAuthType: true,
|
|
239
|
-
getOauthInfo: true,
|
|
240
|
-
getUserInfo: true,
|
|
241
|
-
createCallLog: true,
|
|
242
|
-
updateCallLog: true,
|
|
243
|
-
getCallLog: false,
|
|
244
|
-
createMessageLog: true,
|
|
245
|
-
updateMessageLog: false,
|
|
246
|
-
createContact: false,
|
|
247
|
-
findContact: false,
|
|
248
|
-
listAppointments: false,
|
|
249
|
-
createAppointment: false,
|
|
250
|
-
updateAppointment: false,
|
|
251
|
-
refreshAppointment: false,
|
|
252
|
-
confirmAppointment: false,
|
|
253
|
-
cancelAppointment: false,
|
|
254
|
-
unAuthorize: false,
|
|
255
|
-
upsertCallDisposition: false,
|
|
256
|
-
findContactWithName: true,
|
|
257
|
-
getUserList: false,
|
|
258
|
-
getLicenseStatus: true,
|
|
259
|
-
getLogFormatType: false,
|
|
260
|
-
refreshUserInfo: false,
|
|
261
|
-
cacheCallNote: false,
|
|
262
|
-
});
|
|
263
|
-
expect(response.body).not.toHaveProperty('getBasicAuth');
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
test('returns basic auth and cache flags for an apiKey platform', async () => {
|
|
267
|
-
process.env.USE_CACHE = 'true';
|
|
268
|
-
connectorRegistry.registerConnector('apiKeyCRM', {
|
|
269
|
-
getAuthType: jest.fn().mockReturnValue('apiKey'),
|
|
270
|
-
getBasicAuth: jest.fn(),
|
|
271
|
-
createCallLog: jest.fn(),
|
|
272
|
-
updateCallLog: jest.fn(),
|
|
273
|
-
updateMessageLog: jest.fn(),
|
|
274
|
-
refreshUserInfo: jest.fn(),
|
|
275
|
-
});
|
|
276
|
-
const app = buildApp();
|
|
277
|
-
|
|
278
|
-
const response = await request(app).get('/implementedInterfaces?platform=apiKeyCRM');
|
|
279
|
-
|
|
280
|
-
expect(response.status).toBe(200);
|
|
281
|
-
expect(response.body).toEqual(expect.objectContaining({
|
|
282
|
-
getAuthType: true,
|
|
283
|
-
getBasicAuth: true,
|
|
284
|
-
createCallLog: true,
|
|
285
|
-
updateCallLog: true,
|
|
286
|
-
updateMessageLog: true,
|
|
287
|
-
refreshUserInfo: true,
|
|
288
|
-
cacheCallNote: true,
|
|
289
|
-
}));
|
|
290
|
-
expect(response.body).not.toHaveProperty('getOauthInfo');
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
test('rejects requests without a platform parameter', async () => {
|
|
294
|
-
const app = buildApp();
|
|
295
|
-
|
|
296
|
-
const response = await request(app).get('/implementedInterfaces');
|
|
297
|
-
|
|
298
|
-
expect(response.status).toBe(400);
|
|
299
|
-
expect(response.text).toBe('Please provide platform.');
|
|
300
|
-
});
|
|
301
|
-
});
|