@friggframework/api-module-pipedrive 0.8.0
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/.eslintrc.json +3 -0
- package/api.js +117 -0
- package/defaultConfig.json +8 -0
- package/index.js +13 -0
- package/jest.config.js +3 -0
- package/manager.js +189 -0
- package/mocks/activities/createActivity.js +172 -0
- package/mocks/activities/deleteActivity.js +3 -0
- package/mocks/activities/listActivities.js +1538 -0
- package/mocks/activities/updateActivity.js +172 -0
- package/mocks/apiMock.js +28 -0
- package/mocks/deals/listDeals.js +236 -0
- package/models/credential.js +38 -0
- package/models/entity.js +26 -0
- package/package.json +24 -0
- package/test/Api.test.js +157 -0
- package/test/Manager.test.js +138 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
data: {
|
|
3
|
+
type: 'task',
|
|
4
|
+
id: 31,
|
|
5
|
+
attributes: {
|
|
6
|
+
action: 'email',
|
|
7
|
+
autoskipAt: null,
|
|
8
|
+
compiledSequenceTemplateHtml: null,
|
|
9
|
+
completed: false,
|
|
10
|
+
completedAt: null,
|
|
11
|
+
createdAt: '2021-11-06T02:52:48.000Z',
|
|
12
|
+
dueAt: '2021-11-06T02:52:48.000Z',
|
|
13
|
+
note: null,
|
|
14
|
+
opportunityAssociation: null,
|
|
15
|
+
scheduledAt: null,
|
|
16
|
+
state: 'incomplete',
|
|
17
|
+
stateChangedAt: null,
|
|
18
|
+
taskType: 'manual',
|
|
19
|
+
updatedAt: '2021-11-06T03:04:55.000Z',
|
|
20
|
+
},
|
|
21
|
+
relationships: {
|
|
22
|
+
account: {
|
|
23
|
+
data: {
|
|
24
|
+
type: 'account',
|
|
25
|
+
id: 3,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
call: {
|
|
29
|
+
data: null,
|
|
30
|
+
},
|
|
31
|
+
calls: {
|
|
32
|
+
links: {
|
|
33
|
+
related:
|
|
34
|
+
'https://api.pipedrive.io/api/v2/calls?filter%5Btask%5D%5Bid%5D=31',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
completer: {
|
|
38
|
+
data: null,
|
|
39
|
+
},
|
|
40
|
+
creator: {
|
|
41
|
+
data: {
|
|
42
|
+
type: 'user',
|
|
43
|
+
id: 1,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
defaultPluginMapping: {
|
|
47
|
+
data: null,
|
|
48
|
+
},
|
|
49
|
+
mailing: {
|
|
50
|
+
data: null,
|
|
51
|
+
},
|
|
52
|
+
mailings: {
|
|
53
|
+
links: {
|
|
54
|
+
related:
|
|
55
|
+
'https://api.pipedrive.io/api/v2/mailings?filter%5Btask%5D%5Bid%5D=31',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
opportunity: {
|
|
59
|
+
data: null,
|
|
60
|
+
},
|
|
61
|
+
owner: {
|
|
62
|
+
data: {
|
|
63
|
+
type: 'user',
|
|
64
|
+
id: 1,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
prospect: {
|
|
68
|
+
data: null,
|
|
69
|
+
},
|
|
70
|
+
prospectAccount: {
|
|
71
|
+
data: null,
|
|
72
|
+
},
|
|
73
|
+
prospectContacts: {
|
|
74
|
+
data: [],
|
|
75
|
+
links: {
|
|
76
|
+
related:
|
|
77
|
+
'https://api.pipedrive.io/api/v2/emailAddresses?filter%5Btask%5D%5Bid%5D=31',
|
|
78
|
+
},
|
|
79
|
+
meta: {
|
|
80
|
+
count: 0,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
prospectOwner: {
|
|
84
|
+
data: null,
|
|
85
|
+
},
|
|
86
|
+
prospectPhoneNumbers: {
|
|
87
|
+
data: [],
|
|
88
|
+
links: {
|
|
89
|
+
related:
|
|
90
|
+
'https://api.pipedrive.io/api/v2/phoneNumbers?filter%5Btask%5D%5Bid%5D=31',
|
|
91
|
+
},
|
|
92
|
+
meta: {
|
|
93
|
+
count: 0,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
prospectStage: {
|
|
97
|
+
data: null,
|
|
98
|
+
},
|
|
99
|
+
sequence: {
|
|
100
|
+
data: null,
|
|
101
|
+
},
|
|
102
|
+
sequenceSequenceSteps: {
|
|
103
|
+
data: [],
|
|
104
|
+
links: {
|
|
105
|
+
related:
|
|
106
|
+
'https://api.pipedrive.io/api/v2/sequenceSteps?filter%5Btask%5D%5Bid%5D=31',
|
|
107
|
+
},
|
|
108
|
+
meta: {
|
|
109
|
+
count: 0,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
sequenceState: {
|
|
113
|
+
data: null,
|
|
114
|
+
},
|
|
115
|
+
sequenceStateSequenceStep: {
|
|
116
|
+
data: null,
|
|
117
|
+
},
|
|
118
|
+
sequenceStateSequenceStepOverrides: {
|
|
119
|
+
data: [],
|
|
120
|
+
meta: {
|
|
121
|
+
count: 0,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
sequenceStateStartingTemplate: {
|
|
125
|
+
data: null,
|
|
126
|
+
},
|
|
127
|
+
sequenceStep: {
|
|
128
|
+
data: null,
|
|
129
|
+
},
|
|
130
|
+
sequenceStepOverrideTemplates: {
|
|
131
|
+
data: [],
|
|
132
|
+
links: {
|
|
133
|
+
related:
|
|
134
|
+
'https://api.pipedrive.io/api/v2/templates?filter%5Btask%5D%5Bid%5D=31',
|
|
135
|
+
},
|
|
136
|
+
meta: {
|
|
137
|
+
count: 0,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
sequenceTemplate: {
|
|
141
|
+
data: null,
|
|
142
|
+
},
|
|
143
|
+
sequenceTemplateTemplate: {
|
|
144
|
+
data: null,
|
|
145
|
+
},
|
|
146
|
+
subject: {
|
|
147
|
+
data: {
|
|
148
|
+
type: 'account',
|
|
149
|
+
id: 3,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
taskPriority: {
|
|
153
|
+
data: {
|
|
154
|
+
type: 'taskPriority',
|
|
155
|
+
id: 3,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
taskTheme: {
|
|
159
|
+
data: {
|
|
160
|
+
type: 'taskTheme',
|
|
161
|
+
id: 1,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
template: {
|
|
165
|
+
data: null,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
links: {
|
|
169
|
+
self: 'https://api.pipedrive.io/api/v2/tasks/31',
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
};
|
package/mocks/apiMock.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class MockApi {
|
|
2
|
+
constructor() {}
|
|
3
|
+
|
|
4
|
+
/** * Deals ** */
|
|
5
|
+
|
|
6
|
+
async listDeals() {
|
|
7
|
+
return require('./deals/listDeals');
|
|
8
|
+
}
|
|
9
|
+
/** * Activities ** */
|
|
10
|
+
|
|
11
|
+
async createActivity() {
|
|
12
|
+
return require('./activities/createActivity');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async listActivities() {
|
|
16
|
+
return require('./activities/listActivities');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async deleteActivity() {
|
|
20
|
+
return require('./activities/deleteActivity');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async updateActivity() {
|
|
24
|
+
return require('./activities/updateActivity');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = MockApi;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
success: true,
|
|
3
|
+
data: [
|
|
4
|
+
{
|
|
5
|
+
id: 1,
|
|
6
|
+
creator_user_id: {
|
|
7
|
+
id: 1811658,
|
|
8
|
+
name: 'Tom Elliott',
|
|
9
|
+
email: 'projectteam@lefthook.co',
|
|
10
|
+
has_pic: 1,
|
|
11
|
+
pic_hash: 'de38c66276cb325d7c0e84d4fae1f0ce',
|
|
12
|
+
active_flag: true,
|
|
13
|
+
value: 1811658,
|
|
14
|
+
},
|
|
15
|
+
user_id: {
|
|
16
|
+
id: 1811658,
|
|
17
|
+
name: 'Tom Elliott',
|
|
18
|
+
email: 'projectteam@lefthook.co',
|
|
19
|
+
has_pic: 1,
|
|
20
|
+
pic_hash: 'de38c66276cb325d7c0e84d4fae1f0ce',
|
|
21
|
+
active_flag: true,
|
|
22
|
+
value: 1811658,
|
|
23
|
+
},
|
|
24
|
+
person_id: {
|
|
25
|
+
active_flag: true,
|
|
26
|
+
name: 'Example Person',
|
|
27
|
+
email: [
|
|
28
|
+
{
|
|
29
|
+
value: '',
|
|
30
|
+
primary: true,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
phone: [
|
|
34
|
+
{
|
|
35
|
+
value: '',
|
|
36
|
+
primary: true,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
owner_id: 1811658,
|
|
40
|
+
value: 1,
|
|
41
|
+
},
|
|
42
|
+
org_id: null,
|
|
43
|
+
stage_id: 1,
|
|
44
|
+
title: 'Example Person deal',
|
|
45
|
+
value: 0,
|
|
46
|
+
currency: 'USD',
|
|
47
|
+
add_time: '2020-07-06 19:08:03',
|
|
48
|
+
update_time: '2020-07-06 19:08:03',
|
|
49
|
+
stage_change_time: null,
|
|
50
|
+
active: true,
|
|
51
|
+
deleted: false,
|
|
52
|
+
status: 'open',
|
|
53
|
+
probability: null,
|
|
54
|
+
next_activity_date: null,
|
|
55
|
+
next_activity_time: null,
|
|
56
|
+
next_activity_id: null,
|
|
57
|
+
last_activity_id: null,
|
|
58
|
+
last_activity_date: null,
|
|
59
|
+
lost_reason: null,
|
|
60
|
+
visible_to: '3',
|
|
61
|
+
close_time: null,
|
|
62
|
+
pipeline_id: 1,
|
|
63
|
+
won_time: null,
|
|
64
|
+
first_won_time: null,
|
|
65
|
+
lost_time: null,
|
|
66
|
+
products_count: 0,
|
|
67
|
+
files_count: 0,
|
|
68
|
+
notes_count: 0,
|
|
69
|
+
followers_count: 1,
|
|
70
|
+
email_messages_count: 0,
|
|
71
|
+
activities_count: 0,
|
|
72
|
+
done_activities_count: 0,
|
|
73
|
+
undone_activities_count: 0,
|
|
74
|
+
participants_count: 1,
|
|
75
|
+
expected_close_date: null,
|
|
76
|
+
last_incoming_mail_time: null,
|
|
77
|
+
last_outgoing_mail_time: null,
|
|
78
|
+
label: null,
|
|
79
|
+
renewal_type: 'one_time',
|
|
80
|
+
stage_order_nr: 1,
|
|
81
|
+
person_name: 'Example Person',
|
|
82
|
+
org_name: null,
|
|
83
|
+
next_activity_subject: null,
|
|
84
|
+
next_activity_type: null,
|
|
85
|
+
next_activity_duration: null,
|
|
86
|
+
next_activity_note: null,
|
|
87
|
+
group_id: null,
|
|
88
|
+
group_name: null,
|
|
89
|
+
formatted_value: '$0',
|
|
90
|
+
weighted_value: 0,
|
|
91
|
+
formatted_weighted_value: '$0',
|
|
92
|
+
weighted_value_currency: 'USD',
|
|
93
|
+
rotten_time: null,
|
|
94
|
+
owner_name: 'Tom Elliott',
|
|
95
|
+
cc_email: 'lefthook-sandbox-41e8b7+deal1@pipedrivemail.com',
|
|
96
|
+
org_hidden: false,
|
|
97
|
+
person_hidden: false,
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: 2,
|
|
101
|
+
creator_user_id: {
|
|
102
|
+
id: 1811658,
|
|
103
|
+
name: 'Tom Elliott',
|
|
104
|
+
email: 'projectteam@lefthook.co',
|
|
105
|
+
has_pic: 1,
|
|
106
|
+
pic_hash: 'de38c66276cb325d7c0e84d4fae1f0ce',
|
|
107
|
+
active_flag: true,
|
|
108
|
+
value: 1811658,
|
|
109
|
+
},
|
|
110
|
+
user_id: {
|
|
111
|
+
id: 1811658,
|
|
112
|
+
name: 'Tom Elliott',
|
|
113
|
+
email: 'projectteam@lefthook.co',
|
|
114
|
+
has_pic: 1,
|
|
115
|
+
pic_hash: 'de38c66276cb325d7c0e84d4fae1f0ce',
|
|
116
|
+
active_flag: true,
|
|
117
|
+
value: 1811658,
|
|
118
|
+
},
|
|
119
|
+
person_id: null,
|
|
120
|
+
org_id: {
|
|
121
|
+
name: 'Left Hook',
|
|
122
|
+
people_count: 0,
|
|
123
|
+
owner_id: 1811658,
|
|
124
|
+
address: null,
|
|
125
|
+
active_flag: true,
|
|
126
|
+
cc_email: 'lefthook-sandbox-41e8b7@pipedrivemail.com',
|
|
127
|
+
value: 1,
|
|
128
|
+
},
|
|
129
|
+
stage_id: 1,
|
|
130
|
+
title: 'New Deal gotta find person',
|
|
131
|
+
value: 0,
|
|
132
|
+
currency: 'USD',
|
|
133
|
+
add_time: '2021-11-19 19:14:43',
|
|
134
|
+
update_time: '2021-11-19 19:14:43',
|
|
135
|
+
stage_change_time: null,
|
|
136
|
+
active: true,
|
|
137
|
+
deleted: false,
|
|
138
|
+
status: 'open',
|
|
139
|
+
probability: null,
|
|
140
|
+
next_activity_date: null,
|
|
141
|
+
next_activity_time: null,
|
|
142
|
+
next_activity_id: null,
|
|
143
|
+
last_activity_id: null,
|
|
144
|
+
last_activity_date: null,
|
|
145
|
+
lost_reason: null,
|
|
146
|
+
visible_to: '3',
|
|
147
|
+
close_time: null,
|
|
148
|
+
pipeline_id: 1,
|
|
149
|
+
won_time: null,
|
|
150
|
+
first_won_time: null,
|
|
151
|
+
lost_time: null,
|
|
152
|
+
products_count: 0,
|
|
153
|
+
files_count: 0,
|
|
154
|
+
notes_count: 0,
|
|
155
|
+
followers_count: 1,
|
|
156
|
+
email_messages_count: 0,
|
|
157
|
+
activities_count: 0,
|
|
158
|
+
done_activities_count: 0,
|
|
159
|
+
undone_activities_count: 0,
|
|
160
|
+
participants_count: 0,
|
|
161
|
+
expected_close_date: null,
|
|
162
|
+
last_incoming_mail_time: null,
|
|
163
|
+
last_outgoing_mail_time: null,
|
|
164
|
+
label: null,
|
|
165
|
+
renewal_type: 'one_time',
|
|
166
|
+
stage_order_nr: 1,
|
|
167
|
+
person_name: null,
|
|
168
|
+
org_name: 'Left Hook',
|
|
169
|
+
next_activity_subject: null,
|
|
170
|
+
next_activity_type: null,
|
|
171
|
+
next_activity_duration: null,
|
|
172
|
+
next_activity_note: null,
|
|
173
|
+
group_id: null,
|
|
174
|
+
group_name: null,
|
|
175
|
+
formatted_value: '$0',
|
|
176
|
+
weighted_value: 0,
|
|
177
|
+
formatted_weighted_value: '$0',
|
|
178
|
+
weighted_value_currency: 'USD',
|
|
179
|
+
rotten_time: null,
|
|
180
|
+
owner_name: 'Tom Elliott',
|
|
181
|
+
cc_email: 'lefthook-sandbox-41e8b7+deal2@pipedrivemail.com',
|
|
182
|
+
org_hidden: false,
|
|
183
|
+
person_hidden: false,
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
additional_data: {
|
|
187
|
+
pagination: {
|
|
188
|
+
start: 0,
|
|
189
|
+
limit: 100,
|
|
190
|
+
more_items_in_collection: false,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
related_objects: {
|
|
194
|
+
user: {
|
|
195
|
+
1811658: {
|
|
196
|
+
id: 1811658,
|
|
197
|
+
name: 'Tom Elliott',
|
|
198
|
+
email: 'projectteam@lefthook.co',
|
|
199
|
+
has_pic: 1,
|
|
200
|
+
pic_hash: 'de38c66276cb325d7c0e84d4fae1f0ce',
|
|
201
|
+
active_flag: true,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
person: {
|
|
205
|
+
1: {
|
|
206
|
+
active_flag: true,
|
|
207
|
+
id: 1,
|
|
208
|
+
name: 'Example Person',
|
|
209
|
+
email: [
|
|
210
|
+
{
|
|
211
|
+
value: '',
|
|
212
|
+
primary: true,
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
phone: [
|
|
216
|
+
{
|
|
217
|
+
value: '',
|
|
218
|
+
primary: true,
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
owner_id: 1811658,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
organization: {
|
|
225
|
+
1: {
|
|
226
|
+
id: 1,
|
|
227
|
+
name: 'Left Hook',
|
|
228
|
+
people_count: 0,
|
|
229
|
+
owner_id: 1811658,
|
|
230
|
+
address: null,
|
|
231
|
+
active_flag: true,
|
|
232
|
+
cc_email: 'lefthook-sandbox-41e8b7@pipedrivemail.com',
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
const MongooseUtil = require('../../../utils/MongooseUtil');
|
|
3
|
+
const Parent = require('../../../base/models/Credential');
|
|
4
|
+
|
|
5
|
+
const collectionName = 'PipedriveCredentials';
|
|
6
|
+
const parentModelObject = new Parent();
|
|
7
|
+
|
|
8
|
+
const _schema = new mongoose.Schema({
|
|
9
|
+
accessToken: {
|
|
10
|
+
type: String,
|
|
11
|
+
trim: true,
|
|
12
|
+
lhEncrypt: true,
|
|
13
|
+
},
|
|
14
|
+
refreshToken: {
|
|
15
|
+
type: String,
|
|
16
|
+
trim: true,
|
|
17
|
+
lhEncrypt: true,
|
|
18
|
+
},
|
|
19
|
+
companyDomain: { type: String },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const _model = MongooseUtil.createModel(
|
|
23
|
+
collectionName,
|
|
24
|
+
_schema,
|
|
25
|
+
parentModelObject
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
class Credential extends Parent {
|
|
29
|
+
static Schema = _schema;
|
|
30
|
+
|
|
31
|
+
static Model = _model;
|
|
32
|
+
|
|
33
|
+
constructor(model = _model) {
|
|
34
|
+
super(model);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = Credential;
|
package/models/entity.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const mongoose = require('mongoose');
|
|
3
|
+
const MongooseUtil = require('../../../utils/MongooseUtil');
|
|
4
|
+
const Parent = require('../../../base/models/Entity');
|
|
5
|
+
|
|
6
|
+
const collectionName = 'PipedriveEntity';
|
|
7
|
+
const parentModelObject = new Parent();
|
|
8
|
+
|
|
9
|
+
const _schema = new mongoose.Schema({});
|
|
10
|
+
|
|
11
|
+
const _model = MongooseUtil.createModel(
|
|
12
|
+
collectionName,
|
|
13
|
+
_schema,
|
|
14
|
+
parentModelObject
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
class Entity extends Parent {
|
|
18
|
+
static Schema = _schema;
|
|
19
|
+
static Model = _model;
|
|
20
|
+
|
|
21
|
+
constructor(model = _model) {
|
|
22
|
+
super(model);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = Entity;
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.8.0",
|
|
3
|
+
"name": "@friggframework/api-module-pipedrive",
|
|
4
|
+
"prettier": "@friggframework/prettier-config",
|
|
5
|
+
"description": "",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint:fix": "prettier --write --loglevel error . && eslint . --fix",
|
|
9
|
+
"test": "jest"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@friggframework/eslint-config": "^1.0.0",
|
|
15
|
+
"@friggframework/test-environment": "^1.0.0",
|
|
16
|
+
"eslint": "^7.32.0",
|
|
17
|
+
"jest": "^27.4.7",
|
|
18
|
+
"prettier": "^2.5.1",
|
|
19
|
+
"sinon": "^12.0.1"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@friggframework/module-plugin": "^1.0.0"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/test/Api.test.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
const chai = require('chai');
|
|
2
|
+
const { expect } = chai;
|
|
3
|
+
const should = chai.should();
|
|
4
|
+
const Api = require('../api');
|
|
5
|
+
const { mockApi } = require('../../../../test/utils/mockApi');
|
|
6
|
+
|
|
7
|
+
const MockedApi = mockApi(Api, {
|
|
8
|
+
authenticationMode: 'browser',
|
|
9
|
+
filteringScope: (url) => {
|
|
10
|
+
return /^https:[/][/].+[.]pipedrive[.]com/.test(url);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('Pipedrive API class', async () => {
|
|
15
|
+
let api;
|
|
16
|
+
before(async function () {
|
|
17
|
+
await MockedApi.initialize({ test: this.test });
|
|
18
|
+
api = await MockedApi.mock();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
after(async function () {
|
|
22
|
+
await MockedApi.clean({ test: this.test });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('User', async () => {
|
|
26
|
+
it('should list user profile', async () => {
|
|
27
|
+
const response = await api.getUser();
|
|
28
|
+
chai.assert.hasAllKeys(response.data, [
|
|
29
|
+
'id',
|
|
30
|
+
'name',
|
|
31
|
+
'company_country',
|
|
32
|
+
'company_domain',
|
|
33
|
+
'company_id',
|
|
34
|
+
'company_name',
|
|
35
|
+
'default_currency',
|
|
36
|
+
'locale',
|
|
37
|
+
'lang',
|
|
38
|
+
'last_login',
|
|
39
|
+
'language',
|
|
40
|
+
'email',
|
|
41
|
+
'phone',
|
|
42
|
+
'created',
|
|
43
|
+
'modified',
|
|
44
|
+
'signup_flow_variation',
|
|
45
|
+
'has_created_company',
|
|
46
|
+
'is_admin',
|
|
47
|
+
'active_flag',
|
|
48
|
+
'timezone_name',
|
|
49
|
+
'timezone_offset',
|
|
50
|
+
'role_id',
|
|
51
|
+
'icon_url',
|
|
52
|
+
'is_you',
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('Deals', async () => {
|
|
58
|
+
it('should list deals', async () => {
|
|
59
|
+
const response = await api.listDeals();
|
|
60
|
+
response.data.length.should.above(0);
|
|
61
|
+
response.data[0].should.have.property('id');
|
|
62
|
+
return response;
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('Activities', async () => {
|
|
67
|
+
const mockActivity = {};
|
|
68
|
+
it('should list all Activity Fields', async () => {
|
|
69
|
+
const response = await api.listActivityFields();
|
|
70
|
+
const isRequired = response.data.filter(
|
|
71
|
+
(field) => field.mandatory_flag
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
for (const field of isRequired) {
|
|
75
|
+
mockActivity[field.key] = 'blah';
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
it('should create an email activity', async () => {
|
|
79
|
+
const activity = {
|
|
80
|
+
subject: 'Example Activtiy from the local grave',
|
|
81
|
+
type: 'email',
|
|
82
|
+
due_date: new Date('2021-12-03T15:06:38.700Z'),
|
|
83
|
+
user_id: '1811658',
|
|
84
|
+
};
|
|
85
|
+
const response = await api.createActivity(activity);
|
|
86
|
+
response.success.should.equal(true);
|
|
87
|
+
});
|
|
88
|
+
it('should get activities', async () => {
|
|
89
|
+
const response = await api.listActivities({
|
|
90
|
+
query: {
|
|
91
|
+
user_id: 0, // Gets activities for all users, instead of just the auth'ed user
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
response.data[0].should.have.property('id');
|
|
95
|
+
response.data.length.should.above(0);
|
|
96
|
+
return response;
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('Users', async () => {
|
|
101
|
+
it('should get users', async () => {
|
|
102
|
+
const response = await api.listUsers();
|
|
103
|
+
response.data.should.be.an('array').of.length.greaterThan(0);
|
|
104
|
+
response.data[0].should.have.keys(
|
|
105
|
+
'active_flag',
|
|
106
|
+
'created',
|
|
107
|
+
'default_currency',
|
|
108
|
+
'email',
|
|
109
|
+
'has_created_company',
|
|
110
|
+
'icon_url',
|
|
111
|
+
'id',
|
|
112
|
+
'is_admin',
|
|
113
|
+
'is_you',
|
|
114
|
+
'lang',
|
|
115
|
+
'last_login',
|
|
116
|
+
'locale',
|
|
117
|
+
'modified',
|
|
118
|
+
'name',
|
|
119
|
+
'phone',
|
|
120
|
+
'role_id',
|
|
121
|
+
'signup_flow_variation',
|
|
122
|
+
'timezone_name',
|
|
123
|
+
'timezone_offset'
|
|
124
|
+
);
|
|
125
|
+
return response;
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('Bad Auth', async () => {
|
|
130
|
+
it('should refresh bad auth token', async () => {
|
|
131
|
+
// Needed to paste a valid JWT, otherwise it's testing the wrong error.
|
|
132
|
+
// TODO expand on other error types.
|
|
133
|
+
const badAccessToken =
|
|
134
|
+
'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzZWFuLm1hdHRoZXdzQGxlZnRob29rLmNvbSIsImlhdCI6MTYzNTUzMDk3OCwiZXhwIjoxNjM1NTM4MTc4LCJiZW50byI6ImFwcDFlIiwiYWN0Ijp7InN1YiI6IlZob0NzMFNRZ25Fa2RDanRkaFZLemV5bXBjNW9valZoRXB2am03Rjh1UVEiLCJuYW1lIjoiTGVmdCBIb29rIiwiaXNzIjoiZmxhZ3NoaXAiLCJ0eXBlIjoiYXBwIn0sIm9yZ191c2VyX2lkIjoxLCJhdWQiOiJMZWZ0IEhvb2siLCJzY29wZXMiOiJBSkFBOEFIUUFCQUJRQT09Iiwib3JnX2d1aWQiOiJmNzY3MDEzZC1mNTBiLTRlY2QtYjM1My0zNWU0MWQ5Y2RjNGIiLCJvcmdfc2hvcnRuYW1lIjoibGVmdGhvb2tzYW5kYm94In0.XFmIai0GpAePsYeA4MjRntZS3iW6effmKmIhT7SBzTQ';
|
|
135
|
+
api.access_token = badAccessToken;
|
|
136
|
+
|
|
137
|
+
await api.listDeals();
|
|
138
|
+
api.access_token.should.not.equal(badAccessToken);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should throw error with invalid refresh token', async () => {
|
|
142
|
+
try {
|
|
143
|
+
api.access_token =
|
|
144
|
+
'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzZWFuLm1hdHRoZXdzQGxlZnRob29rLmNvbSIsImlhdCI6MTYzNTUzMDk3OCwiZXhwIjoxNjM1NTM4MTc4LCJiZW50byI6ImFwcDFlIiwiYWN0Ijp7InN1YiI6IlZob0NzMFNRZ25Fa2RDanRkaFZLemV5bXBjNW9valZoRXB2am03Rjh1UVEiLCJuYW1lIjoiTGVmdCBIb29rIiwiaXNzIjoiZmxhZ3NoaXAiLCJ0eXBlIjoiYXBwIn0sIm9yZ191c2VyX2lkIjoxLCJhdWQiOiJMZWZ0IEhvb2siLCJzY29wZXMiOiJBSkFBOEFIUUFCQUJRQT09Iiwib3JnX2d1aWQiOiJmNzY3MDEzZC1mNTBiLTRlY2QtYjM1My0zNWU0MWQ5Y2RjNGIiLCJvcmdfc2hvcnRuYW1lIjoibGVmdGhvb2tzYW5kYm94In0.XFmIai0GpAePsYeA4MjRntZS3iW6effmKmIhT7SBzTQ';
|
|
145
|
+
api.refresh_token = 'nolongervalid';
|
|
146
|
+
await api.listDeals();
|
|
147
|
+
throw new Error('Expected error not thrown');
|
|
148
|
+
} catch (e) {
|
|
149
|
+
e.message.should.contain(
|
|
150
|
+
'-----------------------------------------------------\n' +
|
|
151
|
+
'An error ocurred while fetching an external resource.\n' +
|
|
152
|
+
'-----------------------------------------------------'
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|