@skriptfabrik/n8n-nodes-clockify-enhanced 0.4.0 → 0.4.3
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 +30 -0
- package/CHANGELOG.md +11 -0
- package/jest.config.ts +11 -0
- package/package.json +4 -4
- package/project.json +38 -0
- package/src/api.d.ts +12413 -0
- package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.spec.ts +920 -0
- package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.ts +387 -0
- package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.spec.ts +870 -0
- package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.ts +356 -0
- package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.ts +120 -0
- package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.ts +125 -0
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +13 -0
- package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.d.ts +0 -14
- package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.js +0 -216
- package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.js.map +0 -1
- package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.d.ts +0 -52
- package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.js +0 -297
- package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.js.map +0 -1
- package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.d.ts +0 -3
- package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.js +0 -117
- package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.js.map +0 -1
- package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.d.ts +0 -3
- package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.js +0 -122
- package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.js.map +0 -1
|
@@ -0,0 +1,870 @@
|
|
|
1
|
+
import type { Request } from 'express';
|
|
2
|
+
import { mock, mockClear, mockDeep } from 'jest-mock-extended';
|
|
3
|
+
import { clockifyApiRequest } from 'n8n-nodes-base/dist/nodes/Clockify/GenericFunctions';
|
|
4
|
+
import type {
|
|
5
|
+
IHookFunctions,
|
|
6
|
+
ILoadOptionsFunctions,
|
|
7
|
+
IWebhookFunctions,
|
|
8
|
+
} from 'n8n-workflow';
|
|
9
|
+
import { ClockifyEnhancedTrigger } from './ClockifyEnhancedTrigger.node';
|
|
10
|
+
|
|
11
|
+
jest.mock('n8n-nodes-base/dist/nodes/Clockify/GenericFunctions');
|
|
12
|
+
|
|
13
|
+
describe('ClockifyEnhancedTrigger', () => {
|
|
14
|
+
const hookFunctions = mockDeep<IHookFunctions>();
|
|
15
|
+
const loadOptionsFunctions = mockDeep<ILoadOptionsFunctions>();
|
|
16
|
+
const webhookFunctions = mockDeep<IWebhookFunctions>();
|
|
17
|
+
|
|
18
|
+
let trigger: ClockifyEnhancedTrigger;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
trigger = new ClockifyEnhancedTrigger();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
mockClear(hookFunctions);
|
|
26
|
+
mockClear(loadOptionsFunctions);
|
|
27
|
+
mockClear(webhookFunctions);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should be defined', () => {
|
|
31
|
+
expect(trigger).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should load workspaces', () => {
|
|
35
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue([
|
|
36
|
+
{
|
|
37
|
+
costRate: {
|
|
38
|
+
amount: 10500,
|
|
39
|
+
currency: 'USD',
|
|
40
|
+
},
|
|
41
|
+
currencies: [
|
|
42
|
+
{
|
|
43
|
+
code: 'USD',
|
|
44
|
+
id: '5b641568b07987035750505e',
|
|
45
|
+
isDefault: true,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
featureSubscriptionType: 'PREMIUM',
|
|
49
|
+
features: ['ADD_TIME_FOR_OTHERS', 'ADMIN_PANEL', 'ALERTS', 'APPROVAL'],
|
|
50
|
+
hourlyRate: {
|
|
51
|
+
amount: 10500,
|
|
52
|
+
currency: 'USD',
|
|
53
|
+
},
|
|
54
|
+
id: '64a687e29ae1f428e7ebe303',
|
|
55
|
+
imageUrl: 'https://www.url.com/imageurl-1234567890.jpg',
|
|
56
|
+
memberships: [
|
|
57
|
+
{
|
|
58
|
+
costRate: {
|
|
59
|
+
amount: 10500,
|
|
60
|
+
currency: 'USD',
|
|
61
|
+
},
|
|
62
|
+
hourlyRate: {
|
|
63
|
+
amount: 10500,
|
|
64
|
+
currency: 'USD',
|
|
65
|
+
},
|
|
66
|
+
membershipStatus: 'PENDING',
|
|
67
|
+
membershipType: 'PROJECT',
|
|
68
|
+
targetId: '64c777ddd3fcab07cfbb210c',
|
|
69
|
+
userId: '5a0ab5acb07987125438b60f',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
name: 'Cool Company',
|
|
73
|
+
workspaceSettings: {
|
|
74
|
+
adminOnlyPages: '["PROJECT","TEAM","REPORTS"]',
|
|
75
|
+
automaticLock: {
|
|
76
|
+
changeDay: 'FRIDAY',
|
|
77
|
+
dayOfMonth: 15,
|
|
78
|
+
firstDay: 'MONDAY',
|
|
79
|
+
olderThanPeriod: 'DAYS',
|
|
80
|
+
olderThanValue: 5,
|
|
81
|
+
type: 'WEEKLY',
|
|
82
|
+
},
|
|
83
|
+
canSeeTimeSheet: true,
|
|
84
|
+
canSeeTracker: true,
|
|
85
|
+
currencyFormat: 'CURRENCY_SPACE_VALUE',
|
|
86
|
+
defaultBillableProjects: true,
|
|
87
|
+
forceDescription: true,
|
|
88
|
+
forceProjects: true,
|
|
89
|
+
forceTags: true,
|
|
90
|
+
forceTasks: true,
|
|
91
|
+
isProjectPublicByDefault: true,
|
|
92
|
+
lockTimeEntries: 'string',
|
|
93
|
+
lockTimeZone: 'string',
|
|
94
|
+
multiFactorEnabled: true,
|
|
95
|
+
numberFormat: 'COMMA_PERIOD',
|
|
96
|
+
onlyAdminsCreateProject: true,
|
|
97
|
+
onlyAdminsCreateTag: true,
|
|
98
|
+
onlyAdminsCreateTask: true,
|
|
99
|
+
onlyAdminsSeeAllTimeEntries: true,
|
|
100
|
+
onlyAdminsSeeBillableRates: true,
|
|
101
|
+
onlyAdminsSeeDashboard: true,
|
|
102
|
+
onlyAdminsSeePublicProjectsEntries: true,
|
|
103
|
+
projectFavorites: true,
|
|
104
|
+
projectGroupingLabel: 'Project Label',
|
|
105
|
+
projectPickerSpecialFilter: true,
|
|
106
|
+
round: {
|
|
107
|
+
minutes: 'string',
|
|
108
|
+
round: 'string',
|
|
109
|
+
},
|
|
110
|
+
timeRoundingInReports: true,
|
|
111
|
+
timeTrackingMode: 'DEFAULT',
|
|
112
|
+
trackTimeDownToSecond: true,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
]);
|
|
116
|
+
|
|
117
|
+
expect(
|
|
118
|
+
trigger.methods.loadOptions.listWorkspaces.call(loadOptionsFunctions),
|
|
119
|
+
).resolves.toEqual([
|
|
120
|
+
{
|
|
121
|
+
name: 'Cool Company',
|
|
122
|
+
value: '64a687e29ae1f428e7ebe303',
|
|
123
|
+
},
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
127
|
+
'GET',
|
|
128
|
+
'workspaces',
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should not load workspaces because of undefined name', () => {
|
|
133
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue([
|
|
134
|
+
{
|
|
135
|
+
costRate: {
|
|
136
|
+
amount: 10500,
|
|
137
|
+
currency: 'USD',
|
|
138
|
+
},
|
|
139
|
+
currencies: [
|
|
140
|
+
{
|
|
141
|
+
code: 'USD',
|
|
142
|
+
id: '5b641568b07987035750505e',
|
|
143
|
+
isDefault: true,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
featureSubscriptionType: 'PREMIUM',
|
|
147
|
+
features: ['ADD_TIME_FOR_OTHERS', 'ADMIN_PANEL', 'ALERTS', 'APPROVAL'],
|
|
148
|
+
hourlyRate: {
|
|
149
|
+
amount: 10500,
|
|
150
|
+
currency: 'USD',
|
|
151
|
+
},
|
|
152
|
+
id: '64a687e29ae1f428e7ebe303',
|
|
153
|
+
imageUrl: 'https://www.url.com/imageurl-1234567890.jpg',
|
|
154
|
+
memberships: [
|
|
155
|
+
{
|
|
156
|
+
costRate: {
|
|
157
|
+
amount: 10500,
|
|
158
|
+
currency: 'USD',
|
|
159
|
+
},
|
|
160
|
+
hourlyRate: {
|
|
161
|
+
amount: 10500,
|
|
162
|
+
currency: 'USD',
|
|
163
|
+
},
|
|
164
|
+
membershipStatus: 'PENDING',
|
|
165
|
+
membershipType: 'PROJECT',
|
|
166
|
+
targetId: '64c777ddd3fcab07cfbb210c',
|
|
167
|
+
userId: '5a0ab5acb07987125438b60f',
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
name: undefined,
|
|
171
|
+
workspaceSettings: {
|
|
172
|
+
adminOnlyPages: '["PROJECT","TEAM","REPORTS"]',
|
|
173
|
+
automaticLock: {
|
|
174
|
+
changeDay: 'FRIDAY',
|
|
175
|
+
dayOfMonth: 15,
|
|
176
|
+
firstDay: 'MONDAY',
|
|
177
|
+
olderThanPeriod: 'DAYS',
|
|
178
|
+
olderThanValue: 5,
|
|
179
|
+
type: 'WEEKLY',
|
|
180
|
+
},
|
|
181
|
+
canSeeTimeSheet: true,
|
|
182
|
+
canSeeTracker: true,
|
|
183
|
+
currencyFormat: 'CURRENCY_SPACE_VALUE',
|
|
184
|
+
defaultBillableProjects: true,
|
|
185
|
+
forceDescription: true,
|
|
186
|
+
forceProjects: true,
|
|
187
|
+
forceTags: true,
|
|
188
|
+
forceTasks: true,
|
|
189
|
+
isProjectPublicByDefault: true,
|
|
190
|
+
lockTimeEntries: 'string',
|
|
191
|
+
lockTimeZone: 'string',
|
|
192
|
+
multiFactorEnabled: true,
|
|
193
|
+
numberFormat: 'COMMA_PERIOD',
|
|
194
|
+
onlyAdminsCreateProject: true,
|
|
195
|
+
onlyAdminsCreateTag: true,
|
|
196
|
+
onlyAdminsCreateTask: true,
|
|
197
|
+
onlyAdminsSeeAllTimeEntries: true,
|
|
198
|
+
onlyAdminsSeeBillableRates: true,
|
|
199
|
+
onlyAdminsSeeDashboard: true,
|
|
200
|
+
onlyAdminsSeePublicProjectsEntries: true,
|
|
201
|
+
projectFavorites: true,
|
|
202
|
+
projectGroupingLabel: 'Project Label',
|
|
203
|
+
projectPickerSpecialFilter: true,
|
|
204
|
+
round: {
|
|
205
|
+
minutes: 'string',
|
|
206
|
+
round: 'string',
|
|
207
|
+
},
|
|
208
|
+
timeRoundingInReports: true,
|
|
209
|
+
timeTrackingMode: 'DEFAULT',
|
|
210
|
+
trackTimeDownToSecond: true,
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
]);
|
|
214
|
+
|
|
215
|
+
expect(
|
|
216
|
+
trigger.methods.loadOptions.listWorkspaces.call(loadOptionsFunctions),
|
|
217
|
+
).resolves.toEqual([]);
|
|
218
|
+
|
|
219
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
220
|
+
'GET',
|
|
221
|
+
'workspaces',
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should not load workspaces because of undefined id', () => {
|
|
226
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue([
|
|
227
|
+
{
|
|
228
|
+
costRate: {
|
|
229
|
+
amount: 10500,
|
|
230
|
+
currency: 'USD',
|
|
231
|
+
},
|
|
232
|
+
currencies: [
|
|
233
|
+
{
|
|
234
|
+
code: 'USD',
|
|
235
|
+
id: '5b641568b07987035750505e',
|
|
236
|
+
isDefault: true,
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
featureSubscriptionType: 'PREMIUM',
|
|
240
|
+
features: ['ADD_TIME_FOR_OTHERS', 'ADMIN_PANEL', 'ALERTS', 'APPROVAL'],
|
|
241
|
+
hourlyRate: {
|
|
242
|
+
amount: 10500,
|
|
243
|
+
currency: 'USD',
|
|
244
|
+
},
|
|
245
|
+
id: undefined,
|
|
246
|
+
imageUrl: 'https://www.url.com/imageurl-1234567890.jpg',
|
|
247
|
+
memberships: [
|
|
248
|
+
{
|
|
249
|
+
costRate: {
|
|
250
|
+
amount: 10500,
|
|
251
|
+
currency: 'USD',
|
|
252
|
+
},
|
|
253
|
+
hourlyRate: {
|
|
254
|
+
amount: 10500,
|
|
255
|
+
currency: 'USD',
|
|
256
|
+
},
|
|
257
|
+
membershipStatus: 'PENDING',
|
|
258
|
+
membershipType: 'PROJECT',
|
|
259
|
+
targetId: '64c777ddd3fcab07cfbb210c',
|
|
260
|
+
userId: '5a0ab5acb07987125438b60f',
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
name: 'Cool Company',
|
|
264
|
+
workspaceSettings: {
|
|
265
|
+
adminOnlyPages: '["PROJECT","TEAM","REPORTS"]',
|
|
266
|
+
automaticLock: {
|
|
267
|
+
changeDay: 'FRIDAY',
|
|
268
|
+
dayOfMonth: 15,
|
|
269
|
+
firstDay: 'MONDAY',
|
|
270
|
+
olderThanPeriod: 'DAYS',
|
|
271
|
+
olderThanValue: 5,
|
|
272
|
+
type: 'WEEKLY',
|
|
273
|
+
},
|
|
274
|
+
canSeeTimeSheet: true,
|
|
275
|
+
canSeeTracker: true,
|
|
276
|
+
currencyFormat: 'CURRENCY_SPACE_VALUE',
|
|
277
|
+
defaultBillableProjects: true,
|
|
278
|
+
forceDescription: true,
|
|
279
|
+
forceProjects: true,
|
|
280
|
+
forceTags: true,
|
|
281
|
+
forceTasks: true,
|
|
282
|
+
isProjectPublicByDefault: true,
|
|
283
|
+
lockTimeEntries: 'string',
|
|
284
|
+
lockTimeZone: 'string',
|
|
285
|
+
multiFactorEnabled: true,
|
|
286
|
+
numberFormat: 'COMMA_PERIOD',
|
|
287
|
+
onlyAdminsCreateProject: true,
|
|
288
|
+
onlyAdminsCreateTag: true,
|
|
289
|
+
onlyAdminsCreateTask: true,
|
|
290
|
+
onlyAdminsSeeAllTimeEntries: true,
|
|
291
|
+
onlyAdminsSeeBillableRates: true,
|
|
292
|
+
onlyAdminsSeeDashboard: true,
|
|
293
|
+
onlyAdminsSeePublicProjectsEntries: true,
|
|
294
|
+
projectFavorites: true,
|
|
295
|
+
projectGroupingLabel: 'Project Label',
|
|
296
|
+
projectPickerSpecialFilter: true,
|
|
297
|
+
round: {
|
|
298
|
+
minutes: 'string',
|
|
299
|
+
round: 'string',
|
|
300
|
+
},
|
|
301
|
+
timeRoundingInReports: true,
|
|
302
|
+
timeTrackingMode: 'DEFAULT',
|
|
303
|
+
trackTimeDownToSecond: true,
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
]);
|
|
307
|
+
|
|
308
|
+
expect(
|
|
309
|
+
trigger.methods.loadOptions.listWorkspaces.call(loadOptionsFunctions),
|
|
310
|
+
).resolves.toEqual([]);
|
|
311
|
+
|
|
312
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
313
|
+
'GET',
|
|
314
|
+
'workspaces',
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should check that a webhook exists', async () => {
|
|
319
|
+
const workspaceId = '64a687e29ae1f428e7ebe303';
|
|
320
|
+
const webhookAuthToken =
|
|
321
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2NGI3YmU3YmUwODM1Yjc2ZDYzOTY5YTciLCJtdWx0aUZhY3RvciI6dHJ1ZSwiaXNzIjoiY2xvY2tpZnkiLCJuYW1lIjoiTWFydGluIExsb3lkIiwiZXhwIjoxNjkzMzY5MzEwLCJ0eXBlIjoiYWNjZXNzIiwiaWF0IjoxNjkzMzI2MTEwLCJqdGkiOiJZVGcxT0Raak9XTXRPRGRsWVMwME5qZ3hMVGxpTlRndE5UQmlOVEprTmpOaE';
|
|
322
|
+
const webhookId = '76a687e29ae1f428e7ebe101';
|
|
323
|
+
const webhookUrl =
|
|
324
|
+
'http://localhost:5678/webhook/c940f948-0c2e-4cba-9d47-1b38790d77bb';
|
|
325
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
326
|
+
webhookAuthToken: undefined,
|
|
327
|
+
webhookId: undefined,
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
hookFunctions.getNodeParameter
|
|
331
|
+
.calledWith('workspaceId')
|
|
332
|
+
.mockReturnValue(workspaceId);
|
|
333
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue({
|
|
334
|
+
webhooks: [
|
|
335
|
+
{
|
|
336
|
+
authToken: webhookAuthToken,
|
|
337
|
+
enabled: true,
|
|
338
|
+
id: webhookId,
|
|
339
|
+
name: 'stripe',
|
|
340
|
+
triggerSource: [
|
|
341
|
+
'54a687e29ae1f428e7ebe909',
|
|
342
|
+
'87p187e29ae1f428e7ebej56',
|
|
343
|
+
],
|
|
344
|
+
triggerSourceType: 'PROJECT_ID',
|
|
345
|
+
url: 'http://localhost:5678/webhook/c940f948-0c2e-4cba-9d47-1b38790d77bb',
|
|
346
|
+
userId: '5a0ab5acb07987125438b60f',
|
|
347
|
+
webhookEvent: 'NEW_PROJECT',
|
|
348
|
+
workspaceId: '64a687e29ae1f428e7ebe303',
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
workspaceWebhookCount: 5,
|
|
352
|
+
});
|
|
353
|
+
hookFunctions.getNodeWebhookUrl
|
|
354
|
+
.calledWith('default')
|
|
355
|
+
.mockReturnValue(webhookUrl);
|
|
356
|
+
hookFunctions.getWorkflowStaticData
|
|
357
|
+
.calledWith('node')
|
|
358
|
+
.mockReturnValue(staticData);
|
|
359
|
+
|
|
360
|
+
expect(
|
|
361
|
+
trigger.webhookMethods.default.checkExists.call(hookFunctions),
|
|
362
|
+
).resolves.toBe(true);
|
|
363
|
+
|
|
364
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
365
|
+
'GET',
|
|
366
|
+
`workspaces/${workspaceId}/webhooks`,
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
await new Promise(process.nextTick);
|
|
370
|
+
|
|
371
|
+
expect(staticData.webhookAuthToken).toBe(webhookAuthToken);
|
|
372
|
+
expect(staticData.webhookId).toBe(webhookId);
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('should check that a webhook does not exist because of invalid response', async () => {
|
|
376
|
+
const workspaceId = '64a687e29ae1f428e7ebe303';
|
|
377
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
378
|
+
webhookAuthToken: undefined,
|
|
379
|
+
webhookId: undefined,
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
hookFunctions.getNodeParameter
|
|
383
|
+
.calledWith('workspaceId')
|
|
384
|
+
.mockReturnValue(workspaceId);
|
|
385
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue({
|
|
386
|
+
webhooks: undefined,
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
expect(
|
|
390
|
+
trigger.webhookMethods.default.checkExists.call(hookFunctions),
|
|
391
|
+
).resolves.toBe(false);
|
|
392
|
+
|
|
393
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
394
|
+
'GET',
|
|
395
|
+
`workspaces/${workspaceId}/webhooks`,
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
await new Promise(process.nextTick);
|
|
399
|
+
|
|
400
|
+
expect(staticData.webhookAuthToken).toBeUndefined();
|
|
401
|
+
expect(staticData.webhookId).toBeUndefined();
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it('should check that a webhook does not exist', async () => {
|
|
405
|
+
const workspaceId = '64a687e29ae1f428e7ebe303';
|
|
406
|
+
const webhookAuthToken =
|
|
407
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2NGI3YmU3YmUwODM1Yjc2ZDYzOTY5YTciLCJtdWx0aUZhY3RvciI6dHJ1ZSwiaXNzIjoiY2xvY2tpZnkiLCJuYW1lIjoiTWFydGluIExsb3lkIiwiZXhwIjoxNjkzMzY5MzEwLCJ0eXBlIjoiYWNjZXNzIiwiaWF0IjoxNjkzMzI2MTEwLCJqdGkiOiJZVGcxT0Raak9XTXRPRGRsWVMwME5qZ3hMVGxpTlRndE5UQmlOVEprTmpOaE';
|
|
408
|
+
const webhookId = '76a687e29ae1f428e7ebe101';
|
|
409
|
+
const webhookUrl =
|
|
410
|
+
'http://localhost:5678/webhook/985dc3e9-b382-4dd0-922e-0ceee97023e9';
|
|
411
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
412
|
+
webhookAuthToken: undefined,
|
|
413
|
+
webhookId: undefined,
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
hookFunctions.getNodeParameter
|
|
417
|
+
.calledWith('workspaceId')
|
|
418
|
+
.mockReturnValue(workspaceId);
|
|
419
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue({
|
|
420
|
+
webhooks: [
|
|
421
|
+
{
|
|
422
|
+
authToken: webhookAuthToken,
|
|
423
|
+
enabled: true,
|
|
424
|
+
id: webhookId,
|
|
425
|
+
name: 'stripe',
|
|
426
|
+
triggerSource: [
|
|
427
|
+
'54a687e29ae1f428e7ebe909',
|
|
428
|
+
'87p187e29ae1f428e7ebej56',
|
|
429
|
+
],
|
|
430
|
+
triggerSourceType: 'PROJECT_ID',
|
|
431
|
+
url: 'http://localhost:5678/webhook/c940f948-0c2e-4cba-9d47-1b38790d77bb',
|
|
432
|
+
userId: '5a0ab5acb07987125438b60f',
|
|
433
|
+
webhookEvent: 'NEW_PROJECT',
|
|
434
|
+
workspaceId: '64a687e29ae1f428e7ebe303',
|
|
435
|
+
},
|
|
436
|
+
],
|
|
437
|
+
workspaceWebhookCount: 5,
|
|
438
|
+
});
|
|
439
|
+
hookFunctions.getNodeWebhookUrl
|
|
440
|
+
.calledWith('default')
|
|
441
|
+
.mockReturnValue(webhookUrl);
|
|
442
|
+
hookFunctions.getWorkflowStaticData
|
|
443
|
+
.calledWith('node')
|
|
444
|
+
.mockReturnValue(staticData);
|
|
445
|
+
|
|
446
|
+
expect(
|
|
447
|
+
trigger.webhookMethods.default.checkExists.call(hookFunctions),
|
|
448
|
+
).resolves.toBe(false);
|
|
449
|
+
|
|
450
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
451
|
+
'GET',
|
|
452
|
+
`workspaces/${workspaceId}/webhooks`,
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
await new Promise(process.nextTick);
|
|
456
|
+
|
|
457
|
+
expect(staticData.webhookAuthToken).toBeUndefined();
|
|
458
|
+
expect(staticData.webhookId).toBeUndefined();
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('should create webhook', async () => {
|
|
462
|
+
const workspaceId = '64a687e29ae1f428e7ebe303';
|
|
463
|
+
const name = 'stripe';
|
|
464
|
+
const webhookUrl =
|
|
465
|
+
'http://localhost:5678/webhook/985dc3e9-b382-4dd0-922e-0ceee97023e9';
|
|
466
|
+
const webhookEvent = 'NEW_PROJECT';
|
|
467
|
+
const webhookAuthToken =
|
|
468
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2NGI3YmU3YmUwODM1Yjc2ZDYzOTY5YTciLCJtdWx0aUZhY3RvciI6dHJ1ZSwiaXNzIjoiY2xvY2tpZnkiLCJuYW1lIjoiTWFydGluIExsb3lkIiwiZXhwIjoxNjkzMzY5MzEwLCJ0eXBlIjoiYWNjZXNzIiwiaWF0IjoxNjkzMzI2MTEwLCJqdGkiOiJZVGcxT0Raak9XTXRPRGRsWVMwME5qZ3hMVGxpTlRndE5UQmlOVEprTmpOaE';
|
|
469
|
+
const webhookId = '76a687e29ae1f428e7ebe101';
|
|
470
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
471
|
+
webhookAuthToken: undefined,
|
|
472
|
+
webhookId: undefined,
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
hookFunctions.getNodeParameter
|
|
476
|
+
.calledWith('workspaceId')
|
|
477
|
+
.mockReturnValue(workspaceId);
|
|
478
|
+
hookFunctions.getNodeParameter.calledWith('name').mockReturnValue(name);
|
|
479
|
+
hookFunctions.getNodeWebhookUrl
|
|
480
|
+
.calledWith('default')
|
|
481
|
+
.mockReturnValue(webhookUrl);
|
|
482
|
+
hookFunctions.getNodeParameter
|
|
483
|
+
.calledWith('webhookEvent')
|
|
484
|
+
.mockReturnValue(webhookEvent);
|
|
485
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue({
|
|
486
|
+
authToken: webhookAuthToken,
|
|
487
|
+
enabled: true,
|
|
488
|
+
id: webhookId,
|
|
489
|
+
name: 'stripe',
|
|
490
|
+
triggerSource: ['54a687e29ae1f428e7ebe909', '87p187e29ae1f428e7ebej56'],
|
|
491
|
+
triggerSourceType: 'PROJECT_ID',
|
|
492
|
+
url: 'http://localhost:5678/webhook/c940f948-0c2e-4cba-9d47-1b38790d77bb',
|
|
493
|
+
userId: '5a0ab5acb07987125438b60f',
|
|
494
|
+
webhookEvent: 'NEW_PROJECT',
|
|
495
|
+
workspaceId: '64a687e29ae1f428e7ebe303',
|
|
496
|
+
});
|
|
497
|
+
hookFunctions.getWorkflowStaticData
|
|
498
|
+
.calledWith('node')
|
|
499
|
+
.mockReturnValue(staticData);
|
|
500
|
+
|
|
501
|
+
expect(
|
|
502
|
+
trigger.webhookMethods.default.create.call(hookFunctions),
|
|
503
|
+
).resolves.toBe(true);
|
|
504
|
+
|
|
505
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
506
|
+
'POST',
|
|
507
|
+
`workspaces/${workspaceId}/webhooks`,
|
|
508
|
+
{
|
|
509
|
+
name,
|
|
510
|
+
triggerSource: [],
|
|
511
|
+
triggerSourceType: 'WORKSPACE_ID',
|
|
512
|
+
url: webhookUrl,
|
|
513
|
+
webhookEvent,
|
|
514
|
+
},
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
await new Promise(process.nextTick);
|
|
518
|
+
|
|
519
|
+
expect(staticData.webhookAuthToken).toBe(webhookAuthToken);
|
|
520
|
+
expect(staticData.webhookId).toBe(webhookId);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it('should not create webhook because of undefined auth token', async () => {
|
|
524
|
+
const workspaceId = '64a687e29ae1f428e7ebe303';
|
|
525
|
+
const name = 'stripe';
|
|
526
|
+
const webhookUrl =
|
|
527
|
+
'http://localhost:5678/webhook/985dc3e9-b382-4dd0-922e-0ceee97023e9';
|
|
528
|
+
const webhookEvent = 'NEW_PROJECT';
|
|
529
|
+
const webhookAuthToken = undefined;
|
|
530
|
+
const webhookId = '76a687e29ae1f428e7ebe101';
|
|
531
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
532
|
+
webhookAuthToken: undefined,
|
|
533
|
+
webhookId: undefined,
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
hookFunctions.getNodeParameter
|
|
537
|
+
.calledWith('workspaceId')
|
|
538
|
+
.mockReturnValue(workspaceId);
|
|
539
|
+
hookFunctions.getNodeParameter.calledWith('name').mockReturnValue(name);
|
|
540
|
+
hookFunctions.getNodeWebhookUrl
|
|
541
|
+
.calledWith('default')
|
|
542
|
+
.mockReturnValue(webhookUrl);
|
|
543
|
+
hookFunctions.getNodeParameter
|
|
544
|
+
.calledWith('webhookEvent')
|
|
545
|
+
.mockReturnValue(webhookEvent);
|
|
546
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue({
|
|
547
|
+
authToken: webhookAuthToken,
|
|
548
|
+
enabled: true,
|
|
549
|
+
id: webhookId,
|
|
550
|
+
name: 'stripe',
|
|
551
|
+
triggerSource: ['54a687e29ae1f428e7ebe909', '87p187e29ae1f428e7ebej56'],
|
|
552
|
+
triggerSourceType: 'PROJECT_ID',
|
|
553
|
+
url: 'http://localhost:5678/webhook/c940f948-0c2e-4cba-9d47-1b38790d77bb',
|
|
554
|
+
userId: '5a0ab5acb07987125438b60f',
|
|
555
|
+
webhookEvent: 'NEW_PROJECT',
|
|
556
|
+
workspaceId: '64a687e29ae1f428e7ebe303',
|
|
557
|
+
});
|
|
558
|
+
hookFunctions.getWorkflowStaticData
|
|
559
|
+
.calledWith('node')
|
|
560
|
+
.mockReturnValue(staticData);
|
|
561
|
+
|
|
562
|
+
expect(
|
|
563
|
+
trigger.webhookMethods.default.create.call(hookFunctions),
|
|
564
|
+
).resolves.toBe(false);
|
|
565
|
+
|
|
566
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
567
|
+
'POST',
|
|
568
|
+
`workspaces/${workspaceId}/webhooks`,
|
|
569
|
+
{
|
|
570
|
+
name,
|
|
571
|
+
triggerSource: [],
|
|
572
|
+
triggerSourceType: 'WORKSPACE_ID',
|
|
573
|
+
url: webhookUrl,
|
|
574
|
+
webhookEvent,
|
|
575
|
+
},
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
await new Promise(process.nextTick);
|
|
579
|
+
|
|
580
|
+
expect(staticData.webhookAuthToken).toBeUndefined();
|
|
581
|
+
expect(staticData.webhookId).toBeUndefined();
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
it('should not create webhook because of undefined id', async () => {
|
|
585
|
+
const workspaceId = '64a687e29ae1f428e7ebe303';
|
|
586
|
+
const name = 'stripe';
|
|
587
|
+
const webhookUrl =
|
|
588
|
+
'http://localhost:5678/webhook/985dc3e9-b382-4dd0-922e-0ceee97023e9';
|
|
589
|
+
const webhookEvent = 'NEW_PROJECT';
|
|
590
|
+
const webhookAuthToken =
|
|
591
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2NGI3YmU3YmUwODM1Yjc2ZDYzOTY5YTciLCJtdWx0aUZhY3RvciI6dHJ1ZSwiaXNzIjoiY2xvY2tpZnkiLCJuYW1lIjoiTWFydGluIExsb3lkIiwiZXhwIjoxNjkzMzY5MzEwLCJ0eXBlIjoiYWNjZXNzIiwiaWF0IjoxNjkzMzI2MTEwLCJqdGkiOiJZVGcxT0Raak9XTXRPRGRsWVMwME5qZ3hMVGxpTlRndE5UQmlOVEprTmpOaE';
|
|
592
|
+
const webhookId = undefined;
|
|
593
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
594
|
+
webhookAuthToken: undefined,
|
|
595
|
+
webhookId: undefined,
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
hookFunctions.getNodeParameter
|
|
599
|
+
.calledWith('workspaceId')
|
|
600
|
+
.mockReturnValue(workspaceId);
|
|
601
|
+
hookFunctions.getNodeParameter.calledWith('name').mockReturnValue(name);
|
|
602
|
+
hookFunctions.getNodeWebhookUrl
|
|
603
|
+
.calledWith('default')
|
|
604
|
+
.mockReturnValue(webhookUrl);
|
|
605
|
+
hookFunctions.getNodeParameter
|
|
606
|
+
.calledWith('webhookEvent')
|
|
607
|
+
.mockReturnValue(webhookEvent);
|
|
608
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue({
|
|
609
|
+
authToken: webhookAuthToken,
|
|
610
|
+
enabled: true,
|
|
611
|
+
id: webhookId,
|
|
612
|
+
name: 'stripe',
|
|
613
|
+
triggerSource: ['54a687e29ae1f428e7ebe909', '87p187e29ae1f428e7ebej56'],
|
|
614
|
+
triggerSourceType: 'PROJECT_ID',
|
|
615
|
+
url: 'http://localhost:5678/webhook/c940f948-0c2e-4cba-9d47-1b38790d77bb',
|
|
616
|
+
userId: '5a0ab5acb07987125438b60f',
|
|
617
|
+
webhookEvent: 'NEW_PROJECT',
|
|
618
|
+
workspaceId: '64a687e29ae1f428e7ebe303',
|
|
619
|
+
});
|
|
620
|
+
hookFunctions.getWorkflowStaticData
|
|
621
|
+
.calledWith('node')
|
|
622
|
+
.mockReturnValue(staticData);
|
|
623
|
+
|
|
624
|
+
expect(
|
|
625
|
+
trigger.webhookMethods.default.create.call(hookFunctions),
|
|
626
|
+
).resolves.toBe(false);
|
|
627
|
+
|
|
628
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
629
|
+
'POST',
|
|
630
|
+
`workspaces/${workspaceId}/webhooks`,
|
|
631
|
+
{
|
|
632
|
+
name,
|
|
633
|
+
triggerSource: [],
|
|
634
|
+
triggerSourceType: 'WORKSPACE_ID',
|
|
635
|
+
url: webhookUrl,
|
|
636
|
+
webhookEvent,
|
|
637
|
+
},
|
|
638
|
+
);
|
|
639
|
+
|
|
640
|
+
await new Promise(process.nextTick);
|
|
641
|
+
|
|
642
|
+
expect(staticData.webhookAuthToken).toBeUndefined();
|
|
643
|
+
expect(staticData.webhookId).toBeUndefined();
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
it('should delete webhook', async () => {
|
|
647
|
+
const workspaceId = '64a687e29ae1f428e7ebe303';
|
|
648
|
+
const webhookAuthToken =
|
|
649
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2NGI3YmU3YmUwODM1Yjc2ZDYzOTY5YTciLCJtdWx0aUZhY3RvciI6dHJ1ZSwiaXNzIjoiY2xvY2tpZnkiLCJuYW1lIjoiTWFydGluIExsb3lkIiwiZXhwIjoxNjkzMzY5MzEwLCJ0eXBlIjoiYWNjZXNzIiwiaWF0IjoxNjkzMzI2MTEwLCJqdGkiOiJZVGcxT0Raak9XTXRPRGRsWVMwME5qZ3hMVGxpTlRndE5UQmlOVEprTmpOaE';
|
|
650
|
+
const webhookId = '76a687e29ae1f428e7ebe101';
|
|
651
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
652
|
+
webhookAuthToken,
|
|
653
|
+
webhookId,
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
hookFunctions.getWorkflowStaticData
|
|
657
|
+
.calledWith('node')
|
|
658
|
+
.mockReturnValue(staticData);
|
|
659
|
+
hookFunctions.getNodeParameter
|
|
660
|
+
.calledWith('workspaceId')
|
|
661
|
+
.mockReturnValue(workspaceId);
|
|
662
|
+
jest.mocked(clockifyApiRequest).mockResolvedValue({});
|
|
663
|
+
|
|
664
|
+
expect(
|
|
665
|
+
trigger.webhookMethods.default.delete.call(hookFunctions),
|
|
666
|
+
).resolves.toBe(true);
|
|
667
|
+
|
|
668
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
669
|
+
'DELETE',
|
|
670
|
+
`workspaces/${workspaceId}/webhooks/${webhookId}`,
|
|
671
|
+
);
|
|
672
|
+
|
|
673
|
+
await new Promise(process.nextTick);
|
|
674
|
+
|
|
675
|
+
expect(staticData.webhookAuthToken).toBeUndefined();
|
|
676
|
+
expect(staticData.webhookId).toBeUndefined();
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
it('should not delete webhook because of undefined id', async () => {
|
|
680
|
+
const webhookAuthToken =
|
|
681
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2NGI3YmU3YmUwODM1Yjc2ZDYzOTY5YTciLCJtdWx0aUZhY3RvciI6dHJ1ZSwiaXNzIjoiY2xvY2tpZnkiLCJuYW1lIjoiTWFydGluIExsb3lkIiwiZXhwIjoxNjkzMzY5MzEwLCJ0eXBlIjoiYWNjZXNzIiwiaWF0IjoxNjkzMzI2MTEwLCJqdGkiOiJZVGcxT0Raak9XTXRPRGRsWVMwME5qZ3hMVGxpTlRndE5UQmlOVEprTmpOaE';
|
|
682
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
683
|
+
webhookAuthToken,
|
|
684
|
+
webhookId: undefined,
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
hookFunctions.getWorkflowStaticData
|
|
688
|
+
.calledWith('node')
|
|
689
|
+
.mockReturnValue(staticData);
|
|
690
|
+
|
|
691
|
+
expect(
|
|
692
|
+
trigger.webhookMethods.default.delete.call(hookFunctions),
|
|
693
|
+
).resolves.toBe(true);
|
|
694
|
+
|
|
695
|
+
await new Promise(process.nextTick);
|
|
696
|
+
|
|
697
|
+
expect(staticData.webhookAuthToken).toBe(webhookAuthToken);
|
|
698
|
+
expect(staticData.webhookId).toBeUndefined();
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
it('should not delete webhook because of api exception', async () => {
|
|
702
|
+
const workspaceId = '64a687e29ae1f428e7ebe303';
|
|
703
|
+
const webhookAuthToken =
|
|
704
|
+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI2NGI3YmU3YmUwODM1Yjc2ZDYzOTY5YTciLCJtdWx0aUZhY3RvciI6dHJ1ZSwiaXNzIjoiY2xvY2tpZnkiLCJuYW1lIjoiTWFydGluIExsb3lkIiwiZXhwIjoxNjkzMzY5MzEwLCJ0eXBlIjoiYWNjZXNzIiwiaWF0IjoxNjkzMzI2MTEwLCJqdGkiOiJZVGcxT0Raak9XTXRPRGRsWVMwME5qZ3hMVGxpTlRndE5UQmlOVEprTmpOaE';
|
|
705
|
+
const webhookId = '76a687e29ae1f428e7ebe101';
|
|
706
|
+
const staticData: { webhookAuthToken?: string; webhookId?: string } = {
|
|
707
|
+
webhookAuthToken,
|
|
708
|
+
webhookId,
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
hookFunctions.getWorkflowStaticData
|
|
712
|
+
.calledWith('node')
|
|
713
|
+
.mockReturnValue(staticData);
|
|
714
|
+
hookFunctions.getNodeParameter
|
|
715
|
+
.calledWith('workspaceId')
|
|
716
|
+
.mockReturnValue(workspaceId);
|
|
717
|
+
jest.mocked(clockifyApiRequest).mockRejectedValue(new Error());
|
|
718
|
+
|
|
719
|
+
expect(
|
|
720
|
+
trigger.webhookMethods.default.delete.call(hookFunctions),
|
|
721
|
+
).resolves.toBe(false);
|
|
722
|
+
|
|
723
|
+
expect(jest.mocked(clockifyApiRequest)).toHaveBeenCalledWith(
|
|
724
|
+
'DELETE',
|
|
725
|
+
`workspaces/${workspaceId}/webhooks/${webhookId}`,
|
|
726
|
+
);
|
|
727
|
+
|
|
728
|
+
await new Promise(process.nextTick);
|
|
729
|
+
|
|
730
|
+
expect(staticData.webhookAuthToken).toBe(webhookAuthToken);
|
|
731
|
+
expect(staticData.webhookId).toBe(webhookId);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
it('should provide workflow data', () => {
|
|
735
|
+
const body = {
|
|
736
|
+
id: '_id_',
|
|
737
|
+
description: '_description_',
|
|
738
|
+
userId: '_user_id_',
|
|
739
|
+
billable: false,
|
|
740
|
+
projectId: '_project_id_',
|
|
741
|
+
timeInterval: {
|
|
742
|
+
start: '2024-02-15T00:00:00Z',
|
|
743
|
+
end: '2024-02-15T00:30:00Z',
|
|
744
|
+
duration: 'PT30M',
|
|
745
|
+
},
|
|
746
|
+
workspaceId: '_workspace_id_',
|
|
747
|
+
isLocked: false,
|
|
748
|
+
hourlyRate: null,
|
|
749
|
+
costRate: null,
|
|
750
|
+
customFieldValues: [],
|
|
751
|
+
type: 'REGULAR',
|
|
752
|
+
kioskId: null,
|
|
753
|
+
projectCurrency: null,
|
|
754
|
+
currentlyRunning: false,
|
|
755
|
+
project: {
|
|
756
|
+
name: '_project_name_',
|
|
757
|
+
clientId: '_client_id_',
|
|
758
|
+
workspaceId: '_workspace_id_',
|
|
759
|
+
billable: false,
|
|
760
|
+
estimate: {
|
|
761
|
+
estimate: 'PT0S',
|
|
762
|
+
type: 'AUTO',
|
|
763
|
+
},
|
|
764
|
+
color: '#000000',
|
|
765
|
+
archived: false,
|
|
766
|
+
clientName: '_client_name_',
|
|
767
|
+
duration: 'PT10H30M',
|
|
768
|
+
note: null,
|
|
769
|
+
budgetEstimate: null,
|
|
770
|
+
timeEstimate: {
|
|
771
|
+
estimate: 0,
|
|
772
|
+
type: 'AUTO',
|
|
773
|
+
resetOption: null,
|
|
774
|
+
},
|
|
775
|
+
activeEstimate: 'NONE',
|
|
776
|
+
id: '_project_id_',
|
|
777
|
+
public: true,
|
|
778
|
+
template: false,
|
|
779
|
+
},
|
|
780
|
+
task: {
|
|
781
|
+
name: '_task_name_',
|
|
782
|
+
projectId: '_project_id_',
|
|
783
|
+
assigneeId: '',
|
|
784
|
+
assigneeIds: [],
|
|
785
|
+
estimate: 'PT0S',
|
|
786
|
+
status: 'ACTIVE',
|
|
787
|
+
workspaceId: '_workspace_id_',
|
|
788
|
+
duration: 'PT10H30M30S',
|
|
789
|
+
budgetEstimate: 0,
|
|
790
|
+
billable: false,
|
|
791
|
+
hourlyRate: null,
|
|
792
|
+
costRate: null,
|
|
793
|
+
id: '_task_id_',
|
|
794
|
+
},
|
|
795
|
+
user: {
|
|
796
|
+
id: '_user_id_',
|
|
797
|
+
name: '_user_name_',
|
|
798
|
+
status: 'ACTIVE',
|
|
799
|
+
},
|
|
800
|
+
tags: [],
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
webhookFunctions.getHeaderData.mockReturnValue({
|
|
804
|
+
'clockify-signature': '_signature_',
|
|
805
|
+
'clockify-webhook-event-type': '_event_type_',
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
webhookFunctions.getWorkflowStaticData.calledWith('node').mockReturnValue({
|
|
809
|
+
webhookAuthToken: '_signature_',
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
webhookFunctions.getNodeParameter
|
|
813
|
+
.calledWith('webhookEvent')
|
|
814
|
+
.mockReturnValueOnce('_event_type_');
|
|
815
|
+
|
|
816
|
+
webhookFunctions.getRequestObject.mockReturnValue(mock<Request>({ body }));
|
|
817
|
+
|
|
818
|
+
webhookFunctions.helpers.returnJsonArray.mockReturnValue([{ json: body }]);
|
|
819
|
+
|
|
820
|
+
expect(trigger.webhook.call(webhookFunctions)).resolves.toEqual({
|
|
821
|
+
workflowData: [[{ json: body }]],
|
|
822
|
+
});
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
it('should not provide workflow data because of missing signature header', () => {
|
|
826
|
+
webhookFunctions.getHeaderData.mockReturnValue({
|
|
827
|
+
'clockify-webhook-event-type': '_event_type_',
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
expect(trigger.webhook.call(webhookFunctions)).resolves.toEqual({});
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
it('should not provide workflow data because of missing webhook event type header', () => {
|
|
834
|
+
webhookFunctions.getHeaderData.mockReturnValue({
|
|
835
|
+
'clockify-signature': '_signature_',
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
expect(trigger.webhook.call(webhookFunctions)).resolves.toEqual({});
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
it('should not provide workflow data because of signature missmatch', () => {
|
|
842
|
+
webhookFunctions.getHeaderData.mockReturnValue({
|
|
843
|
+
'clockify-signature': '_signature_',
|
|
844
|
+
'clockify-webhook-event-type': '_event_type_',
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
webhookFunctions.getWorkflowStaticData.calledWith('node').mockReturnValue({
|
|
848
|
+
webhookAuthToken: '_other_signature_',
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
expect(trigger.webhook.call(webhookFunctions)).resolves.toEqual({});
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
it('should not provide workflow data because of webhook event type missmatch', () => {
|
|
855
|
+
webhookFunctions.getHeaderData.mockReturnValue({
|
|
856
|
+
'clockify-signature': '_signature_',
|
|
857
|
+
'clockify-webhook-event-type': '_event_type_',
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
webhookFunctions.getWorkflowStaticData.calledWith('node').mockReturnValue({
|
|
861
|
+
webhookAuthToken: '_signature_',
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
webhookFunctions.getNodeParameter
|
|
865
|
+
.calledWith('webhookEvent')
|
|
866
|
+
.mockReturnValueOnce('_other_event_type_');
|
|
867
|
+
|
|
868
|
+
expect(trigger.webhook.call(webhookFunctions)).resolves.toEqual({});
|
|
869
|
+
});
|
|
870
|
+
});
|