@skriptfabrik/n8n-nodes-clockify-enhanced 0.4.2 → 0.4.4

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.
Files changed (28) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.json +30 -0
  3. package/CHANGELOG.md +27 -0
  4. package/jest.config.ts +11 -0
  5. package/package.json +4 -7
  6. package/project.json +37 -0
  7. package/src/api.d.ts +14974 -0
  8. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.spec.ts +920 -0
  9. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.ts +387 -0
  10. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.spec.ts +870 -0
  11. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.ts +356 -0
  12. package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.ts +120 -0
  13. package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.ts +125 -0
  14. package/tsconfig.json +28 -0
  15. package/tsconfig.lib.json +10 -0
  16. package/tsconfig.spec.json +13 -0
  17. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.d.ts +0 -15
  18. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.js +0 -232
  19. package/src/nodes/ClockifyEnhanced/ClockifyEnhanced.node.js.map +0 -1
  20. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.d.ts +0 -52
  21. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.js +0 -297
  22. package/src/nodes/ClockifyEnhanced/ClockifyEnhancedTrigger.node.js.map +0 -1
  23. package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.d.ts +0 -3
  24. package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.js +0 -117
  25. package/src/nodes/ClockifyEnhanced/descriptions/ProjectDescription.js.map +0 -1
  26. package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.d.ts +0 -3
  27. package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.js +0 -122
  28. package/src/nodes/ClockifyEnhanced/descriptions/ProjectMembershipsDescription.js.map +0 -1
