@app-connect/core 1.7.5 → 1.7.10
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/handlers/admin.js +29 -17
- package/handlers/auth.js +10 -4
- package/handlers/calldown.js +33 -0
- package/handlers/contact.js +54 -3
- package/handlers/log.js +4 -4
- package/index.js +377 -163
- package/lib/debugTracer.js +159 -0
- package/lib/oauth.js +26 -18
- package/lib/ringcentral.js +2 -2
- package/lib/s3ErrorLogReport.js +66 -0
- package/models/accountDataModel.js +34 -0
- package/package.json +70 -67
- package/releaseNotes.json +68 -0
- package/test/connector/registry.test.js +145 -0
- package/test/handlers/admin.test.js +583 -0
- package/test/handlers/auth.test.js +355 -0
- package/test/handlers/contact.test.js +852 -0
- package/test/handlers/log.test.js +868 -0
- package/test/lib/callLogComposer.test.js +1231 -0
- package/test/lib/debugTracer.test.js +328 -0
- package/test/lib/oauth.test.js +359 -0
- package/test/lib/ringcentral.test.js +473 -0
- package/test/lib/util.test.js +282 -0
- package/test/models/accountDataModel.test.js +98 -0
- package/test/models/dynamo/connectorSchema.test.js +189 -0
- package/test/models/models.test.js +539 -0
- package/test/setup.js +176 -176
package/test/setup.js
CHANGED
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
// Test setup for @app-connect/core package
|
|
2
|
-
const path = require('path');
|
|
3
|
-
require('dotenv').config({ path: path.resolve(__dirname, '../.env.test') });
|
|
4
|
-
|
|
5
|
-
// Set test timeout
|
|
6
|
-
jest.setTimeout(30000);
|
|
7
|
-
|
|
8
|
-
// Mock console methods to reduce noise in tests
|
|
9
|
-
global.console = {
|
|
10
|
-
...console,
|
|
11
|
-
log: jest.fn(),
|
|
12
|
-
debug: jest.fn(),
|
|
13
|
-
info: jest.fn(),
|
|
14
|
-
warn: jest.fn(),
|
|
15
|
-
error: jest.fn(),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// Setup database models for testing
|
|
19
|
-
beforeAll(async () => {
|
|
20
|
-
try {
|
|
21
|
-
// Set up test database URL if not provided
|
|
22
|
-
if (!process.env.DATABASE_URL) {
|
|
23
|
-
process.env.DATABASE_URL = 'sqlite::memory:';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Import models
|
|
27
|
-
const { CallLogModel } = require('../models/callLogModel');
|
|
28
|
-
const { MessageLogModel } = require('../models/messageLogModel');
|
|
29
|
-
const { UserModel } = require('../models/userModel');
|
|
30
|
-
const { CacheModel } = require('../models/cacheModel');
|
|
31
|
-
const { AdminConfigModel } = require('../models/adminConfigModel');
|
|
32
|
-
|
|
33
|
-
// Sync database models
|
|
34
|
-
await CallLogModel.sync({ force: true });
|
|
35
|
-
await MessageLogModel.sync({ force: true });
|
|
36
|
-
await UserModel.sync({ force: true });
|
|
37
|
-
await CacheModel.sync({ force: true });
|
|
38
|
-
await AdminConfigModel.sync({ force: true });
|
|
39
|
-
|
|
40
|
-
console.log('Database models synced for testing');
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.error('Error setting up test database:', error);
|
|
43
|
-
// Don't fail the setup, some tests might not need database
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// Clean up after all tests
|
|
48
|
-
afterAll(async () => {
|
|
49
|
-
try {
|
|
50
|
-
// Close database connections
|
|
51
|
-
const { sequelize } = require('../models/sequelize');
|
|
52
|
-
if (sequelize) {
|
|
53
|
-
await sequelize.close();
|
|
54
|
-
}
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error('Error closing database connection:', error);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Global test utilities
|
|
61
|
-
global.testUtils = {
|
|
62
|
-
// Helper to create mock user
|
|
63
|
-
createMockUser: (overrides = {}) => ({
|
|
64
|
-
id: 'test-user-id',
|
|
65
|
-
platform: 'testCRM',
|
|
66
|
-
accessToken: 'test-access-token',
|
|
67
|
-
refreshToken: 'test-refresh-token',
|
|
68
|
-
tokenExpiry: new Date(Date.now() + 3600000), // 1 hour from now
|
|
69
|
-
platformUserInfo: {
|
|
70
|
-
id: 'test-platform-user-id',
|
|
71
|
-
name: 'Test User',
|
|
72
|
-
timezoneName: 'America/Los_Angeles',
|
|
73
|
-
timezoneOffset: 0,
|
|
74
|
-
platformAdditionalInfo: {}
|
|
75
|
-
},
|
|
76
|
-
...overrides
|
|
77
|
-
}),
|
|
78
|
-
|
|
79
|
-
// Helper to create mock call log
|
|
80
|
-
createMockCallLog: (overrides = {}) => ({
|
|
81
|
-
id: 'test-call-log-id',
|
|
82
|
-
userId: 'test-user-id',
|
|
83
|
-
platform: 'testCRM',
|
|
84
|
-
thirdPartyLogId: 'test-third-party-id',
|
|
85
|
-
contactId: 'test-contact-id',
|
|
86
|
-
contactType: 'Contact',
|
|
87
|
-
phoneNumber: '+1234567890',
|
|
88
|
-
callDirection: 'Inbound',
|
|
89
|
-
callResult: 'Answered',
|
|
90
|
-
callDuration: 120,
|
|
91
|
-
callStartTime: new Date(),
|
|
92
|
-
callEndTime: new Date(Date.now() + 120000),
|
|
93
|
-
recordingLink: 'https://example.com/recording.mp3',
|
|
94
|
-
subject: 'Test Call',
|
|
95
|
-
note: 'Test call note',
|
|
96
|
-
...overrides
|
|
97
|
-
}),
|
|
98
|
-
|
|
99
|
-
// Helper to create mock contact
|
|
100
|
-
createMockContact: (overrides = {}) => ({
|
|
101
|
-
id: 'test-contact-id',
|
|
102
|
-
name: 'Test Contact',
|
|
103
|
-
type: 'Contact',
|
|
104
|
-
phone: '+1234567890',
|
|
105
|
-
additionalInfo: null,
|
|
106
|
-
...overrides
|
|
107
|
-
}),
|
|
108
|
-
|
|
109
|
-
// Helper to reset connector registry
|
|
110
|
-
resetConnectorRegistry: () => {
|
|
111
|
-
const connectorRegistry = require('../connector/registry');
|
|
112
|
-
connectorRegistry.connectors.clear();
|
|
113
|
-
connectorRegistry.manifests.clear();
|
|
114
|
-
connectorRegistry.platformInterfaces.clear();
|
|
115
|
-
connectorRegistry.releaseNotes = {};
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
// Helper to create mock connector
|
|
119
|
-
createMockConnector: (overrides = {}) => ({
|
|
120
|
-
getAuthType: jest.fn().mockReturnValue('apiKey'),
|
|
121
|
-
getUserInfo: jest.fn().mockResolvedValue({
|
|
122
|
-
successful: true,
|
|
123
|
-
platformUserInfo: {
|
|
124
|
-
id: 'test-user-id',
|
|
125
|
-
name: 'Test User',
|
|
126
|
-
timezoneName: 'America/Los_Angeles',
|
|
127
|
-
timezoneOffset: 0,
|
|
128
|
-
platformAdditionalInfo: {}
|
|
129
|
-
}
|
|
130
|
-
}),
|
|
131
|
-
createCallLog: jest.fn().mockResolvedValue({
|
|
132
|
-
logId: 'test-log-id',
|
|
133
|
-
returnMessage: {
|
|
134
|
-
message: 'Call logged successfully',
|
|
135
|
-
messageType: 'success',
|
|
136
|
-
ttl: 2000
|
|
137
|
-
}
|
|
138
|
-
}),
|
|
139
|
-
updateCallLog: jest.fn().mockResolvedValue({
|
|
140
|
-
updatedNote: 'Call log updated',
|
|
141
|
-
returnMessage: {
|
|
142
|
-
message: 'Call log updated successfully',
|
|
143
|
-
messageType: 'success',
|
|
144
|
-
ttl: 2000
|
|
145
|
-
}
|
|
146
|
-
}),
|
|
147
|
-
unAuthorize: jest.fn().mockResolvedValue({
|
|
148
|
-
returnMessage: {
|
|
149
|
-
messageType: 'success',
|
|
150
|
-
message: 'Logged out successfully',
|
|
151
|
-
ttl: 1000
|
|
152
|
-
}
|
|
153
|
-
}),
|
|
154
|
-
findContact: jest.fn().mockResolvedValue([
|
|
155
|
-
{
|
|
156
|
-
id: 'test-contact-id',
|
|
157
|
-
name: 'Test Contact',
|
|
158
|
-
type: 'Contact',
|
|
159
|
-
phone: '+1234567890',
|
|
160
|
-
additionalInfo: null
|
|
161
|
-
}
|
|
162
|
-
]),
|
|
163
|
-
createContact: jest.fn().mockResolvedValue({
|
|
164
|
-
contactInfo: {
|
|
165
|
-
id: 'new-contact-id',
|
|
166
|
-
name: 'New Contact'
|
|
167
|
-
},
|
|
168
|
-
returnMessage: {
|
|
169
|
-
message: 'Contact created successfully',
|
|
170
|
-
messageType: 'success',
|
|
171
|
-
ttl: 2000
|
|
172
|
-
}
|
|
173
|
-
}),
|
|
174
|
-
...overrides
|
|
175
|
-
})
|
|
176
|
-
};
|
|
1
|
+
// Test setup for @app-connect/core package
|
|
2
|
+
const path = require('path');
|
|
3
|
+
require('dotenv').config({ path: path.resolve(__dirname, '../.env.test') });
|
|
4
|
+
|
|
5
|
+
// Set test timeout
|
|
6
|
+
jest.setTimeout(30000);
|
|
7
|
+
|
|
8
|
+
// Mock console methods to reduce noise in tests
|
|
9
|
+
global.console = {
|
|
10
|
+
...console,
|
|
11
|
+
log: jest.fn(),
|
|
12
|
+
debug: jest.fn(),
|
|
13
|
+
info: jest.fn(),
|
|
14
|
+
warn: jest.fn(),
|
|
15
|
+
error: jest.fn(),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Setup database models for testing
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
try {
|
|
21
|
+
// Set up test database URL if not provided
|
|
22
|
+
if (!process.env.DATABASE_URL) {
|
|
23
|
+
process.env.DATABASE_URL = 'sqlite::memory:';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Import models
|
|
27
|
+
const { CallLogModel } = require('../models/callLogModel');
|
|
28
|
+
const { MessageLogModel } = require('../models/messageLogModel');
|
|
29
|
+
const { UserModel } = require('../models/userModel');
|
|
30
|
+
const { CacheModel } = require('../models/cacheModel');
|
|
31
|
+
const { AdminConfigModel } = require('../models/adminConfigModel');
|
|
32
|
+
|
|
33
|
+
// Sync database models
|
|
34
|
+
await CallLogModel.sync({ force: true });
|
|
35
|
+
await MessageLogModel.sync({ force: true });
|
|
36
|
+
await UserModel.sync({ force: true });
|
|
37
|
+
await CacheModel.sync({ force: true });
|
|
38
|
+
await AdminConfigModel.sync({ force: true });
|
|
39
|
+
|
|
40
|
+
console.log('Database models synced for testing');
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error('Error setting up test database:', error);
|
|
43
|
+
// Don't fail the setup, some tests might not need database
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Clean up after all tests
|
|
48
|
+
afterAll(async () => {
|
|
49
|
+
try {
|
|
50
|
+
// Close database connections
|
|
51
|
+
const { sequelize } = require('../models/sequelize');
|
|
52
|
+
if (sequelize) {
|
|
53
|
+
await sequelize.close();
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error('Error closing database connection:', error);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Global test utilities
|
|
61
|
+
global.testUtils = {
|
|
62
|
+
// Helper to create mock user
|
|
63
|
+
createMockUser: (overrides = {}) => ({
|
|
64
|
+
id: 'test-user-id',
|
|
65
|
+
platform: 'testCRM',
|
|
66
|
+
accessToken: 'test-access-token',
|
|
67
|
+
refreshToken: 'test-refresh-token',
|
|
68
|
+
tokenExpiry: new Date(Date.now() + 3600000), // 1 hour from now
|
|
69
|
+
platformUserInfo: {
|
|
70
|
+
id: 'test-platform-user-id',
|
|
71
|
+
name: 'Test User',
|
|
72
|
+
timezoneName: 'America/Los_Angeles',
|
|
73
|
+
timezoneOffset: 0,
|
|
74
|
+
platformAdditionalInfo: {}
|
|
75
|
+
},
|
|
76
|
+
...overrides
|
|
77
|
+
}),
|
|
78
|
+
|
|
79
|
+
// Helper to create mock call log
|
|
80
|
+
createMockCallLog: (overrides = {}) => ({
|
|
81
|
+
id: 'test-call-log-id',
|
|
82
|
+
userId: 'test-user-id',
|
|
83
|
+
platform: 'testCRM',
|
|
84
|
+
thirdPartyLogId: 'test-third-party-id',
|
|
85
|
+
contactId: 'test-contact-id',
|
|
86
|
+
contactType: 'Contact',
|
|
87
|
+
phoneNumber: '+1234567890',
|
|
88
|
+
callDirection: 'Inbound',
|
|
89
|
+
callResult: 'Answered',
|
|
90
|
+
callDuration: 120,
|
|
91
|
+
callStartTime: new Date(),
|
|
92
|
+
callEndTime: new Date(Date.now() + 120000),
|
|
93
|
+
recordingLink: 'https://example.com/recording.mp3',
|
|
94
|
+
subject: 'Test Call',
|
|
95
|
+
note: 'Test call note',
|
|
96
|
+
...overrides
|
|
97
|
+
}),
|
|
98
|
+
|
|
99
|
+
// Helper to create mock contact
|
|
100
|
+
createMockContact: (overrides = {}) => ({
|
|
101
|
+
id: 'test-contact-id',
|
|
102
|
+
name: 'Test Contact',
|
|
103
|
+
type: 'Contact',
|
|
104
|
+
phone: '+1234567890',
|
|
105
|
+
additionalInfo: null,
|
|
106
|
+
...overrides
|
|
107
|
+
}),
|
|
108
|
+
|
|
109
|
+
// Helper to reset connector registry
|
|
110
|
+
resetConnectorRegistry: () => {
|
|
111
|
+
const connectorRegistry = require('../connector/registry');
|
|
112
|
+
connectorRegistry.connectors.clear();
|
|
113
|
+
connectorRegistry.manifests.clear();
|
|
114
|
+
connectorRegistry.platformInterfaces.clear();
|
|
115
|
+
connectorRegistry.releaseNotes = {};
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
// Helper to create mock connector
|
|
119
|
+
createMockConnector: (overrides = {}) => ({
|
|
120
|
+
getAuthType: jest.fn().mockReturnValue('apiKey'),
|
|
121
|
+
getUserInfo: jest.fn().mockResolvedValue({
|
|
122
|
+
successful: true,
|
|
123
|
+
platformUserInfo: {
|
|
124
|
+
id: 'test-user-id',
|
|
125
|
+
name: 'Test User',
|
|
126
|
+
timezoneName: 'America/Los_Angeles',
|
|
127
|
+
timezoneOffset: 0,
|
|
128
|
+
platformAdditionalInfo: {}
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
createCallLog: jest.fn().mockResolvedValue({
|
|
132
|
+
logId: 'test-log-id',
|
|
133
|
+
returnMessage: {
|
|
134
|
+
message: 'Call logged successfully',
|
|
135
|
+
messageType: 'success',
|
|
136
|
+
ttl: 2000
|
|
137
|
+
}
|
|
138
|
+
}),
|
|
139
|
+
updateCallLog: jest.fn().mockResolvedValue({
|
|
140
|
+
updatedNote: 'Call log updated',
|
|
141
|
+
returnMessage: {
|
|
142
|
+
message: 'Call log updated successfully',
|
|
143
|
+
messageType: 'success',
|
|
144
|
+
ttl: 2000
|
|
145
|
+
}
|
|
146
|
+
}),
|
|
147
|
+
unAuthorize: jest.fn().mockResolvedValue({
|
|
148
|
+
returnMessage: {
|
|
149
|
+
messageType: 'success',
|
|
150
|
+
message: 'Logged out successfully',
|
|
151
|
+
ttl: 1000
|
|
152
|
+
}
|
|
153
|
+
}),
|
|
154
|
+
findContact: jest.fn().mockResolvedValue([
|
|
155
|
+
{
|
|
156
|
+
id: 'test-contact-id',
|
|
157
|
+
name: 'Test Contact',
|
|
158
|
+
type: 'Contact',
|
|
159
|
+
phone: '+1234567890',
|
|
160
|
+
additionalInfo: null
|
|
161
|
+
}
|
|
162
|
+
]),
|
|
163
|
+
createContact: jest.fn().mockResolvedValue({
|
|
164
|
+
contactInfo: {
|
|
165
|
+
id: 'new-contact-id',
|
|
166
|
+
name: 'New Contact'
|
|
167
|
+
},
|
|
168
|
+
returnMessage: {
|
|
169
|
+
message: 'Contact created successfully',
|
|
170
|
+
messageType: 'success',
|
|
171
|
+
ttl: 2000
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
...overrides
|
|
175
|
+
})
|
|
176
|
+
};
|