@tachybase/plugin-workflow-test 0.23.8

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 (55) hide show
  1. package/.turbo/turbo-build.log +14 -0
  2. package/LICENSE +201 -0
  3. package/client.d.ts +2 -0
  4. package/client.js +1 -0
  5. package/dist/client/index.d.ts +3 -0
  6. package/dist/client/index.js +1 -0
  7. package/dist/e2e/e2eCollectionModel.d.ts +2830 -0
  8. package/dist/e2e/e2eCollectionModel.js +4264 -0
  9. package/dist/e2e/e2ePageObjectModel.d.ts +309 -0
  10. package/dist/e2e/e2ePageObjectModel.js +627 -0
  11. package/dist/e2e/e2eUtils.d.ts +42 -0
  12. package/dist/e2e/e2eUtils.js +399 -0
  13. package/dist/e2e/index.d.ts +4 -0
  14. package/dist/e2e/index.js +43 -0
  15. package/dist/externalVersion.js +10 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +39 -0
  18. package/dist/server/collections/categories.d.ts +3 -0
  19. package/dist/server/collections/categories.js +35 -0
  20. package/dist/server/collections/comments.d.ts +3 -0
  21. package/dist/server/collections/comments.js +44 -0
  22. package/dist/server/collections/posts.d.ts +3 -0
  23. package/dist/server/collections/posts.js +60 -0
  24. package/dist/server/collections/replies.d.ts +8 -0
  25. package/dist/server/collections/replies.js +31 -0
  26. package/dist/server/collections/tags.d.ts +3 -0
  27. package/dist/server/collections/tags.js +35 -0
  28. package/dist/server/functions.d.ts +4 -0
  29. package/dist/server/functions.js +25 -0
  30. package/dist/server/index.d.ts +10 -0
  31. package/dist/server/index.js +102 -0
  32. package/dist/server/instructions.d.ts +41 -0
  33. package/dist/server/instructions.js +82 -0
  34. package/dist/server/triggers.d.ts +20 -0
  35. package/dist/server/triggers.js +49 -0
  36. package/e2e.d.ts +2 -0
  37. package/e2e.js +1 -0
  38. package/package.json +24 -0
  39. package/server.d.ts +2 -0
  40. package/server.js +1 -0
  41. package/src/client/index.ts +3 -0
  42. package/src/e2e/e2eCollectionModel.ts +4251 -0
  43. package/src/e2e/e2ePageObjectModel.ts +647 -0
  44. package/src/e2e/e2eUtils.ts +950 -0
  45. package/src/e2e/index.ts +4 -0
  46. package/src/index.ts +2 -0
  47. package/src/server/collections/categories.ts +15 -0
  48. package/src/server/collections/comments.ts +24 -0
  49. package/src/server/collections/posts.ts +40 -0
  50. package/src/server/collections/replies.ts +9 -0
  51. package/src/server/collections/tags.ts +15 -0
  52. package/src/server/functions.ts +3 -0
  53. package/src/server/index.ts +84 -0
  54. package/src/server/instructions.ts +67 -0
  55. package/src/server/triggers.ts +19 -0