@@ -0,0 +1,920 @@
1
+ import { mockClear, mockDeep } from 'jest-mock-extended';
2
+
3
+ import { ILoadOptionsFunctions, type IExecuteFunctions } from 'n8n-workflow';
4
+
5
+ import {
6
+ clockifyApiRequest,
7
+ clockifyApiRequestAllItems,
8
+ } from 'n8n-nodes-base/dist/nodes/Clockify/GenericFunctions';
9
+
10
+ import { ClockifyEnhanced } from './ClockifyEnhanced.node';
11
+
12
+ import { components } from '../../api';
13
+
14
+ type Client = components['schemas']['ClientDtoV1'];
15
+ type Project = components['schemas']['ProjectDtoImplV1'];
16
+ type User = components['schemas']['UserDtoV1'];
17
+ type Workspace = components['schemas']['WorkspaceDtoV1'];
18
+
19
+ jest.mock('n8n-nodes-base/dist/nodes/Clockify/GenericFunctions');
20
+
21
+ describe('ClockifyEnhanced', () => {
22
+ const project: Project = {
23
+ archived: true,
24
+ billable: true,
25
+ budgetEstimate: {
26
+ active: true,
27
+ estimate: 600000,
28
+ includeExpenses: true,
29
+ resetOption: 'WEEKLY',
30
+ type: 'AUTO',
31
+ },
32
+ clientId: '9t641568b07987035750704',
33
+ clientName: 'Client X',
34
+ color: '#000000',
35
+ costRate: {
36
+ amount: 10500,
37
+ currency: 'USD',
38
+ },
39
+ duration: '60000',
40
+ estimate: {
41
+ estimate: 'PT1H30M',
42
+ type: 'AUTO',
43
+ },
44
+ estimateReset: {
45
+ dayOfMonth: 0,
46
+ dayOfWeek: 'MONDAY',
47
+ hour: 0,
48
+ interval: 'WEEKLY',
49
+ month: 'JANUARY',
50
+ },
51
+ hourlyRate: {
52
+ amount: 10500,
53
+ currency: 'USD',
54
+ },
55
+ id: '5b641568b07987035750505e',
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: 'Software Development',
73
+ note: 'This is a sample note for the project.',
74
+ public: true,
75
+ template: true,
76
+ timeEstimate: {
77
+ active: true,
78
+ estimate: '60000',
79
+ includeNonBillable: true,
80
+ resetOption: 'WEEKLY',
81
+ type: 'AUTO',
82
+ },
83
+ workspaceId: '64a687e29ae1f428e7ebe303',
84
+ };
85
+
86
+ const loadOptionsFunctions = mockDeep<ILoadOptionsFunctions>();
87
+ const executeFunctions = mockDeep<IExecuteFunctions>();
88
+
89
+ let clockifyEnhanced: ClockifyEnhanced;
90
+
91
+ beforeEach(() => {
92
+ clockifyEnhanced = new ClockifyEnhanced();
93
+ });
94
+
95
+ afterEach(() => {
96
+ mockClear(clockifyApiRequest);
97
+ mockClear(clockifyApiRequestAllItems);
98
+ mockClear(loadOptionsFunctions);
99
+ mockClear(executeFunctions);
100
+ });
101
+
102
+ it('should be defined', () => {
103
+ expect(clockifyEnhanced).toBeDefined();
104
+ });
105
+
106
+ describe('load options methods', () => {
107
+ describe('load workspaces', () => {
108
+ it('should return on empty result', () => {
109
+ jest.mocked(clockifyApiRequest).mockResolvedValue(undefined);
110
+
111
+ expect(
112
+ clockifyEnhanced.methods.loadOptions.loadWorkspaces.call(
113
+ loadOptionsFunctions,
114
+ ),
115
+ ).resolves.toStrictEqual([]);
116
+
117
+ expect(clockifyApiRequest).toHaveBeenCalledTimes(1);
118
+ expect(clockifyApiRequest).toHaveBeenCalledWith('GET', 'workspaces');
119
+ });
120
+
121
+ it('should return mapped workspaces', () => {
122
+ const workspaces: Workspace[] = [
123
+ {
124
+ id: '64a687e29ae1f428e7ebe303',
125
+ name: 'Workspace X',
126
+ },
127
+ {
128
+ id: '64a687e29ae1f428e7ebe304',
129
+ name: 'Workspace Y',
130
+ },
131
+ ];
132
+
133
+ jest.mocked(clockifyApiRequest).mockResolvedValue(workspaces);
134
+
135
+ expect(
136
+ clockifyEnhanced.methods.loadOptions.loadWorkspaces.call(
137
+ loadOptionsFunctions,
138
+ ),
139
+ ).resolves.toStrictEqual([
140
+ { name: 'Workspace X', value: '64a687e29ae1f428e7ebe303' },
141
+ { name: 'Workspace Y', value: '64a687e29ae1f428e7ebe304' },
142
+ ]);
143
+
144
+ expect(clockifyApiRequest).toHaveBeenCalledTimes(1);
145
+ expect(clockifyApiRequest).toHaveBeenCalledWith('GET', 'workspaces');
146
+ });
147
+ });
148
+
149
+ describe('load clients', () => {
150
+ it('should return on missing workspace id', () => {
151
+ loadOptionsFunctions.getCurrentNodeParameter
152
+ .calledWith('workspaceId')
153
+ .mockReturnValue('');
154
+
155
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue([]);
156
+
157
+ expect(
158
+ clockifyEnhanced.methods.loadOptions.loadClients.call(
159
+ loadOptionsFunctions,
160
+ ),
161
+ ).resolves.toStrictEqual([]);
162
+
163
+ expect(clockifyApiRequestAllItems).not.toHaveBeenCalled();
164
+ });
165
+
166
+ it('should return on empty result', () => {
167
+ loadOptionsFunctions.getCurrentNodeParameter
168
+ .calledWith('workspaceId')
169
+ .mockReturnValue('_workspace_id_');
170
+
171
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(undefined);
172
+
173
+ expect(
174
+ clockifyEnhanced.methods.loadOptions.loadClients.call(
175
+ loadOptionsFunctions,
176
+ ),
177
+ ).resolves.toStrictEqual([]);
178
+
179
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
180
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
181
+ 'GET',
182
+ `workspaces/_workspace_id_/clients`,
183
+ );
184
+ });
185
+
186
+ it('should return mapped clients', () => {
187
+ const clients: Client[] = [
188
+ {
189
+ id: '64a687e29ae1f428e7ebe303',
190
+ name: 'Client X',
191
+ },
192
+ {
193
+ id: '64a687e29ae1f428e7ebe304',
194
+ name: 'Client Y',
195
+ },
196
+ ];
197
+
198
+ loadOptionsFunctions.getCurrentNodeParameter
199
+ .calledWith('workspaceId')
200
+ .mockReturnValue('_workspace_id_');
201
+
202
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(clients);
203
+
204
+ expect(
205
+ clockifyEnhanced.methods.loadOptions.loadClients.call(
206
+ loadOptionsFunctions,
207
+ ),
208
+ ).resolves.toStrictEqual([
209
+ { name: 'Client X', value: '64a687e29ae1f428e7ebe303' },
210
+ { name: 'Client Y', value: '64a687e29ae1f428e7ebe304' },
211
+ ]);
212
+
213
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
214
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
215
+ 'GET',
216
+ `workspaces/_workspace_id_/clients`,
217
+ );
218
+ });
219
+ });
220
+
221
+ describe('load projects', () => {
222
+ it('should return on missing workspace id', () => {
223
+ loadOptionsFunctions.getCurrentNodeParameter
224
+ .calledWith('workspaceId')
225
+ .mockReturnValue('');
226
+
227
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue([]);
228
+
229
+ expect(
230
+ clockifyEnhanced.methods.loadOptions.loadProjects.call(
231
+ loadOptionsFunctions,
232
+ ),
233
+ ).resolves.toStrictEqual([]);
234
+
235
+ expect(clockifyApiRequestAllItems).not.toHaveBeenCalled();
236
+ });
237
+
238
+ it('should return on empty result', () => {
239
+ loadOptionsFunctions.getCurrentNodeParameter
240
+ .calledWith('workspaceId')
241
+ .mockReturnValue('_workspace_id_');
242
+
243
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(undefined);
244
+
245
+ expect(
246
+ clockifyEnhanced.methods.loadOptions.loadProjects.call(
247
+ loadOptionsFunctions,
248
+ ),
249
+ ).resolves.toStrictEqual([]);
250
+
251
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
252
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
253
+ 'GET',
254
+ `workspaces/_workspace_id_/projects`,
255
+ );
256
+ });
257
+
258
+ it('should return mapped projects', () => {
259
+ const projects: Project[] = [
260
+ {
261
+ id: '64a687e29ae1f428e7ebe303',
262
+ name: 'Project X',
263
+ },
264
+ {
265
+ id: '64a687e29ae1f428e7ebe304',
266
+ name: 'Project Y',
267
+ },
268
+ ];
269
+
270
+ loadOptionsFunctions.getCurrentNodeParameter
271
+ .calledWith('workspaceId')
272
+ .mockReturnValue('_workspace_id_');
273
+
274
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(projects);
275
+
276
+ expect(
277
+ clockifyEnhanced.methods.loadOptions.loadProjects.call(
278
+ loadOptionsFunctions,
279
+ ),
280
+ ).resolves.toStrictEqual([
281
+ { name: 'Project X', value: '64a687e29ae1f428e7ebe303' },
282
+ { name: 'Project Y', value: '64a687e29ae1f428e7ebe304' },
283
+ ]);
284
+
285
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
286
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
287
+ 'GET',
288
+ `workspaces/_workspace_id_/projects`,
289
+ );
290
+ });
291
+ });
292
+
293
+ describe('load users', () => {
294
+ it('should return on missing workspace id', () => {
295
+ loadOptionsFunctions.getCurrentNodeParameter
296
+ .calledWith('workspaceId')
297
+ .mockReturnValue('');
298
+
299
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue([]);
300
+
301
+ expect(
302
+ clockifyEnhanced.methods.loadOptions.loadUsers.call(
303
+ loadOptionsFunctions,
304
+ ),
305
+ ).resolves.toStrictEqual([]);
306
+
307
+ expect(clockifyApiRequestAllItems).not.toHaveBeenCalled();
308
+ });
309
+
310
+ it('should return on empty result', () => {
311
+ loadOptionsFunctions.getCurrentNodeParameter
312
+ .calledWith('workspaceId')
313
+ .mockReturnValue('_workspace_id_');
314
+
315
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(undefined);
316
+
317
+ expect(
318
+ clockifyEnhanced.methods.loadOptions.loadUsers.call(
319
+ loadOptionsFunctions,
320
+ ),
321
+ ).resolves.toStrictEqual([]);
322
+
323
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
324
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
325
+ 'GET',
326
+ `workspaces/_workspace_id_/users`,
327
+ );
328
+ });
329
+
330
+ it('should return mapped users', () => {
331
+ const projects: User[] = [
332
+ {
333
+ id: '64a687e29ae1f428e7ebe303',
334
+ name: 'User X',
335
+ },
336
+ {
337
+ id: '64a687e29ae1f428e7ebe304',
338
+ name: 'User Y',
339
+ },
340
+ ];
341
+
342
+ loadOptionsFunctions.getCurrentNodeParameter
343
+ .calledWith('workspaceId')
344
+ .mockReturnValue('_workspace_id_');
345
+
346
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(projects);
347
+
348
+ expect(
349
+ clockifyEnhanced.methods.loadOptions.loadUsers.call(
350
+ loadOptionsFunctions,
351
+ ),
352
+ ).resolves.toStrictEqual([
353
+ { name: 'User X', value: '64a687e29ae1f428e7ebe303' },
354
+ { name: 'User Y', value: '64a687e29ae1f428e7ebe304' },
355
+ ]);
356
+
357
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
358
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
359
+ 'GET',
360
+ `workspaces/_workspace_id_/users`,
361
+ );
362
+ });
363
+ });
364
+
365
+ describe('load non project users', () => {
366
+ it.each([
367
+ { missingParameter: 'workspaceId', workspaceId: '', projectId: '' },
368
+ {
369
+ missingParameter: 'projectId',
370
+ workspaceId: '_workspace_id_',
371
+ projectId: '',
372
+ },
373
+ {
374
+ missingParameter: 'workspaceId & projectId',
375
+ workspaceId: '',
376
+ projectId: '_project_id_',
377
+ },
378
+ ])(
379
+ 'should return empty result on missing node parameter: $missingParameter',
380
+ ({ workspaceId, projectId }) => {
381
+ loadOptionsFunctions.getCurrentNodeParameter
382
+ .calledWith('workspaceId')
383
+ .mockReturnValue(workspaceId);
384
+
385
+ loadOptionsFunctions.getCurrentNodeParameter
386
+ .calledWith('projectId')
387
+ .mockReturnValue(projectId);
388
+
389
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue([]);
390
+
391
+ expect(
392
+ clockifyEnhanced.methods.loadOptions.loadNonProjectUsers.call(
393
+ loadOptionsFunctions,
394
+ ),
395
+ ).resolves.toStrictEqual([]);
396
+
397
+ expect(clockifyApiRequestAllItems).not.toHaveBeenCalled();
398
+ },
399
+ );
400
+
401
+ it('should return on empty result', () => {
402
+ loadOptionsFunctions.getCurrentNodeParameter
403
+ .calledWith('workspaceId')
404
+ .mockReturnValue('_workspace_id_');
405
+
406
+ loadOptionsFunctions.getCurrentNodeParameter
407
+ .calledWith('projectId')
408
+ .mockReturnValue('_project_id_');
409
+
410
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(undefined);
411
+
412
+ expect(
413
+ clockifyEnhanced.methods.loadOptions.loadNonProjectUsers.call(
414
+ loadOptionsFunctions,
415
+ ),
416
+ ).resolves.toStrictEqual([]);
417
+
418
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
419
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
420
+ 'GET',
421
+ `workspaces/_workspace_id_/users`,
422
+ undefined,
423
+ {
424
+ memberships: 'PROJECT',
425
+ },
426
+ );
427
+ });
428
+
429
+ it('should return mapped non project users', () => {
430
+ const users: User[] = [
431
+ {
432
+ id: '64a687e29ae1f428e7ebe303',
433
+ name: 'User X',
434
+ memberships: [
435
+ {
436
+ targetId: '64c777ddd3fcab07cfbb210c',
437
+ membershipType: 'PROJECT',
438
+ },
439
+ ],
440
+ },
441
+ {
442
+ id: '64a687e29ae1f428e7ebe304',
443
+ name: 'User Y',
444
+ memberships: [
445
+ {
446
+ targetId: '_project_id_',
447
+ membershipType: 'PROJECT',
448
+ },
449
+ ],
450
+ },
451
+ ];
452
+
453
+ loadOptionsFunctions.getCurrentNodeParameter
454
+ .calledWith('workspaceId')
455
+ .mockReturnValue('_workspace_id_');
456
+
457
+ loadOptionsFunctions.getCurrentNodeParameter
458
+ .calledWith('projectId')
459
+ .mockReturnValue('_project_id_');
460
+
461
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(users);
462
+
463
+ expect(
464
+ clockifyEnhanced.methods.loadOptions.loadNonProjectUsers.call(
465
+ loadOptionsFunctions,
466
+ ),
467
+ ).resolves.toStrictEqual([
468
+ { name: 'User X', value: '64a687e29ae1f428e7ebe303' },
469
+ ]);
470
+
471
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
472
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
473
+ 'GET',
474
+ `workspaces/_workspace_id_/users`,
475
+ undefined,
476
+ {
477
+ memberships: 'PROJECT',
478
+ },
479
+ );
480
+ });
481
+ });
482
+
483
+ describe('load project users', () => {
484
+ it.each([
485
+ { missingParameter: 'workspaceId', workspaceId: '', projectId: '' },
486
+ {
487
+ missingParameter: 'projectId',
488
+ workspaceId: '_workspace_id_',
489
+ projectId: '',
490
+ },
491
+ {
492
+ missingParameter: 'workspaceId & projectId',
493
+ workspaceId: '',
494
+ projectId: '_project_id_',
495
+ },
496
+ ])(
497
+ 'should return empty result on missing node parameter: $missingParameter',
498
+ ({ workspaceId, projectId }) => {
499
+ loadOptionsFunctions.getCurrentNodeParameter
500
+ .calledWith('workspaceId')
501
+ .mockReturnValue(workspaceId);
502
+
503
+ loadOptionsFunctions.getCurrentNodeParameter
504
+ .calledWith('projectId')
505
+ .mockReturnValue(projectId);
506
+
507
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue([]);
508
+
509
+ expect(
510
+ clockifyEnhanced.methods.loadOptions.loadProjectUsers.call(
511
+ loadOptionsFunctions,
512
+ ),
513
+ ).resolves.toStrictEqual([]);
514
+
515
+ expect(clockifyApiRequestAllItems).not.toHaveBeenCalled();
516
+ },
517
+ );
518
+
519
+ it('should return on empty result', () => {
520
+ loadOptionsFunctions.getCurrentNodeParameter
521
+ .calledWith('workspaceId')
522
+ .mockReturnValue('_workspace_id_');
523
+
524
+ loadOptionsFunctions.getCurrentNodeParameter
525
+ .calledWith('projectId')
526
+ .mockReturnValue('_project_id_');
527
+
528
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(undefined);
529
+
530
+ expect(
531
+ clockifyEnhanced.methods.loadOptions.loadProjectUsers.call(
532
+ loadOptionsFunctions,
533
+ ),
534
+ ).resolves.toStrictEqual([]);
535
+
536
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
537
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
538
+ 'GET',
539
+ `workspaces/_workspace_id_/users`,
540
+ undefined,
541
+ {
542
+ projectId: '_project_id_',
543
+ },
544
+ );
545
+ });
546
+
547
+ it('should return mapped project users', () => {
548
+ const projects: User[] = [
549
+ {
550
+ id: '64a687e29ae1f428e7ebe303',
551
+ name: 'User X',
552
+ },
553
+ ];
554
+
555
+ loadOptionsFunctions.getCurrentNodeParameter
556
+ .calledWith('workspaceId')
557
+ .mockReturnValue('_workspace_id_');
558
+
559
+ loadOptionsFunctions.getCurrentNodeParameter
560
+ .calledWith('projectId')
561
+ .mockReturnValue('_project_id_');
562
+
563
+ jest.mocked(clockifyApiRequestAllItems).mockResolvedValue(projects);
564
+
565
+ expect(
566
+ clockifyEnhanced.methods.loadOptions.loadProjectUsers.call(
567
+ loadOptionsFunctions,
568
+ ),
569
+ ).resolves.toStrictEqual([
570
+ { name: 'User X', value: '64a687e29ae1f428e7ebe303' },
571
+ ]);
572
+
573
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledTimes(1);
574
+ expect(clockifyApiRequestAllItems).toHaveBeenCalledWith(
575
+ 'GET',
576
+ `workspaces/_workspace_id_/users`,
577
+ undefined,
578
+ { projectId: '_project_id_' },
579
+ );
580
+ });
581
+ });
582
+ });
583
+
584
+ describe('node execution', () => {
585
+ it('should update project', () => {
586
+ const jsonArray = [{ json: project }];
587
+
588
+ const executionData = jsonArray.map(({ json }) => ({
589
+ json,
590
+ pairedItem: { item: 0 },
591
+ }));
592
+
593
+ executeFunctions.getInputData.mockReturnValue([
594
+ {
595
+ json: {},
596
+ },
597
+ ]);
598
+
599
+ executeFunctions.getNodeParameter
600
+ .calledWith('resource', 0)
601
+ .mockReturnValue('project');
602
+
603
+ executeFunctions.getNodeParameter
604
+ .calledWith('operation', 0)
605
+ .mockReturnValue('update');
606
+
607
+ executeFunctions.getNodeParameter
608
+ .calledWith('workspaceId', 0)
609
+ .mockReturnValue('64a687e29ae1f428e7ebe303');
610
+
611
+ executeFunctions.getNodeParameter
612
+ .calledWith('projectId', 0)
613
+ .mockReturnValue('5b641568b07987035750505e');
614
+
615
+ executeFunctions.getNodeParameter
616
+ .calledWith('updateFields', 0)
617
+ .mockReturnValue({
618
+ archived: false,
619
+ });
620
+
621
+ jest.mocked(clockifyApiRequest).mockResolvedValue(project);
622
+
623
+ executeFunctions.helpers.returnJsonArray.mockReturnValue(jsonArray);
624
+
625
+ executeFunctions.helpers.constructExecutionMetaData.mockReturnValue(
626
+ executionData,
627
+ );
628
+
629
+ expect(clockifyEnhanced.execute.call(executeFunctions)).resolves.toEqual([
630
+ executionData,
631
+ ]);
632
+
633
+ expect(clockifyApiRequest).toHaveBeenCalledWith(
634
+ 'PUT',
635
+ '/workspaces/64a687e29ae1f428e7ebe303/projects/5b641568b07987035750505e',
636
+ {
637
+ archived: false,
638
+ },
639
+ );
640
+ });
641
+
642
+ it('should patch project membership', () => {
643
+ const jsonArray = [{ json: project }];
644
+
645
+ const executionData = jsonArray.map(({ json }) => ({
646
+ json,
647
+ pairedItem: { item: 0 },
648
+ }));
649
+
650
+ executeFunctions.getInputData.mockReturnValue([
651
+ {
652
+ json: {},
653
+ },
654
+ ]);
655
+
656
+ executeFunctions.getNodeParameter
657
+ .calledWith('resource', 0)
658
+ .mockReturnValue('project membership');
659
+
660
+ executeFunctions.getNodeParameter
661
+ .calledWith('operation', 0)
662
+ .mockReturnValue('patch');
663
+
664
+ executeFunctions.getNodeParameter
665
+ .calledWith('workspaceId', 0)
666
+ .mockReturnValue('64a687e29ae1f428e7ebe303');
667
+
668
+ executeFunctions.getNodeParameter
669
+ .calledWith('projectId', 0)
670
+ .mockReturnValue('5b641568b07987035750505e');
671
+
672
+ executeFunctions.getNodeParameter
673
+ .calledWith('memberships', 0)
674
+ .mockReturnValue(['5a0ab5acb07987125438b60f']);
675
+
676
+ jest.mocked(clockifyApiRequest).mockResolvedValue(project);
677
+
678
+ executeFunctions.helpers.returnJsonArray
679
+ .calledWith(expect.objectContaining(project))
680
+ .mockReturnValue(jsonArray);
681
+
682
+ executeFunctions.helpers.constructExecutionMetaData
683
+ .calledWith(
684
+ expect.arrayContaining(jsonArray),
685
+ expect.objectContaining({ itemData: { item: 0 } }),
686
+ )
687
+ .mockReturnValue(executionData);
688
+
689
+ expect(clockifyEnhanced.execute.call(executeFunctions)).resolves.toEqual([
690
+ executionData,
691
+ ]);
692
+
693
+ expect(clockifyApiRequest).toHaveBeenCalledWith(
694
+ 'PATCH',
695
+ '/workspaces/64a687e29ae1f428e7ebe303/projects/5b641568b07987035750505e/memberships',
696
+ {
697
+ memberships: [{ userId: '5a0ab5acb07987125438b60f' }],
698
+ },
699
+ );
700
+ });
701
+
702
+ it('should assign users to project', () => {
703
+ const jsonArray = [{ json: project }];
704
+
705
+ const executionData = jsonArray.map(({ json }) => ({
706
+ json,
707
+ pairedItem: { item: 0 },
708
+ }));
709
+
710
+ executeFunctions.getInputData.mockReturnValue([
711
+ {
712
+ json: {},
713
+ },
714
+ ]);
715
+
716
+ executeFunctions.getNodeParameter
717
+ .calledWith('resource', 0)
718
+ .mockReturnValue('project membership');
719
+
720
+ executeFunctions.getNodeParameter
721
+ .calledWith('operation', 0)
722
+ .mockReturnValue('assign');
723
+
724
+ executeFunctions.getNodeParameter
725
+ .calledWith('workspaceId', 0)
726
+ .mockReturnValue('64a687e29ae1f428e7ebe303');
727
+
728
+ executeFunctions.getNodeParameter
729
+ .calledWith('projectId', 0)
730
+ .mockReturnValue('5b641568b07987035750505e');
731
+
732
+ executeFunctions.getNodeParameter
733
+ .calledWith('userIdsToAssign', 0)
734
+ .mockReturnValue(['5a0ab5acb07987125438b60f']);
735
+
736
+ jest.mocked(clockifyApiRequest).mockResolvedValue(project);
737
+
738
+ executeFunctions.helpers.returnJsonArray
739
+ .calledWith(expect.objectContaining(project))
740
+ .mockReturnValue(jsonArray);
741
+
742
+ executeFunctions.helpers.constructExecutionMetaData
743
+ .calledWith(
744
+ expect.arrayContaining(jsonArray),
745
+ expect.objectContaining({ itemData: { item: 0 } }),
746
+ )
747
+ .mockReturnValue(executionData);
748
+
749
+ expect(clockifyEnhanced.execute.call(executeFunctions)).resolves.toEqual([
750
+ executionData,
751
+ ]);
752
+
753
+ expect(clockifyApiRequest).toHaveBeenCalledWith(
754
+ 'POST',
755
+ '/workspaces/64a687e29ae1f428e7ebe303/projects/5b641568b07987035750505e/memberships',
756
+ {
757
+ remove: false,
758
+ userIds: ['5a0ab5acb07987125438b60f'],
759
+ },
760
+ );
761
+ });
762
+
763
+ it('should remove users to project', () => {
764
+ const jsonArray = [{ json: project }];
765
+
766
+ const executionData = jsonArray.map(({ json }) => ({
767
+ json,
768
+ pairedItem: { item: 0 },
769
+ }));
770
+
771
+ executeFunctions.getInputData.mockReturnValue([
772
+ {
773
+ json: {},
774
+ },
775
+ ]);
776
+
777
+ executeFunctions.getNodeParameter
778
+ .calledWith('resource', 0)
779
+ .mockReturnValue('project membership');
780
+
781
+ executeFunctions.getNodeParameter
782
+ .calledWith('operation', 0)
783
+ .mockReturnValue('remove');
784
+
785
+ executeFunctions.getNodeParameter
786
+ .calledWith('workspaceId', 0)
787
+ .mockReturnValue('64a687e29ae1f428e7ebe303');
788
+
789
+ executeFunctions.getNodeParameter
790
+ .calledWith('projectId', 0)
791
+ .mockReturnValue('5b641568b07987035750505e');
792
+
793
+ executeFunctions.getNodeParameter
794
+ .calledWith('userIdsToRemove', 0)
795
+ .mockReturnValue(['5a0ab5acb07987125438b60f']);
796
+
797
+ jest.mocked(clockifyApiRequest).mockResolvedValue(project);
798
+
799
+ executeFunctions.helpers.returnJsonArray
800
+ .calledWith(expect.objectContaining(project))
801
+ .mockReturnValue(jsonArray);
802
+
803
+ executeFunctions.helpers.constructExecutionMetaData
804
+ .calledWith(
805
+ expect.arrayContaining(jsonArray),
806
+ expect.objectContaining({ itemData: { item: 0 } }),
807
+ )
808
+ .mockReturnValue(executionData);
809
+
810
+ expect(clockifyEnhanced.execute.call(executeFunctions)).resolves.toEqual([
811
+ executionData,
812
+ ]);
813
+
814
+ expect(clockifyApiRequest).toHaveBeenCalledWith(
815
+ 'POST',
816
+ '/workspaces/64a687e29ae1f428e7ebe303/projects/5b641568b07987035750505e/memberships',
817
+ {
818
+ remove: true,
819
+ userIds: ['5a0ab5acb07987125438b60f'],
820
+ },
821
+ );
822
+ });
823
+
824
+ it('should return on error', () => {
825
+ executeFunctions.getInputData.mockReturnValue([
826
+ {
827
+ json: {},
828
+ },
829
+ ]);
830
+
831
+ executeFunctions.getNodeParameter
832
+ .calledWith('resource', 0)
833
+ .mockReturnValue('project');
834
+
835
+ executeFunctions.getNodeParameter
836
+ .calledWith('operation', 0)
837
+ .mockReturnValue('update');
838
+
839
+ executeFunctions.getNodeParameter
840
+ .calledWith('workspaceId', 0)
841
+ .mockReturnValue('64a687e29ae1f428e7ebe303');
842
+
843
+ executeFunctions.getNodeParameter
844
+ .calledWith('projectId', 0)
845
+ .mockReturnValue('5b641568b07987035750505e');
846
+
847
+ executeFunctions.getNodeParameter
848
+ .calledWith('updateFields', 0)
849
+ .mockReturnValue({
850
+ archived: false,
851
+ });
852
+
853
+ jest
854
+ .mocked(clockifyApiRequest)
855
+ .mockRejectedValue(new Error('__error_message__'));
856
+
857
+ executeFunctions.continueOnFail.mockReturnValue(true);
858
+
859
+ expect(clockifyEnhanced.execute.call(executeFunctions)).resolves.toEqual([
860
+ [{ json: { error: '__error_message__' }, pairedItem: { item: 0 } }],
861
+ ]);
862
+
863
+ expect(clockifyApiRequest).toHaveBeenCalledWith(
864
+ 'PUT',
865
+ '/workspaces/64a687e29ae1f428e7ebe303/projects/5b641568b07987035750505e',
866
+ {
867
+ archived: false,
868
+ },
869
+ );
870
+ });
871
+
872
+ it('should throw on error', () => {
873
+ executeFunctions.getInputData.mockReturnValue([
874
+ {
875
+ json: {},
876
+ },
877
+ ]);
878
+
879
+ executeFunctions.getNodeParameter
880
+ .calledWith('resource', 0)
881
+ .mockReturnValue('project');
882
+
883
+ executeFunctions.getNodeParameter
884
+ .calledWith('operation', 0)
885
+ .mockReturnValue('update');
886
+
887
+ executeFunctions.getNodeParameter
888
+ .calledWith('workspaceId', 0)
889
+ .mockReturnValue('64a687e29ae1f428e7ebe303');
890
+
891
+ executeFunctions.getNodeParameter
892
+ .calledWith('projectId', 0)
893
+ .mockReturnValue('5b641568b07987035750505e');
894
+
895
+ executeFunctions.getNodeParameter
896
+ .calledWith('updateFields', 0)
897
+ .mockReturnValue({
898
+ archived: false,
899
+ });
900
+
901
+ const error = new Error('__error_message__');
902
+
903
+ jest.mocked(clockifyApiRequest).mockRejectedValue(error);
904
+
905
+ executeFunctions.continueOnFail.mockReturnValue(false);
906
+
907
+ expect(clockifyEnhanced.execute.call(executeFunctions)).rejects.toEqual(
908
+ error,
909
+ );
910
+
911
+ expect(clockifyApiRequest).toHaveBeenCalledWith(
912
+ 'PUT',
913
+ '/workspaces/64a687e29ae1f428e7ebe303/projects/5b641568b07987035750505e',
914
+ {
915
+ archived: false,
916
+ },
917
+ );
918
+ });
919
+ });
920
+ });