@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,275 +0,0 @@
|
|
|
1
|
-
const findContactByName = require('../../../mcp/tools/findContactByName');
|
|
2
|
-
const jwt = require('../../../lib/jwt');
|
|
3
|
-
const connectorRegistry = require('../../../connector/registry');
|
|
4
|
-
const contactCore = require('../../../handlers/contact');
|
|
5
|
-
|
|
6
|
-
// Mock dependencies
|
|
7
|
-
jest.mock('../../../lib/jwt');
|
|
8
|
-
jest.mock('../../../connector/registry');
|
|
9
|
-
jest.mock('../../../handlers/contact');
|
|
10
|
-
|
|
11
|
-
describe('MCP Tool: findContactByName', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.clearAllMocks();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('tool definition', () => {
|
|
17
|
-
test('should have correct tool definition', () => {
|
|
18
|
-
expect(findContactByName.definition).toBeDefined();
|
|
19
|
-
expect(findContactByName.definition.name).toBe('findContactByName');
|
|
20
|
-
expect(findContactByName.definition.description).toContain('REQUIRES CRM CONNECTION');
|
|
21
|
-
expect(findContactByName.definition.inputSchema).toBeDefined();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('should require name parameter (jwtToken is server-injected)', () => {
|
|
25
|
-
expect(findContactByName.definition.inputSchema.required).not.toContain('jwtToken');
|
|
26
|
-
expect(findContactByName.definition.inputSchema.required).toContain('name');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('execute', () => {
|
|
31
|
-
test('should find contact by name successfully', async () => {
|
|
32
|
-
// Arrange
|
|
33
|
-
const mockContact = {
|
|
34
|
-
id: 'contact-123',
|
|
35
|
-
name: 'John Doe',
|
|
36
|
-
phone: '+1234567890',
|
|
37
|
-
type: 'Contact'
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
jwt.decodeJwt.mockReturnValue({
|
|
41
|
-
id: 'user-123',
|
|
42
|
-
platform: 'testCRM'
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const mockConnector = {
|
|
46
|
-
findContactWithName: jest.fn()
|
|
47
|
-
};
|
|
48
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
49
|
-
|
|
50
|
-
contactCore.findContactWithName.mockResolvedValue({
|
|
51
|
-
successful: true,
|
|
52
|
-
contact: mockContact,
|
|
53
|
-
returnMessage: { message: 'Contact found' }
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Act
|
|
57
|
-
const result = await findContactByName.execute({
|
|
58
|
-
jwtToken: 'mock-jwt-token',
|
|
59
|
-
name: 'John Doe'
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// Assert
|
|
63
|
-
expect(result).toEqual({
|
|
64
|
-
success: true,
|
|
65
|
-
data: mockContact
|
|
66
|
-
});
|
|
67
|
-
expect(jwt.decodeJwt).toHaveBeenCalledWith('mock-jwt-token');
|
|
68
|
-
expect(connectorRegistry.getConnector).toHaveBeenCalledWith('testCRM');
|
|
69
|
-
expect(contactCore.findContactWithName).toHaveBeenCalledWith({
|
|
70
|
-
platform: 'testCRM',
|
|
71
|
-
userId: 'user-123',
|
|
72
|
-
name: 'John Doe'
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('should find contact with partial name', async () => {
|
|
77
|
-
// Arrange
|
|
78
|
-
const mockContact = {
|
|
79
|
-
id: 'contact-456',
|
|
80
|
-
name: 'Jane Smith',
|
|
81
|
-
phone: '+9876543210',
|
|
82
|
-
type: 'Contact'
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
jwt.decodeJwt.mockReturnValue({
|
|
86
|
-
id: 'user-123',
|
|
87
|
-
platform: 'testCRM'
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const mockConnector = {
|
|
91
|
-
findContactWithName: jest.fn()
|
|
92
|
-
};
|
|
93
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
94
|
-
|
|
95
|
-
contactCore.findContactWithName.mockResolvedValue({
|
|
96
|
-
successful: true,
|
|
97
|
-
contact: mockContact
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// Act
|
|
101
|
-
const result = await findContactByName.execute({
|
|
102
|
-
jwtToken: 'mock-jwt-token',
|
|
103
|
-
name: 'Jane'
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Assert
|
|
107
|
-
expect(result.success).toBe(true);
|
|
108
|
-
expect(result.data).toEqual(mockContact);
|
|
109
|
-
expect(contactCore.findContactWithName).toHaveBeenCalledWith({
|
|
110
|
-
platform: 'testCRM',
|
|
111
|
-
userId: 'user-123',
|
|
112
|
-
name: 'Jane'
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('should return error when contact not found', async () => {
|
|
117
|
-
// Arrange
|
|
118
|
-
jwt.decodeJwt.mockReturnValue({
|
|
119
|
-
id: 'user-123',
|
|
120
|
-
platform: 'testCRM'
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const mockConnector = {
|
|
124
|
-
findContactWithName: jest.fn()
|
|
125
|
-
};
|
|
126
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
127
|
-
|
|
128
|
-
contactCore.findContactWithName.mockResolvedValue({
|
|
129
|
-
successful: false,
|
|
130
|
-
contact: null,
|
|
131
|
-
returnMessage: { message: 'Contact not found' }
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
// Act
|
|
135
|
-
const result = await findContactByName.execute({
|
|
136
|
-
jwtToken: 'mock-jwt-token',
|
|
137
|
-
name: 'NonExistent Person'
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// Assert
|
|
141
|
-
expect(result).toEqual({
|
|
142
|
-
success: false,
|
|
143
|
-
error: 'Contact not found'
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('should return error when JWT is invalid', async () => {
|
|
148
|
-
// Arrange
|
|
149
|
-
jwt.decodeJwt.mockReturnValue({
|
|
150
|
-
platform: 'testCRM'
|
|
151
|
-
// id is missing
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Act
|
|
155
|
-
const result = await findContactByName.execute({
|
|
156
|
-
jwtToken: 'invalid-token',
|
|
157
|
-
name: 'John Doe'
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Assert
|
|
161
|
-
expect(result.success).toBe(false);
|
|
162
|
-
expect(result.error).toContain('Invalid JWT token');
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('should return error when decodeJwt returns null', async () => {
|
|
166
|
-
jwt.decodeJwt.mockReturnValue(null);
|
|
167
|
-
|
|
168
|
-
const result = await findContactByName.execute({
|
|
169
|
-
jwtToken: 'invalid-token',
|
|
170
|
-
name: 'John Doe'
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
expect(result.success).toBe(false);
|
|
174
|
-
expect(result.error).toContain('Invalid JWT token');
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('should return error when platform connector not found', async () => {
|
|
178
|
-
// Arrange
|
|
179
|
-
jwt.decodeJwt.mockReturnValue({
|
|
180
|
-
id: 'user-123',
|
|
181
|
-
platform: 'unknownCRM'
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
connectorRegistry.getConnector.mockReturnValue(null);
|
|
185
|
-
|
|
186
|
-
// Act
|
|
187
|
-
const result = await findContactByName.execute({
|
|
188
|
-
jwtToken: 'mock-jwt-token',
|
|
189
|
-
name: 'John Doe'
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// Assert
|
|
193
|
-
expect(result.success).toBe(false);
|
|
194
|
-
expect(result.error).toContain('Platform connector not found');
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test('should return error when findContactWithName is not implemented', async () => {
|
|
198
|
-
// Arrange
|
|
199
|
-
jwt.decodeJwt.mockReturnValue({
|
|
200
|
-
id: 'user-123',
|
|
201
|
-
platform: 'testCRM'
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
const mockConnector = {}; // No findContactWithName method
|
|
205
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
206
|
-
|
|
207
|
-
// Act
|
|
208
|
-
const result = await findContactByName.execute({
|
|
209
|
-
jwtToken: 'mock-jwt-token',
|
|
210
|
-
name: 'John Doe'
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// Assert
|
|
214
|
-
expect(result.success).toBe(false);
|
|
215
|
-
expect(result.error).toContain('not implemented');
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test('should handle unexpected errors gracefully', async () => {
|
|
219
|
-
// Arrange
|
|
220
|
-
jwt.decodeJwt.mockReturnValue({
|
|
221
|
-
id: 'user-123',
|
|
222
|
-
platform: 'testCRM'
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
const mockConnector = {
|
|
226
|
-
findContactWithName: jest.fn()
|
|
227
|
-
};
|
|
228
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
229
|
-
|
|
230
|
-
contactCore.findContactWithName.mockRejectedValue(
|
|
231
|
-
new Error('API rate limit exceeded')
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
// Act
|
|
235
|
-
const result = await findContactByName.execute({
|
|
236
|
-
jwtToken: 'mock-jwt-token',
|
|
237
|
-
name: 'John Doe'
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
// Assert
|
|
241
|
-
expect(result.success).toBe(false);
|
|
242
|
-
expect(result.error).toBe('API rate limit exceeded');
|
|
243
|
-
expect(result.errorDetails).toBeDefined();
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
test('should handle empty name parameter', async () => {
|
|
247
|
-
// Arrange
|
|
248
|
-
jwt.decodeJwt.mockReturnValue({
|
|
249
|
-
id: 'user-123',
|
|
250
|
-
platform: 'testCRM'
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
const mockConnector = {
|
|
254
|
-
findContactWithName: jest.fn()
|
|
255
|
-
};
|
|
256
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
257
|
-
|
|
258
|
-
contactCore.findContactWithName.mockResolvedValue({
|
|
259
|
-
successful: false,
|
|
260
|
-
returnMessage: { message: 'Name parameter is required' }
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
// Act
|
|
264
|
-
const result = await findContactByName.execute({
|
|
265
|
-
jwtToken: 'mock-jwt-token',
|
|
266
|
-
name: ''
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// Assert
|
|
270
|
-
expect(result.success).toBe(false);
|
|
271
|
-
expect(result.error).toBe('Name parameter is required');
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
const findContactByPhone = require('../../../mcp/tools/findContactByPhone');
|
|
2
|
-
const jwt = require('../../../lib/jwt');
|
|
3
|
-
const connectorRegistry = require('../../../connector/registry');
|
|
4
|
-
const contactCore = require('../../../handlers/contact');
|
|
5
|
-
|
|
6
|
-
// Mock dependencies
|
|
7
|
-
jest.mock('../../../lib/jwt');
|
|
8
|
-
jest.mock('../../../connector/registry');
|
|
9
|
-
jest.mock('../../../handlers/contact');
|
|
10
|
-
|
|
11
|
-
describe('MCP Tool: findContactByPhone', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
jest.clearAllMocks();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('tool definition', () => {
|
|
17
|
-
test('should have correct tool definition', () => {
|
|
18
|
-
expect(findContactByPhone.definition).toBeDefined();
|
|
19
|
-
expect(findContactByPhone.definition.name).toBe('findContactByPhone');
|
|
20
|
-
expect(findContactByPhone.definition.description).toContain('REQUIRES CRM CONNECTION');
|
|
21
|
-
expect(findContactByPhone.definition.inputSchema).toBeDefined();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('should require phoneNumber parameter (jwtToken is server-injected)', () => {
|
|
25
|
-
expect(findContactByPhone.definition.inputSchema.required).not.toContain('jwtToken');
|
|
26
|
-
expect(findContactByPhone.definition.inputSchema.required).toContain('phoneNumber');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should have optional parameters', () => {
|
|
30
|
-
expect(findContactByPhone.definition.inputSchema.properties).toHaveProperty('overridingFormat');
|
|
31
|
-
expect(findContactByPhone.definition.inputSchema.properties).toHaveProperty('isExtension');
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('execute', () => {
|
|
36
|
-
test('should find contact by phone successfully', async () => {
|
|
37
|
-
// Arrange
|
|
38
|
-
const mockContact = {
|
|
39
|
-
id: 'contact-123',
|
|
40
|
-
name: 'John Doe',
|
|
41
|
-
phone: '+1234567890',
|
|
42
|
-
type: 'Contact'
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
jwt.decodeJwt.mockReturnValue({
|
|
46
|
-
id: 'user-123',
|
|
47
|
-
platform: 'testCRM'
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const mockConnector = {
|
|
51
|
-
findContact: jest.fn()
|
|
52
|
-
};
|
|
53
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
54
|
-
|
|
55
|
-
contactCore.findContact.mockResolvedValue({
|
|
56
|
-
successful: true,
|
|
57
|
-
contact: mockContact,
|
|
58
|
-
returnMessage: { message: 'Contact found' }
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Act
|
|
62
|
-
const result = await findContactByPhone.execute({
|
|
63
|
-
jwtToken: 'mock-jwt-token',
|
|
64
|
-
phoneNumber: '+1234567890'
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Assert
|
|
68
|
-
expect(result).toEqual({
|
|
69
|
-
success: true,
|
|
70
|
-
data: mockContact
|
|
71
|
-
});
|
|
72
|
-
expect(jwt.decodeJwt).toHaveBeenCalledWith('mock-jwt-token');
|
|
73
|
-
expect(connectorRegistry.getConnector).toHaveBeenCalledWith('testCRM');
|
|
74
|
-
expect(contactCore.findContact).toHaveBeenCalledWith({
|
|
75
|
-
platform: 'testCRM',
|
|
76
|
-
userId: 'user-123',
|
|
77
|
-
phoneNumber: '+1234567890',
|
|
78
|
-
overridingFormat: '',
|
|
79
|
-
isExtension: false
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('should handle overriding format parameter', async () => {
|
|
84
|
-
// Arrange
|
|
85
|
-
const mockContact = {
|
|
86
|
-
id: 'contact-456',
|
|
87
|
-
name: 'Jane Smith',
|
|
88
|
-
phone: '1234567890'
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
jwt.decodeJwt.mockReturnValue({
|
|
92
|
-
id: 'user-123',
|
|
93
|
-
platform: 'testCRM'
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const mockConnector = {
|
|
97
|
-
findContact: jest.fn()
|
|
98
|
-
};
|
|
99
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
100
|
-
|
|
101
|
-
contactCore.findContact.mockResolvedValue({
|
|
102
|
-
successful: true,
|
|
103
|
-
contact: mockContact
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Act
|
|
107
|
-
const result = await findContactByPhone.execute({
|
|
108
|
-
jwtToken: 'mock-jwt-token',
|
|
109
|
-
phoneNumber: '+1234567890',
|
|
110
|
-
overridingFormat: '1234567890'
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// Assert
|
|
114
|
-
expect(result.success).toBe(true);
|
|
115
|
-
expect(contactCore.findContact).toHaveBeenCalledWith({
|
|
116
|
-
platform: 'testCRM',
|
|
117
|
-
userId: 'user-123',
|
|
118
|
-
phoneNumber: '+1234567890',
|
|
119
|
-
overridingFormat: '1234567890',
|
|
120
|
-
isExtension: false
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('should handle isExtension parameter', async () => {
|
|
125
|
-
// Arrange
|
|
126
|
-
const mockContact = {
|
|
127
|
-
id: 'contact-789',
|
|
128
|
-
name: 'Bob Johnson',
|
|
129
|
-
phone: '101'
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
jwt.decodeJwt.mockReturnValue({
|
|
133
|
-
id: 'user-123',
|
|
134
|
-
platform: 'testCRM'
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const mockConnector = {
|
|
138
|
-
findContact: jest.fn()
|
|
139
|
-
};
|
|
140
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
141
|
-
|
|
142
|
-
contactCore.findContact.mockResolvedValue({
|
|
143
|
-
successful: true,
|
|
144
|
-
contact: mockContact
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
// Act
|
|
148
|
-
const result = await findContactByPhone.execute({
|
|
149
|
-
jwtToken: 'mock-jwt-token',
|
|
150
|
-
phoneNumber: '101',
|
|
151
|
-
isExtension: true
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// Assert
|
|
155
|
-
expect(result.success).toBe(true);
|
|
156
|
-
expect(contactCore.findContact).toHaveBeenCalledWith({
|
|
157
|
-
platform: 'testCRM',
|
|
158
|
-
userId: 'user-123',
|
|
159
|
-
phoneNumber: '101',
|
|
160
|
-
overridingFormat: '',
|
|
161
|
-
isExtension: true
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('should return error when contact not found', async () => {
|
|
166
|
-
// Arrange
|
|
167
|
-
jwt.decodeJwt.mockReturnValue({
|
|
168
|
-
id: 'user-123',
|
|
169
|
-
platform: 'testCRM'
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const mockConnector = {
|
|
173
|
-
findContact: jest.fn()
|
|
174
|
-
};
|
|
175
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
176
|
-
|
|
177
|
-
contactCore.findContact.mockResolvedValue({
|
|
178
|
-
successful: false,
|
|
179
|
-
contact: null,
|
|
180
|
-
returnMessage: { message: 'Contact not found' }
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// Act
|
|
184
|
-
const result = await findContactByPhone.execute({
|
|
185
|
-
jwtToken: 'mock-jwt-token',
|
|
186
|
-
phoneNumber: '+9999999999'
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// Assert
|
|
190
|
-
expect(result).toEqual({
|
|
191
|
-
success: false,
|
|
192
|
-
error: 'Contact not found'
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test('should return error when JWT is invalid', async () => {
|
|
197
|
-
// Arrange
|
|
198
|
-
jwt.decodeJwt.mockReturnValue({
|
|
199
|
-
platform: 'testCRM'
|
|
200
|
-
// id is missing
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
// Act
|
|
204
|
-
const result = await findContactByPhone.execute({
|
|
205
|
-
jwtToken: 'invalid-token',
|
|
206
|
-
phoneNumber: '+1234567890'
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// Assert
|
|
210
|
-
expect(result.success).toBe(false);
|
|
211
|
-
expect(result.error).toContain('Invalid JWT token');
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test('should return error when decodeJwt returns null', async () => {
|
|
215
|
-
jwt.decodeJwt.mockReturnValue(null);
|
|
216
|
-
|
|
217
|
-
const result = await findContactByPhone.execute({
|
|
218
|
-
jwtToken: 'invalid-token',
|
|
219
|
-
phoneNumber: '+1234567890'
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
expect(result.success).toBe(false);
|
|
223
|
-
expect(result.error).toContain('Invalid JWT token');
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
test('should return error when platform connector not found', async () => {
|
|
227
|
-
// Arrange
|
|
228
|
-
jwt.decodeJwt.mockReturnValue({
|
|
229
|
-
id: 'user-123',
|
|
230
|
-
platform: 'unknownCRM'
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
connectorRegistry.getConnector.mockReturnValue(null);
|
|
234
|
-
|
|
235
|
-
// Act
|
|
236
|
-
const result = await findContactByPhone.execute({
|
|
237
|
-
jwtToken: 'mock-jwt-token',
|
|
238
|
-
phoneNumber: '+1234567890'
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// Assert
|
|
242
|
-
expect(result.success).toBe(false);
|
|
243
|
-
expect(result.error).toContain('Platform connector not found');
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
test('should return error when findContact is not implemented', async () => {
|
|
247
|
-
// Arrange
|
|
248
|
-
jwt.decodeJwt.mockReturnValue({
|
|
249
|
-
id: 'user-123',
|
|
250
|
-
platform: 'testCRM'
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
const mockConnector = {}; // No findContact method
|
|
254
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
255
|
-
|
|
256
|
-
// Act
|
|
257
|
-
const result = await findContactByPhone.execute({
|
|
258
|
-
jwtToken: 'mock-jwt-token',
|
|
259
|
-
phoneNumber: '+1234567890'
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// Assert
|
|
263
|
-
expect(result.success).toBe(false);
|
|
264
|
-
expect(result.error).toContain('not implemented');
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
test('should handle unexpected errors gracefully', async () => {
|
|
268
|
-
// Arrange
|
|
269
|
-
jwt.decodeJwt.mockReturnValue({
|
|
270
|
-
id: 'user-123',
|
|
271
|
-
platform: 'testCRM'
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
const mockConnector = {
|
|
275
|
-
findContact: jest.fn()
|
|
276
|
-
};
|
|
277
|
-
connectorRegistry.getConnector.mockReturnValue(mockConnector);
|
|
278
|
-
|
|
279
|
-
contactCore.findContact.mockRejectedValue(
|
|
280
|
-
new Error('Database connection failed')
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
// Act
|
|
284
|
-
const result = await findContactByPhone.execute({
|
|
285
|
-
jwtToken: 'mock-jwt-token',
|
|
286
|
-
phoneNumber: '+1234567890'
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
// Assert
|
|
290
|
-
expect(result.success).toBe(false);
|
|
291
|
-
expect(result.error).toBe('Database connection failed');
|
|
292
|
-
expect(result.errorDetails).toBeDefined();
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
|