@app-connect/core 1.7.37 → 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} +538 -449
- 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/{lib → dist/lib}/migrateCallLogsSchema.js +75 -160
- 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 +8 -0
- 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/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,436 +0,0 @@
|
|
|
1
|
-
const createCallLog = require('../../../mcp/tools/createCallLog');
|
|
2
|
-
const jwt = require('../../../lib/jwt');
|
|
3
|
-
const connectorRegistry = require('../../../connector/registry');
|
|
4
|
-
const logCore = require('../../../handlers/log');
|
|
5
|
-
const contactCore = require('../../../handlers/contact');
|
|
6
|
-
const util = require('../../../lib/util');
|
|
7
|
-
const { CallLogModel } = require('../../../models/callLogModel');
|
|
8
|
-
|
|
9
|
-
// Mock dependencies
|
|
10
|
-
jest.mock('../../../lib/jwt');
|
|
11
|
-
jest.mock('../../../connector/registry');
|
|
12
|
-
jest.mock('../../../handlers/log');
|
|
13
|
-
jest.mock('../../../handlers/contact');
|
|
14
|
-
jest.mock('../../../lib/util');
|
|
15
|
-
jest.mock('../../../models/callLogModel');
|
|
16
|
-
|
|
17
|
-
describe('MCP Tool: createCallLog', () => {
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
process.env.HASH_KEY = 'test-hash-key';
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('tool definition', () => {
|
|
24
|
-
test('should have correct tool definition', () => {
|
|
25
|
-
expect(createCallLog.definition).toBeDefined();
|
|
26
|
-
expect(createCallLog.definition.name).toBe('createCallLog');
|
|
27
|
-
expect(createCallLog.definition.description).toContain('REQUIRES CRM CONNECTION');
|
|
28
|
-
expect(createCallLog.definition.inputSchema).toBeDefined();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should require incomingData parameter (jwtToken is server-injected)', () => {
|
|
32
|
-
expect(createCallLog.definition.inputSchema.required).not.toContain('jwtToken');
|
|
33
|
-
expect(createCallLog.definition.inputSchema.required).toContain('incomingData');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('should have detailed inputSchema for incomingData', () => {
|
|
37
|
-
const incomingDataSchema = createCallLog.definition.inputSchema.properties.incomingData;
|
|
38
|
-
expect(incomingDataSchema.properties).toHaveProperty('logInfo');
|
|
39
|
-
expect(incomingDataSchema.properties).toHaveProperty('note');
|
|
40
|
-
expect(incomingDataSchema.required).toContain('logInfo');
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('execute', () => {
|
|
45
|
-
test('should create call log successfully', async () => {
|
|
46
|
-
// Arrange
|
|
47
|
-
const mockIncomingData = {
|
|
48
|
-
logInfo: {
|
|
49
|
-
id: 'rc-call-123',
|
|
50
|
-
sessionId: 'session-123',
|
|
51
|
-
direction: 'Inbound',
|
|
52
|
-
startTime: '2024-01-01T10:00:00Z',
|
|
53
|
-
duration: 120,
|
|
54
|
-
from: { phoneNumber: '+1234567890', name: 'John Doe' },
|
|
55
|
-
to: { phoneNumber: '+0987654321', name: 'Company' },
|
|
56
|
-
accountId: 'rc-account-123'
|
|
57
|
-
},
|
|
58
|
-
contactName: 'John Doe',
|
|
59
|
-
contactType: 'Contact',
|
|
60
|
-
note: 'Test call note'
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
jwt.decodeJwt.mockReturnValue({
|
|
64
|
-
id: 'user-123',
|
|
65
|
-
platform: 'testCRM'
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const mockConnector = {
|
|
69
|
-
createCallLog: jest.fn()
|
|
70
|
-
};
|
|
71
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
72
|
-
|
|
73
|
-
CallLogModel.findOne.mockResolvedValue(null); // No existing log
|
|
74
|
-
|
|
75
|
-
util.getHashValue.mockReturnValue('hashed-account-id');
|
|
76
|
-
|
|
77
|
-
// Mock contactCore.findContact to return a contact
|
|
78
|
-
contactCore.findContact.mockResolvedValue({
|
|
79
|
-
successful: true,
|
|
80
|
-
contact: [{ id: 'contact-123', isNewContact: false }]
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
logCore.createCallLog.mockResolvedValue({
|
|
84
|
-
successful: true,
|
|
85
|
-
logId: 'crm-log-123',
|
|
86
|
-
returnMessage: { message: 'Call logged successfully' }
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Act
|
|
90
|
-
const result = await createCallLog.execute({
|
|
91
|
-
jwtToken: 'mock-jwt-token',
|
|
92
|
-
incomingData: mockIncomingData
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Assert
|
|
96
|
-
expect(result).toEqual({
|
|
97
|
-
success: true,
|
|
98
|
-
data: {
|
|
99
|
-
logId: 'crm-log-123',
|
|
100
|
-
message: 'Call logged successfully'
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
expect(jwt.decodeJwt).toHaveBeenCalledWith('mock-jwt-token');
|
|
104
|
-
expect(CallLogModel.findOne).toHaveBeenCalledWith({
|
|
105
|
-
where: { sessionId: 'session-123' }
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('should create call log with AI note and transcript', async () => {
|
|
110
|
-
// Arrange
|
|
111
|
-
const mockIncomingData = {
|
|
112
|
-
logInfo: {
|
|
113
|
-
id: 'rc-call-456',
|
|
114
|
-
sessionId: 'session-456',
|
|
115
|
-
direction: 'Outbound',
|
|
116
|
-
startTime: '2024-01-01T11:00:00Z',
|
|
117
|
-
duration: 300,
|
|
118
|
-
from: { phoneNumber: '+0987654321' },
|
|
119
|
-
to: { phoneNumber: '+1234567890' }
|
|
120
|
-
},
|
|
121
|
-
aiNote: 'AI generated summary of the call',
|
|
122
|
-
transcript: 'Full call transcript text'
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
jwt.decodeJwt.mockReturnValue({
|
|
126
|
-
id: 'user-123',
|
|
127
|
-
platform: 'testCRM'
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const mockConnector = {
|
|
131
|
-
createCallLog: jest.fn()
|
|
132
|
-
};
|
|
133
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
134
|
-
|
|
135
|
-
CallLogModel.findOne.mockResolvedValue(null);
|
|
136
|
-
|
|
137
|
-
// Mock contactCore.findContact to return a contact
|
|
138
|
-
contactCore.findContact.mockResolvedValue({
|
|
139
|
-
successful: true,
|
|
140
|
-
contact: [{ id: 'contact-456', isNewContact: false }]
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
logCore.createCallLog.mockResolvedValue({
|
|
144
|
-
successful: true,
|
|
145
|
-
logId: 'crm-log-456'
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Act
|
|
149
|
-
const result = await createCallLog.execute({
|
|
150
|
-
jwtToken: 'mock-jwt-token',
|
|
151
|
-
incomingData: mockIncomingData
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Assert
|
|
155
|
-
expect(result.success).toBe(true);
|
|
156
|
-
expect(result.data.logId).toBe('crm-log-456');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test('should create call log with additional submission', async () => {
|
|
160
|
-
// Arrange
|
|
161
|
-
const mockIncomingData = {
|
|
162
|
-
logInfo: {
|
|
163
|
-
id: 'rc-call-789',
|
|
164
|
-
sessionId: 'session-789',
|
|
165
|
-
direction: 'Inbound',
|
|
166
|
-
startTime: '2024-01-01T12:00:00Z',
|
|
167
|
-
duration: 60,
|
|
168
|
-
from: { phoneNumber: '+1234567890' },
|
|
169
|
-
to: { phoneNumber: '+0987654321' }
|
|
170
|
-
},
|
|
171
|
-
additionalSubmission: {
|
|
172
|
-
isAssignedToUser: true,
|
|
173
|
-
adminAssignedUserToken: 'admin-jwt-token',
|
|
174
|
-
adminAssignedUserRcId: 'rc-ext-101'
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
jwt.decodeJwt.mockReturnValue({
|
|
179
|
-
id: 'user-123',
|
|
180
|
-
platform: 'testCRM'
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const mockConnector = {
|
|
184
|
-
createCallLog: jest.fn()
|
|
185
|
-
};
|
|
186
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
187
|
-
|
|
188
|
-
CallLogModel.findOne.mockResolvedValue(null);
|
|
189
|
-
|
|
190
|
-
// Mock contactCore.findContact to return a contact
|
|
191
|
-
contactCore.findContact.mockResolvedValue({
|
|
192
|
-
successful: true,
|
|
193
|
-
contact: [{ id: 'contact-789', isNewContact: false }]
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
logCore.createCallLog.mockResolvedValue({
|
|
197
|
-
successful: true,
|
|
198
|
-
logId: 'crm-log-789'
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// Act
|
|
202
|
-
const result = await createCallLog.execute({
|
|
203
|
-
jwtToken: 'mock-jwt-token',
|
|
204
|
-
incomingData: mockIncomingData
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// Assert
|
|
208
|
-
expect(result.success).toBe(true);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test('should return error when call log already exists', async () => {
|
|
212
|
-
// Arrange
|
|
213
|
-
const mockIncomingData = {
|
|
214
|
-
logInfo: {
|
|
215
|
-
sessionId: 'existing-session'
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
CallLogModel.findOne.mockResolvedValue({
|
|
220
|
-
id: 'existing-log',
|
|
221
|
-
sessionId: 'existing-session'
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
// Act
|
|
225
|
-
const result = await createCallLog.execute({
|
|
226
|
-
jwtToken: 'mock-jwt-token',
|
|
227
|
-
incomingData: mockIncomingData
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
// Assert
|
|
231
|
-
expect(result.success).toBe(false);
|
|
232
|
-
expect(result.error).toContain('already exists');
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test('should return error when jwtToken is missing', async () => {
|
|
236
|
-
// Act
|
|
237
|
-
const result = await createCallLog.execute({
|
|
238
|
-
incomingData: { logInfo: {} }
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// Assert
|
|
242
|
-
expect(result.success).toBe(false);
|
|
243
|
-
expect(result.error).toContain('authorize CRM platform');
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
test('should return error when incomingData is missing', async () => {
|
|
247
|
-
// Act
|
|
248
|
-
const result = await createCallLog.execute({
|
|
249
|
-
jwtToken: 'mock-jwt-token'
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
// Assert
|
|
253
|
-
expect(result.success).toBe(false);
|
|
254
|
-
expect(result.error).toContain('Incoming data must be provided');
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
test('should return error when logInfo is missing', async () => {
|
|
258
|
-
// Act
|
|
259
|
-
const result = await createCallLog.execute({
|
|
260
|
-
jwtToken: 'mock-jwt-token',
|
|
261
|
-
incomingData: { contactId: 'contact-123' }
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// Assert
|
|
265
|
-
expect(result.success).toBe(false);
|
|
266
|
-
expect(result.error).toContain('logInfo is required');
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
test('should return error when JWT is invalid', async () => {
|
|
270
|
-
// Arrange
|
|
271
|
-
const mockIncomingData = {
|
|
272
|
-
logInfo: {
|
|
273
|
-
sessionId: 'session-123'
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
CallLogModel.findOne.mockResolvedValue(null);
|
|
278
|
-
|
|
279
|
-
jwt.decodeJwt.mockReturnValue({
|
|
280
|
-
platform: 'testCRM'
|
|
281
|
-
// id is missing
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
// Act
|
|
285
|
-
const result = await createCallLog.execute({
|
|
286
|
-
jwtToken: 'invalid-token',
|
|
287
|
-
incomingData: mockIncomingData
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
// Assert
|
|
291
|
-
expect(result.success).toBe(false);
|
|
292
|
-
expect(result.error).toContain('Invalid JWT token');
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
test('should return error when decodeJwt returns null', async () => {
|
|
296
|
-
jwt.decodeJwt.mockReturnValue(null);
|
|
297
|
-
const result = await createCallLog.execute({
|
|
298
|
-
jwtToken: 'invalid-token',
|
|
299
|
-
incomingData: { logInfo: { sessionId: 'session-123' } }
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
expect(result.success).toBe(false);
|
|
303
|
-
expect(result.error).toContain('Invalid JWT token');
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test('should return error when platform connector not found', async () => {
|
|
307
|
-
// Arrange
|
|
308
|
-
const mockIncomingData = {
|
|
309
|
-
logInfo: {
|
|
310
|
-
sessionId: 'session-123'
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
CallLogModel.findOne.mockResolvedValue(null);
|
|
315
|
-
|
|
316
|
-
jwt.decodeJwt.mockReturnValue({
|
|
317
|
-
id: 'user-123',
|
|
318
|
-
platform: 'unknownCRM'
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
connectorRegistry.getConnector.mockReturnValue(null);
|
|
322
|
-
|
|
323
|
-
// Act
|
|
324
|
-
const result = await createCallLog.execute({
|
|
325
|
-
jwtToken: 'mock-jwt-token',
|
|
326
|
-
incomingData: mockIncomingData
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// Assert
|
|
330
|
-
expect(result.success).toBe(false);
|
|
331
|
-
expect(result.error).toContain('Platform connector not found');
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
test('should return error when createCallLog is not implemented', async () => {
|
|
335
|
-
// Arrange
|
|
336
|
-
const mockIncomingData = {
|
|
337
|
-
logInfo: {
|
|
338
|
-
sessionId: 'session-123'
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
CallLogModel.findOne.mockResolvedValue(null);
|
|
343
|
-
|
|
344
|
-
jwt.decodeJwt.mockReturnValue({
|
|
345
|
-
id: 'user-123',
|
|
346
|
-
platform: 'testCRM'
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
const mockConnector = {}; // No createCallLog method
|
|
350
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
351
|
-
|
|
352
|
-
// Act
|
|
353
|
-
const result = await createCallLog.execute({
|
|
354
|
-
jwtToken: 'mock-jwt-token',
|
|
355
|
-
incomingData: mockIncomingData
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
// Assert
|
|
359
|
-
expect(result.success).toBe(false);
|
|
360
|
-
expect(result.error).toContain('not implemented');
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
test('should return error when creation fails', async () => {
|
|
364
|
-
// Arrange
|
|
365
|
-
const mockIncomingData = {
|
|
366
|
-
logInfo: {
|
|
367
|
-
id: 'rc-call-999',
|
|
368
|
-
sessionId: 'session-999',
|
|
369
|
-
direction: 'Inbound',
|
|
370
|
-
startTime: '2024-01-01T13:00:00Z',
|
|
371
|
-
duration: 45,
|
|
372
|
-
from: { phoneNumber: '+1234567890' },
|
|
373
|
-
to: { phoneNumber: '+0987654321' }
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
jwt.decodeJwt.mockReturnValue({
|
|
378
|
-
id: 'user-123',
|
|
379
|
-
platform: 'testCRM'
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
const mockConnector = {
|
|
383
|
-
createCallLog: jest.fn()
|
|
384
|
-
};
|
|
385
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
386
|
-
|
|
387
|
-
CallLogModel.findOne.mockResolvedValue(null);
|
|
388
|
-
|
|
389
|
-
// Mock contactCore.findContact to return a contact
|
|
390
|
-
contactCore.findContact.mockResolvedValue({
|
|
391
|
-
successful: true,
|
|
392
|
-
contact: [{ id: 'contact-999', isNewContact: false }]
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
logCore.createCallLog.mockResolvedValue({
|
|
396
|
-
successful: false,
|
|
397
|
-
returnMessage: { message: 'Failed to create log in CRM' }
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// Act
|
|
401
|
-
const result = await createCallLog.execute({
|
|
402
|
-
jwtToken: 'mock-jwt-token',
|
|
403
|
-
incomingData: mockIncomingData
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
// Assert
|
|
407
|
-
expect(result.success).toBe(false);
|
|
408
|
-
expect(result.error).toBe('Failed to create log in CRM');
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
test('should handle unexpected errors gracefully', async () => {
|
|
412
|
-
// Arrange
|
|
413
|
-
const mockIncomingData = {
|
|
414
|
-
logInfo: {
|
|
415
|
-
sessionId: 'session-error'
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
CallLogModel.findOne.mockRejectedValue(
|
|
420
|
-
new Error('Database connection failed')
|
|
421
|
-
);
|
|
422
|
-
|
|
423
|
-
// Act
|
|
424
|
-
const result = await createCallLog.execute({
|
|
425
|
-
jwtToken: 'mock-jwt-token',
|
|
426
|
-
incomingData: mockIncomingData
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
// Assert
|
|
430
|
-
expect(result.success).toBe(false);
|
|
431
|
-
expect(result.error).toBe('Database connection failed');
|
|
432
|
-
expect(result.errorDetails).toBeDefined();
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
});
|
|
436
|
-
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const createContact = require('../../../mcp/tools/createContact');
|
|
2
|
-
const jwt = require('../../../lib/jwt');
|
|
3
|
-
const connectorRegistry = require('../../../connector/registry');
|
|
4
|
-
const contactCore = require('../../../handlers/contact');
|
|
5
|
-
|
|
6
|
-
jest.mock('../../../lib/jwt');
|
|
7
|
-
jest.mock('../../../connector/registry');
|
|
8
|
-
jest.mock('../../../handlers/contact');
|
|
9
|
-
|
|
10
|
-
describe('MCP Tool: createContact', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('should have correct tool definition', () => {
|
|
16
|
-
expect(createContact.definition).toBeDefined();
|
|
17
|
-
expect(createContact.definition.name).toBe('createContact');
|
|
18
|
-
expect(createContact.definition.inputSchema.required).toContain('phoneNumber');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('should create contact successfully', async () => {
|
|
22
|
-
jwt.decodeJwt.mockReturnValue({ id: 'user-123', platform: 'testCRM' });
|
|
23
|
-
connectorRegistry.getConnector.mockReturnValue({ createContact: jest.fn() });
|
|
24
|
-
contactCore.createContact.mockResolvedValue({
|
|
25
|
-
successful: true,
|
|
26
|
-
returnMessage: { message: 'Created' },
|
|
27
|
-
contact: { id: 'contact-1' }
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const result = await createContact.execute({
|
|
31
|
-
jwtToken: 'mock-jwt-token',
|
|
32
|
-
phoneNumber: '+14155551234',
|
|
33
|
-
newContactName: 'John Doe'
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
expect(result).toEqual({
|
|
37
|
-
success: true,
|
|
38
|
-
data: {
|
|
39
|
-
contact: { id: 'contact-1' },
|
|
40
|
-
message: 'Created'
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('should return error when decodeJwt returns null', async () => {
|
|
46
|
-
jwt.decodeJwt.mockReturnValue(null);
|
|
47
|
-
|
|
48
|
-
const result = await createContact.execute({
|
|
49
|
-
jwtToken: 'invalid-jwt',
|
|
50
|
-
phoneNumber: '+14155551234',
|
|
51
|
-
newContactName: 'John Doe'
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
expect(result.success).toBe(false);
|
|
55
|
-
expect(result.error).toContain('Invalid JWT token');
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|