@@ -0,0 +1,950 @@
1
+ import { Page, request } from '@tachybase/test/e2e';
2
+
3
+ const PORT = process.env.APP_PORT || 20000;
4
+ const APP_BASE_URL = process.env.APP_BASE_URL || `http://localhost:${PORT}`;
5
+
6
+ // 创建工作流
7
+ export const apiCreateWorkflow = async (data: any) => {
8
+ const api = await request.newContext({
9
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
10
+ });
11
+
12
+ const state = await api.storageState();
13
+ const headers = getHeaders(state);
14
+ /*
15
+ {
16
+ "current": true,
17
+ "options": {
18
+ "deleteExecutionOnStatus": []
19
+ },
20
+ "title": "t3",
21
+ "type": "collection"
22
+ }
23
+ */
24
+ const result = await api.post(`/api/workflows:create`, {
25
+ headers,
26
+ data,
27
+ });
28
+
29
+ if (!result.ok()) {
30
+ throw new Error(await result.text());
31
+ }
32
+ /*
33
+ {
34
+ "data": {
35
+ "id": 74,
36
+ "key": "il2nu3ovj53",
37
+ "updatedAt": "2023-12-12T06:53:21.232Z",
38
+ "createdAt": "2023-12-12T06:53:21.232Z",
39
+ "title": "t3",
40
+ "type": "collection",
41
+ "enabled": false,
42
+ "description": null,
43
+ "executed": 0,
44
+ "allExecuted": 0,
45
+ "config": {},
46
+ "current": true,
47
+ "options": {
48
+ "deleteExecutionOnStatus": []
49
+ },
50
+ "useTransaction": true
51
+ }
52
+ }
53
+ */
54
+ return (await result.json()).data;
55
+ };
56
+
57
+ // 更新工作流
58
+ export const apiUpdateWorkflow = async (id: number, data: any) => {
59
+ const api = await request.newContext({
60
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
61
+ });
62
+
63
+ const state = await api.storageState();
64
+ const headers = getHeaders(state);
65
+ /*
66
+ {
67
+ "id": 74,
68
+ "key": "il2nu3ovj53",
69
+ "updatedAt": "2023-12-12T06:53:21.232Z",
70
+ "createdAt": "2023-12-12T06:53:21.232Z",
71
+ "title": "t3",
72
+ "type": "collection",
73
+ "enabled": false,
74
+ "description": null,
75
+ "executed": 0,
76
+ "allExecuted": 0,
77
+ "current": true,
78
+ "options": {
79
+ "deleteExecutionOnStatus": []
80
+ },
81
+ "useTransaction": true
82
+ }
83
+ */
84
+ const result = await api.post(`/api/workflows:update?filterByTk=${id}`, {
85
+ headers,
86
+ data,
87
+ });
88
+
89
+ if (!result.ok()) {
90
+ throw new Error(await result.text());
91
+ }
92
+ /*{
93
+ "data": [
94
+ {
95
+ "id": 72,
96
+ "createdAt": "2023-12-12T02:43:53.793Z",
97
+ "updatedAt": "2023-12-12T05:41:33.300Z",
98
+ "key": "fzk3j2oj4el",
99
+ "title": "a11",
100
+ "enabled": true,
101
+ "description": null,
102
+ "type": "collection",
103
+ "config": {},
104
+ "useTransaction": true,
105
+ "executed": 0,
106
+ "allExecuted": 0,
107
+ "current": true,
108
+ "options": {
109
+ "deleteExecutionOnStatus": []
110
+ }
111
+ }
112
+ ]
113
+ }*/
114
+ return (await result.json()).data;
115
+ };
116
+
117
+ // 删除工作流
118
+ export const apiDeleteWorkflow = async (id: number) => {
119
+ const api = await request.newContext({
120
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
121
+ });
122
+
123
+ const state = await api.storageState();
124
+ const headers = getHeaders(state);
125
+
126
+ const result = await api.post(`/api/workflows:destroy?filterByTk=${id}`, {
127
+ headers,
128
+ });
129
+
130
+ if (!result.ok()) {
131
+ throw new Error(await result.text());
132
+ }
133
+ // {"data":1}
134
+ return (await result.json()).data;
135
+ };
136
+
137
+ // 查询工作流
138
+ export const apiGetWorkflow = async (id: number) => {
139
+ const api = await request.newContext({
140
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
141
+ });
142
+
143
+ const state = await api.storageState();
144
+ const headers = getHeaders(state);
145
+
146
+ const result = await api.get(`/api/workflows:get?filterByTk=${id}`, {
147
+ headers,
148
+ });
149
+
150
+ if (!result.ok()) {
151
+ throw new Error(await result.text());
152
+ }
153
+ /*
154
+ {
155
+ "data": {
156
+ "id": 73,
157
+ "createdAt": "2023-12-12T05:59:52.741Z",
158
+ "updatedAt": "2023-12-12T05:59:52.741Z",
159
+ "key": "1iuin0qchrh",
160
+ "title": "t2",
161
+ "enabled": false,
162
+ "description": null,
163
+ "type": "collection",
164
+ "config": { },
165
+ "useTransaction": true,
166
+ "executed": 0,
167
+ "allExecuted": 0,
168
+ "current": true,
169
+ "options": { }
170
+ }
171
+ }
172
+ */
173
+ return (await result.json()).data;
174
+ };
175
+
176
+ // 更新工作流触发器节点
177
+ export const apiUpdateWorkflowTrigger = async (id: number, data: any) => {
178
+ const api = await request.newContext({
179
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
180
+ });
181
+
182
+ const state = await api.storageState();
183
+ const headers = getHeaders(state);
184
+ /*
185
+ {
186
+ "config": {
187
+ "appends": [
188
+ "dept"
189
+ ],
190
+ "collection": "tt_mnt_org",
191
+ "changed": [],
192
+ "condition": {
193
+ "$and": [
194
+ {
195
+ "id": {
196
+ "$eq": 1
197
+ }
198
+ }
199
+ ]
200
+ },
201
+ "mode": 1
202
+ }
203
+ }
204
+ */
205
+ const result = await api.post(`/api/workflows:update?filterByTk=${id}`, {
206
+ headers,
207
+ data,
208
+ });
209
+
210
+ if (!result.ok()) {
211
+ throw new Error(await result.text());
212
+ }
213
+ /*
214
+ {
215
+ "data": [
216
+ {
217
+ "id": 73,
218
+ "createdAt": "2023-12-12T05:59:52.741Z",
219
+ "updatedAt": "2023-12-12T06:13:36.068Z",
220
+ "key": "1iuin0qchrh",
221
+ "title": "t2",
222
+ "enabled": false,
223
+ "description": null,
224
+ "type": "collection",
225
+ "config": {
226
+ "appends": [
227
+ "dept"
228
+ ],
229
+ "collection": "tt_mnt_org",
230
+ "changed": [],
231
+ "condition": {
232
+ "$and": [
233
+ {
234
+ "id": {
235
+ "$eq": 1
236
+ }
237
+ }
238
+ ]
239
+ },
240
+ "mode": 1
241
+ },
242
+ "useTransaction": true,
243
+ "executed": 0,
244
+ "allExecuted": 0,
245
+ "current": true,
246
+ "options": {}
247
+ }
248
+ ]
249
+ }
250
+ */
251
+ return (await result.json()).data;
252
+ };
253
+
254
+ // 添加工作流节点
255
+ export const apiCreateWorkflowNode = async (workflowId: number, data: any) => {
256
+ const api = await request.newContext({
257
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
258
+ });
259
+
260
+ const state = await api.storageState();
261
+ const headers = getHeaders(state);
262
+ /*upstreamId前置节点id ,null代表再触发器节点后面增加节点
263
+ {
264
+ "type": "calculation",
265
+ "upstreamId": 263,
266
+ "branchIndex": null,
267
+ "title": "运算",
268
+ "config": {}
269
+ }
270
+ */
271
+ const result = await api.post(`/api/workflows/${workflowId}/nodes:create`, {
272
+ headers,
273
+ data,
274
+ });
275
+
276
+ if (!result.ok()) {
277
+ throw new Error(await result.text());
278
+ }
279
+ /*
280
+ {
281
+ "data": {
282
+ "id": 265,
283
+ "type": "calculation",
284
+ "upstreamId": null,
285
+ "branchIndex": null,
286
+ "title": "运算",
287
+ "config": {},
288
+ "workflowId": 76,
289
+ "updatedAt": "2023-12-16T10:56:39.288Z",
290
+ "createdAt": "2023-12-16T10:56:39.281Z",
291
+ "key": "20jz2urt5w7",
292
+ "downstreamId": 263
293
+ }
294
+ }
295
+ */
296
+ return (await result.json()).data;
297
+ };
298
+
299
+ // 查询工作流节点
300
+ export const apiGetWorkflowNode = async (id: number) => {
301
+ const api = await request.newContext({
302
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
303
+ });
304
+
305
+ const state = await api.storageState();
306
+ const headers = getHeaders(state);
307
+
308
+ const result = await api.get(`/api/flow_nodes:get?filterByTk=${id}`, {
309
+ headers,
310
+ });
311
+
312
+ if (!result.ok()) {
313
+ throw new Error(await result.text());
314
+ }
315
+ /*
316
+ {
317
+ "data": {
318
+ "id": 267,
319
+ "createdAt": "2023-12-17T06:56:10.147Z",
320
+ "updatedAt": "2023-12-17T08:53:38.117Z",
321
+ "key": "idr5wibhyqn",
322
+ "title": "查询数据",
323
+ "upstreamId": 269,
324
+ "branchIndex": null,
325
+ "downstreamId": 270,
326
+ "type": "query",
327
+ "config": {
328
+ "collection": "users",
329
+ "params": {
330
+ "filter": {
331
+ "$and": [
332
+ {
333
+ "id": {
334
+ "$eq": "{{$context.data.id}}"
335
+ }
336
+ }
337
+ ]
338
+ },
339
+ "sort": [],
340
+ "page": 1,
341
+ "pageSize": 20,
342
+ "appends": []
343
+ }
344
+ },
345
+ "workflowId": 76
346
+ }
347
+ }
348
+ */
349
+ return (await result.json()).data;
350
+ };
351
+
352
+ // 更新工作流节点配置
353
+ export const apiUpdateWorkflowNode = async (id: number, data: any) => {
354
+ const api = await request.newContext({
355
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
356
+ });
357
+
358
+ const state = await api.storageState();
359
+ const headers = getHeaders(state);
360
+ /*
361
+ {
362
+ "config": {
363
+ "engine": "math.js",
364
+ "expression": "1"
365
+ }
366
+ }
367
+ */
368
+ const result = await api.post(`/api/flow_nodes:update?filterByTk=${id}`, {
369
+ headers,
370
+ data,
371
+ });
372
+
373
+ if (!result.ok()) {
374
+ throw new Error(await result.text());
375
+ }
376
+ /*
377
+ {
378
+ "data": [
379
+ {
380
+ "id": 266,
381
+ "createdAt": "2023-12-16T10:56:58.586Z",
382
+ "updatedAt": "2023-12-16T11:16:32.796Z",
383
+ "key": "atbyvcs5mwc",
384
+ "title": "运算",
385
+ "upstreamId": 263,
386
+ "branchIndex": null,
387
+ "downstreamId": null,
388
+ "type": "calculation",
389
+ "config": {
390
+ "engine": "math.js",
391
+ "expression": "1"
392
+ },
393
+ "workflowId": 76
394
+ }
395
+ ]
396
+ }
397
+ */
398
+ return (await result.json()).data;
399
+ };
400
+
401
+ // 查询节点执行历史
402
+ export const apiGetWorkflowNodeExecutions = async (id: number) => {
403
+ const api = await request.newContext({
404
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
405
+ });
406
+
407
+ const state = await api.storageState();
408
+ const headers = getHeaders(state);
409
+ const url = `/api/executions:list?appends[]=jobs&filter[workflowId]=${id}&fields=id,createdAt,updatedAt,key,status,workflowId,jobs`;
410
+ const result = await api.get(url, {
411
+ headers,
412
+ });
413
+
414
+ if (!result.ok()) {
415
+ throw new Error(await result.text());
416
+ }
417
+ /*
418
+ {
419
+ "data": [
420
+ {
421
+ "id": 15,
422
+ "createdAt": "2023-12-13T02:13:13.737Z",
423
+ "updatedAt": "2023-12-13T02:13:13.799Z",
424
+ "key": "yibkv8h2uq6",
425
+ "useTransaction": false,
426
+ "status": 1,
427
+ "workflowId": 16,
428
+ "jobs": [
429
+ {
430
+ "id": 16,
431
+ "createdAt": "2023-12-13T02:13:13.783Z",
432
+ "updatedAt": "2023-12-13T02:13:13.783Z",
433
+ "executionId": 15,
434
+ "nodeId": 16,
435
+ "upstreamId": null,
436
+ "status": 1,
437
+ "result": false
438
+ },
439
+ {
440
+ "id": 17,
441
+ "createdAt": "2023-12-13T02:13:13.788Z",
442
+ "updatedAt": "2023-12-13T02:13:13.788Z",
443
+ "executionId": 15,
444
+ "nodeId": 17,
445
+ "upstreamId": 16,
446
+ "status": 1,
447
+ "result": true
448
+ }
449
+ ]
450
+ },
451
+ {
452
+ "id": 14,
453
+ "createdAt": "2023-12-13T02:09:00.529Z",
454
+ "updatedAt": "2023-12-13T02:09:00.590Z",
455
+ "key": "yibkv8h2uq6",
456
+ "useTransaction": false,
457
+ "status": 1,
458
+ "workflowId": 16,
459
+ "jobs": [
460
+ {
461
+ "id": 14,
462
+ "createdAt": "2023-12-13T02:09:00.575Z",
463
+ "updatedAt": "2023-12-13T02:09:00.575Z",
464
+ "executionId": 14,
465
+ "nodeId": 16,
466
+ "upstreamId": null,
467
+ "status": 1,
468
+ "result": false
469
+ },
470
+ {
471
+ "id": 15,
472
+ "createdAt": "2023-12-13T02:09:00.583Z",
473
+ "updatedAt": "2023-12-13T02:09:00.583Z",
474
+ "executionId": 14,
475
+ "nodeId": 17,
476
+ "upstreamId": 14,
477
+ "status": 1,
478
+ "result": true
479
+ }
480
+ ]
481
+ }
482
+ ],
483
+ "meta": {
484
+ "count": 2,
485
+ "page": 1,
486
+ "pageSize": 20,
487
+ "totalPage": 1
488
+ }
489
+ }
490
+ */
491
+ return (await result.json()).data;
492
+ };
493
+
494
+ // 更新业务表单条数据
495
+ export const apiUpdateRecord = async (collectionName: string, id: number, data: any) => {
496
+ const api = await request.newContext({
497
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
498
+ });
499
+ const state = await api.storageState();
500
+ const headers = getHeaders(state);
501
+ const result = await api.post(`/api/${collectionName}:update?filterByTk=${id}`, {
502
+ headers,
503
+ data,
504
+ });
505
+
506
+ if (!result.ok()) {
507
+ throw new Error(await result.text());
508
+ }
509
+ /*
510
+ {
511
+ "data": [
512
+ {
513
+ "id": 1,
514
+ "createdAt": "2023-12-12T02:43:53.793Z",
515
+ "updatedAt": "2023-12-12T05:41:33.300Z",
516
+ "key": "fzk3j2oj4el",
517
+ "title": "a11",
518
+ "enabled": true,
519
+ "description": null
520
+ }
521
+ ]
522
+ }
523
+ */
524
+ return (await result.json()).data;
525
+ };
526
+
527
+ // 查询业务表单条数据
528
+ export const apiGetRecord = async (collectionName: string, id: number) => {
529
+ const api = await request.newContext({
530
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
531
+ });
532
+ const state = await api.storageState();
533
+ const headers = getHeaders(state);
534
+ const result = await api.get(`/api/${collectionName}:get?filterByTk=${id}`, {
535
+ headers,
536
+ });
537
+
538
+ if (!result.ok()) {
539
+ throw new Error(await result.text());
540
+ }
541
+ /*
542
+ {
543
+ "data": {
544
+ "id": 1,
545
+ "createdAt": "2023-12-12T02:43:53.793Z",
546
+ "updatedAt": "2023-12-12T05:41:33.300Z",
547
+ "key": "fzk3j2oj4el",
548
+ "title": "a11",
549
+ "enabled": true,
550
+ "description": null
551
+ },
552
+ "meta": {
553
+ "allowedActions": {
554
+ "view": [
555
+ 1
556
+ ],
557
+ "update": [
558
+ 1
559
+ ],
560
+ "destroy": [
561
+ 1
562
+ ]
563
+ }
564
+ }
565
+ }
566
+ */
567
+ return (await result.json()).data;
568
+ };
569
+
570
+ // 查询业务表list
571
+ export const apiGetList = async (collectionName: string) => {
572
+ const api = await request.newContext({
573
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
574
+ });
575
+ const state = await api.storageState();
576
+ const headers = getHeaders(state);
577
+ const result = await api.get(`/api/${collectionName}:list`, {
578
+ headers,
579
+ });
580
+
581
+ if (!result.ok()) {
582
+ throw new Error(await result.text());
583
+ }
584
+ /*
585
+ {
586
+ "data": [
587
+ {
588
+ "id": 1,
589
+ "createdAt": "2023-12-12T02:43:53.793Z",
590
+ "updatedAt": "2023-12-12T05:41:33.300Z",
591
+ "key": "fzk3j2oj4el",
592
+ "title": "a11",
593
+ "enabled": true,
594
+ "description": null
595
+ }
596
+ ],
597
+ "meta": {
598
+ "count": 1,
599
+ "page": 1,
600
+ "pageSize": 20,
601
+ "totalPage": 1
602
+ }
603
+ }
604
+ */
605
+ return await result.json();
606
+ };
607
+
608
+ // 查询业务表list
609
+ export const apiFilterList = async (collectionName: string, filter: string) => {
610
+ const api = await request.newContext({
611
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
612
+ });
613
+ const state = await api.storageState();
614
+ const headers = getHeaders(state);
615
+ const result = await api.get(`/api/${collectionName}:list?${filter}`, {
616
+ headers,
617
+ });
618
+
619
+ if (!result.ok()) {
620
+ throw new Error(await result.text());
621
+ }
622
+ /*
623
+ {
624
+ "data": [
625
+ {
626
+ "id": 1,
627
+ "createdAt": "2023-12-12T02:43:53.793Z",
628
+ "updatedAt": "2023-12-12T05:41:33.300Z",
629
+ "key": "fzk3j2oj4el",
630
+ "title": "a11",
631
+ "enabled": true,
632
+ "description": null
633
+ }
634
+ ],
635
+ "meta": {
636
+ "count": 1,
637
+ "page": 1,
638
+ "pageSize": 20,
639
+ "totalPage": 1
640
+ }
641
+ }
642
+ */
643
+ return await result.json();
644
+ };
645
+
646
+ // 添加业务表单条数据触发工作流表单事件,triggerWorkflows=key1!field,key2,key3!field.subfield
647
+ export const apiCreateRecordTriggerFormEvent = async (collectionName: string, triggerWorkflows: string, data: any) => {
648
+ const api = await request.newContext({
649
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
650
+ });
651
+ const state = await api.storageState();
652
+ const headers = getHeaders(state);
653
+ /*
654
+ {
655
+ "title": "a11",
656
+ "enabled": true,
657
+ "description": null
658
+ }
659
+ */
660
+ const result = await api.post(`/api/${collectionName}:create?triggerWorkflows=${triggerWorkflows}`, {
661
+ headers,
662
+ data,
663
+ });
664
+
665
+ if (!result.ok()) {
666
+ throw new Error(await result.text());
667
+ }
668
+ /*
669
+ {
670
+ "data": {
671
+ "id": 1,
672
+ "createdAt": "2023-12-12T02:43:53.793Z",
673
+ "updatedAt": "2023-12-12T05:41:33.300Z",
674
+ "key": "fzk3j2oj4el",
675
+ "title": "a11",
676
+ "enabled": true,
677
+ "description": null
678
+ },
679
+ "meta": {
680
+ "allowedActions": {
681
+ "view": [
682
+ 1
683
+ ],
684
+ "update": [
685
+ 1
686
+ ],
687
+ "destroy": [
688
+ 1
689
+ ]
690
+ }
691
+ }
692
+ }
693
+ */
694
+ return (await result.json()).data;
695
+ };
696
+
697
+ // 提交至工作流触发工作流表单事件
698
+ export const apiSubmitRecordTriggerFormEvent = async (triggerWorkflows: string, data: any) => {
699
+ const api = await request.newContext({
700
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
701
+ });
702
+ const state = await api.storageState();
703
+ const headers = getHeaders(state);
704
+ /*
705
+ {
706
+ "title": "a11",
707
+ "enabled": true,
708
+ "description": null
709
+ }
710
+ */
711
+ const result = await api.post(`/api/workflows:trigger?triggerWorkflows=${triggerWorkflows}`, {
712
+ headers,
713
+ data,
714
+ });
715
+
716
+ if (!result.ok()) {
717
+ throw new Error(await result.text());
718
+ }
719
+ /*
720
+ {}
721
+ */
722
+ return await result.json();
723
+ };
724
+
725
+ // 获取数据源个数
726
+ export const apiGetDataSourceCount = async () => {
727
+ const api = await request.newContext({
728
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
729
+ });
730
+ const state = await api.storageState();
731
+ const headers = getHeaders(state);
732
+ const result = await api.get(`/api/dataSources:list?pageSize=50`, {
733
+ headers,
734
+ });
735
+
736
+ if (!result.ok()) {
737
+ throw new Error(await result.text());
738
+ }
739
+ /*
740
+ {
741
+ "data": 1
742
+ }
743
+ */
744
+ return (await result.json()).meta.count;
745
+ };
746
+
747
+ // 添加业务表单条数据触发工作流表单事件,triggerWorkflows=key1!field,key2,key3!field.subfield
748
+ export const apiCreateRecordTriggerActionEvent = async (
749
+ collectionName: string,
750
+ triggerWorkflows: string,
751
+ data: any,
752
+ ) => {
753
+ const api = await request.newContext({
754
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
755
+ });
756
+ const state = await api.storageState();
757
+ const headers = getHeaders(state);
758
+ /*
759
+ {
760
+ "title": "a11",
761
+ "enabled": true,
762
+ "description": null
763
+ }
764
+ */
765
+ const result = await api.post(`/api/${collectionName}:create?triggerWorkflows=${triggerWorkflows}`, {
766
+ headers,
767
+ data,
768
+ });
769
+
770
+ if (!result.ok()) {
771
+ throw new Error(await result.text());
772
+ }
773
+ /*
774
+ {
775
+ "data": {
776
+ "id": 1,
777
+ "createdAt": "2023-12-12T02:43:53.793Z",
778
+ "updatedAt": "2023-12-12T05:41:33.300Z",
779
+ "key": "fzk3j2oj4el",
780
+ "title": "a11",
781
+ "enabled": true,
782
+ "description": null
783
+ },
784
+ "meta": {
785
+ "allowedActions": {
786
+ "view": [
787
+ 1
788
+ ],
789
+ "update": [
790
+ 1
791
+ ],
792
+ "destroy": [
793
+ 1
794
+ ]
795
+ }
796
+ }
797
+ }
798
+ */
799
+ return (await result.json()).data;
800
+ };
801
+
802
+ // 审批中心发起审批
803
+ export const apiApplyApprovalEvent = async (data: any) => {
804
+ const api = await request.newContext({
805
+ storageState: process.env.PLAYWRIGHT_AUTH_FILE,
806
+ });
807
+ const state = await api.storageState();
808
+ const headers = getHeaders(state);
809
+ /*
810
+ {
811
+ "title": "a11",
812
+ "enabled": true,
813
+ "description": null
814
+ }
815
+ */
816
+ const result = await api.post('/api/approvals:create', {
817
+ headers,
818
+ data,
819
+ });
820
+
821
+ if (!result.ok()) {
822
+ throw new Error(await result.text());
823
+ }
824
+ /*
825
+ {
826
+ "data": {
827
+ "id": 35,
828
+ "collectionName": "tt_amt_orgREmwr",
829
+ "data": {
830
+ "id": 6,
831
+ "url": null,
832
+ "sort": 3,
833
+ "email": null,
834
+ "phone": null,
835
+ "address": null,
836
+ "orgcode": "区域编码000000006",
837
+ "orgname": "阿三大苏打实打实的",
838
+ "isenable": null,
839
+ "staffnum": null,
840
+ "createdAt": "2024-03-09T11:37:47.620Z",
841
+ "sharesnum": null,
842
+ "updatedAt": "2024-03-09T11:37:47.620Z",
843
+ "insurednum": null,
844
+ "range_json": null,
845
+ "regcapital": null,
846
+ "testdataid": null,
847
+ "createdById": 1,
848
+ "paidcapital": null,
849
+ "range_check": [],
850
+ "updatedById": 1,
851
+ "status_radio": null,
852
+ "establishdate": null,
853
+ "insuranceratio": null,
854
+ "range_markdown": null,
855
+ "range_richtext": null,
856
+ "status_singleselect": null,
857
+ "range_multipleselect": [],
858
+ "insuranceratio_formula": null
859
+ },
860
+ "status": 2,
861
+ "workflowId": 39,
862
+ "dataKey": "6",
863
+ "updatedAt": "2024-03-09T11:37:47.640Z",
864
+ "createdAt": "2024-03-09T11:37:47.640Z",
865
+ "createdById": 1,
866
+ "updatedById": 1,
867
+ "workflowKey": null,
868
+ "latestExecutionId": null
869
+ }
870
+ }
871
+ */
872
+ return (await result.json()).data;
873
+ };
874
+
875
+ const getStorageItem = (key: string, storageState: any) => {
876
+ return storageState.origins
877
+ .find((item) => item.origin === APP_BASE_URL)
878
+ ?.localStorage.find((item) => item.name === key)?.value;
879
+ };
880
+
881
+ function getHeaders(storageState: any) {
882
+ const headers: any = {};
883
+ const token = getStorageItem('TACHYBASE_TOKEN', storageState);
884
+ const auth = getStorageItem('TACHYBASE_AUTH', storageState);
885
+ const subAppName = new URL(APP_BASE_URL).pathname.match(/^\/apps\/([^/]*)\/*/)?.[1];
886
+ const hostName = new URL(APP_BASE_URL).host;
887
+ const locale = getStorageItem('TACHYBASE_LOCALE', storageState);
888
+ const timezone = '+08:00';
889
+ const withAclMeta = 'true';
890
+ const role = getStorageItem('TACHYBASE_ROLE', storageState);
891
+
892
+ if (token) {
893
+ headers.Authorization = `Bearer ${token}`;
894
+ }
895
+ if (auth) {
896
+ headers['X-Authenticator'] = auth;
897
+ }
898
+ if (subAppName) {
899
+ headers['X-App'] = subAppName;
900
+ }
901
+ if (hostName) {
902
+ headers['X-Hostname'] = hostName;
903
+ }
904
+ if (locale) {
905
+ headers['X-Locale'] = locale;
906
+ }
907
+ if (timezone) {
908
+ headers['X-Timezone'] = timezone;
909
+ }
910
+ if (withAclMeta) {
911
+ headers['X-With-Acl-Meta'] = withAclMeta;
912
+ }
913
+ if (role) {
914
+ headers['X-Role'] = role;
915
+ }
916
+
917
+ return headers;
918
+ }
919
+
920
+ // 用户登录新会话
921
+ export const userLogin = async (page: Page, approvalUserEmail: string, approvalUser: string) => {
922
+ await page.goto(`${process.env.APP_BASE_URL}/signin`);
923
+ await page.getByPlaceholder('Email').fill(approvalUserEmail);
924
+ await page.getByPlaceholder('Password').fill(approvalUser);
925
+ await page.getByRole('button', { name: 'Sign in' }).click();
926
+ await page.waitForLoadState('networkidle');
927
+ return page;
928
+ };
929
+
930
+ export default module.exports = {
931
+ apiCreateWorkflow,
932
+ apiUpdateWorkflow,
933
+ apiDeleteWorkflow,
934
+ apiGetWorkflow,
935
+ apiUpdateWorkflowTrigger,
936
+ apiGetWorkflowNodeExecutions,
937
+ apiCreateWorkflowNode,
938
+ apiUpdateWorkflowNode,
939
+ apiGetWorkflowNode,
940
+ apiUpdateRecord,
941
+ apiGetRecord,
942
+ apiGetList,
943
+ apiCreateRecordTriggerFormEvent,
944
+ apiSubmitRecordTriggerFormEvent,
945
+ apiFilterList,
946
+ apiGetDataSourceCount,
947
+ apiCreateRecordTriggerActionEvent,
948
+ apiApplyApprovalEvent,
949
+ userLogin,
950
+ };