@nocobase/plugin-workflow-test 0.17.0-alpha.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.
@@ -0,0 +1,15 @@
1
+ import { CollectionOptions } from '@nocobase/database';
2
+
3
+ export default {
4
+ name: 'tags',
5
+ fields: [
6
+ {
7
+ type: 'belongsToMany',
8
+ name: 'posts',
9
+ },
10
+ {
11
+ type: 'string',
12
+ name: 'name',
13
+ },
14
+ ],
15
+ } as CollectionOptions;
@@ -0,0 +1,3 @@
1
+ export default {
2
+ no1: () => 1,
3
+ };
@@ -0,0 +1,78 @@
1
+ import path from 'path';
2
+
3
+ import { Plugin, ApplicationOptions } from '@nocobase/server';
4
+ import { MockServer, mockServer } from '@nocobase/test';
5
+
6
+ import instructions from './instructions';
7
+ import functions from './functions';
8
+
9
+ interface MockServerOptions extends ApplicationOptions {
10
+ autoStart?: boolean;
11
+ collectionsPath?: string;
12
+ cleanDb?: boolean;
13
+ }
14
+
15
+ async function createMockServer({ autoStart, collectionsPath, cleanDb, ...options }: MockServerOptions) {
16
+ const app = mockServer(options);
17
+
18
+ if (cleanDb) {
19
+ await app.cleanDb();
20
+ }
21
+
22
+ await app.load();
23
+
24
+ if (collectionsPath) {
25
+ await app.db.import({ directory: collectionsPath });
26
+ }
27
+
28
+ try {
29
+ await app.db.sync();
30
+ } catch (error) {
31
+ console.error(error);
32
+ }
33
+
34
+ if (autoStart) {
35
+ await app.start();
36
+ // await app.runCommand('start', '--quickstart');
37
+ }
38
+
39
+ return app;
40
+ }
41
+
42
+ export function sleep(ms: number) {
43
+ return new Promise((resolve) => {
44
+ setTimeout(resolve, ms);
45
+ });
46
+ }
47
+
48
+ export async function getApp({
49
+ autoStart = true,
50
+ cleanDb = true,
51
+ plugins = [],
52
+ ...options
53
+ }: MockServerOptions = {}): Promise<MockServer> {
54
+ return createMockServer({
55
+ ...options,
56
+ autoStart,
57
+ cleanDb,
58
+ plugins: ['workflow', 'workflow-test', ...plugins],
59
+ });
60
+ }
61
+
62
+ export default class extends Plugin {
63
+ async load() {
64
+ await this.db.import({
65
+ directory: path.resolve(__dirname, 'collections'),
66
+ });
67
+
68
+ const workflow = this.app.getPlugin<any>('workflow');
69
+
70
+ for (const [key, instruction] of Object.entries(instructions)) {
71
+ workflow.instructions.register(key, instruction);
72
+ }
73
+
74
+ for (const [key, func] of Object.entries(functions)) {
75
+ workflow.functions.register(key, func);
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,66 @@
1
+ import { lodash } from '@nocobase/utils';
2
+
3
+ export default {
4
+ echo: {
5
+ run({ config = {} }: any, { result }, processor) {
6
+ return {
7
+ status: 1,
8
+ result: config.path == null ? result : lodash.get(result, config.path),
9
+ };
10
+ },
11
+ },
12
+
13
+ error: {
14
+ run(node, input, processor) {
15
+ throw new Error('definite error');
16
+ },
17
+ },
18
+
19
+ pending: {
20
+ run(node, input, processor) {
21
+ return {
22
+ status: 0,
23
+ };
24
+ },
25
+ },
26
+
27
+ prompt: {
28
+ run(node, input, processor) {
29
+ return {
30
+ status: 0,
31
+ };
32
+ },
33
+ resume(node, job, processor) {
34
+ return job.set({
35
+ status: 1,
36
+ });
37
+ },
38
+ },
39
+
40
+ 'prompt->error': {
41
+ run(node, input, processor) {
42
+ return {
43
+ status: 0,
44
+ };
45
+ },
46
+ resume(node, input, processor) {
47
+ throw new Error('input failed');
48
+ },
49
+ },
50
+
51
+ customizedSuccess: {
52
+ run(node, input, processor) {
53
+ return {
54
+ status: 100,
55
+ };
56
+ },
57
+ },
58
+
59
+ customizedError: {
60
+ run(node, input, processor) {
61
+ return {
62
+ status: -100,
63
+ };
64
+ },
65
+ },
66
+ };