@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.
- package/.turbo/turbo-build.log +14 -0
- package/LICENSE +201 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +1 -0
- package/dist/e2e/e2eCollectionModel.d.ts +2830 -0
- package/dist/e2e/e2eCollectionModel.js +4264 -0
- package/dist/e2e/e2ePageObjectModel.d.ts +309 -0
- package/dist/e2e/e2ePageObjectModel.js +627 -0
- package/dist/e2e/e2eUtils.d.ts +42 -0
- package/dist/e2e/e2eUtils.js +399 -0
- package/dist/e2e/index.d.ts +4 -0
- package/dist/e2e/index.js +43 -0
- package/dist/externalVersion.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/server/collections/categories.d.ts +3 -0
- package/dist/server/collections/categories.js +35 -0
- package/dist/server/collections/comments.d.ts +3 -0
- package/dist/server/collections/comments.js +44 -0
- package/dist/server/collections/posts.d.ts +3 -0
- package/dist/server/collections/posts.js +60 -0
- package/dist/server/collections/replies.d.ts +8 -0
- package/dist/server/collections/replies.js +31 -0
- package/dist/server/collections/tags.d.ts +3 -0
- package/dist/server/collections/tags.js +35 -0
- package/dist/server/functions.d.ts +4 -0
- package/dist/server/functions.js +25 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +102 -0
- package/dist/server/instructions.d.ts +41 -0
- package/dist/server/instructions.js +82 -0
- package/dist/server/triggers.d.ts +20 -0
- package/dist/server/triggers.js +49 -0
- package/e2e.d.ts +2 -0
- package/e2e.js +1 -0
- package/package.json +24 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/index.ts +3 -0
- package/src/e2e/e2eCollectionModel.ts +4251 -0
- package/src/e2e/e2ePageObjectModel.ts +647 -0
- package/src/e2e/e2eUtils.ts +950 -0
- package/src/e2e/index.ts +4 -0
- package/src/index.ts +2 -0
- package/src/server/collections/categories.ts +15 -0
- package/src/server/collections/comments.ts +24 -0
- package/src/server/collections/posts.ts +40 -0
- package/src/server/collections/replies.ts +9 -0
- package/src/server/collections/tags.ts +15 -0
- package/src/server/functions.ts +3 -0
- package/src/server/index.ts +84 -0
- package/src/server/instructions.ts +67 -0
- package/src/server/triggers.ts +19 -0
package/src/e2e/index.ts
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CollectionOptions } from '@tachybase/database';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: 'comments',
|
|
5
|
+
fields: [
|
|
6
|
+
{
|
|
7
|
+
type: 'belongsTo',
|
|
8
|
+
name: 'post',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
type: 'text',
|
|
12
|
+
name: 'content',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
type: 'integer',
|
|
16
|
+
name: 'status',
|
|
17
|
+
defaultValue: 0,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'hasMany',
|
|
21
|
+
name: 'replies',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
} as CollectionOptions;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CollectionOptions } from '@tachybase/database';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
name: 'posts',
|
|
5
|
+
createdBy: true,
|
|
6
|
+
updatedBy: true,
|
|
7
|
+
fields: [
|
|
8
|
+
{
|
|
9
|
+
type: 'string',
|
|
10
|
+
name: 'title',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
type: 'boolean',
|
|
14
|
+
name: 'published',
|
|
15
|
+
defaultValue: false,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: 'integer',
|
|
19
|
+
name: 'read',
|
|
20
|
+
defaultValue: 0,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: 'belongsTo',
|
|
24
|
+
name: 'category',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: 'hasMany',
|
|
28
|
+
name: 'comments',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
type: 'belongsToMany',
|
|
32
|
+
name: 'tags',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: 'integer',
|
|
36
|
+
name: 'read',
|
|
37
|
+
defaultValue: 0,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
} as CollectionOptions;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { SequelizeDataSource } from '@tachybase/data-source';
|
|
3
|
+
import { Resourcer } from '@tachybase/resourcer';
|
|
4
|
+
import { ApplicationOptions, Plugin } from '@tachybase/server';
|
|
5
|
+
import { createMockServer, mockDatabase, MockServer } from '@tachybase/test';
|
|
6
|
+
import { uid } from '@tachybase/utils';
|
|
7
|
+
|
|
8
|
+
import functions from './functions';
|
|
9
|
+
import instructions from './instructions';
|
|
10
|
+
import triggers from './triggers';
|
|
11
|
+
|
|
12
|
+
export interface MockServerOptions extends ApplicationOptions {
|
|
13
|
+
collectionsPath?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// async function createMockServer(options: MockServerOptions) {
|
|
17
|
+
// const app = mockServer(options);
|
|
18
|
+
// await app.cleanDb();
|
|
19
|
+
// await app.runCommand('start', '--quickstart');
|
|
20
|
+
// return app;
|
|
21
|
+
// }
|
|
22
|
+
|
|
23
|
+
export function sleep(ms: number) {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
setTimeout(resolve, ms);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function getApp(options: MockServerOptions = {}): Promise<MockServer> {
|
|
30
|
+
const { plugins = [], collectionsPath, ...others } = options;
|
|
31
|
+
class TestCollectionPlugin extends Plugin {
|
|
32
|
+
async load() {
|
|
33
|
+
if (collectionsPath) {
|
|
34
|
+
await this.db.import({ directory: collectionsPath });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const app = await createMockServer({
|
|
39
|
+
...others,
|
|
40
|
+
plugins: [
|
|
41
|
+
[
|
|
42
|
+
'workflow',
|
|
43
|
+
{
|
|
44
|
+
triggers,
|
|
45
|
+
instructions,
|
|
46
|
+
functions,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
'workflow-test',
|
|
50
|
+
TestCollectionPlugin,
|
|
51
|
+
...plugins,
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await app.dataSourceManager.add(
|
|
56
|
+
new SequelizeDataSource({
|
|
57
|
+
name: 'another',
|
|
58
|
+
collectionManager: {
|
|
59
|
+
database: mockDatabase({
|
|
60
|
+
tablePrefix: `t${uid(5)}`,
|
|
61
|
+
}),
|
|
62
|
+
},
|
|
63
|
+
resourceManager: {},
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
const another = app.dataSourceManager.dataSources.get('another');
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
const anotherDB = another.collectionManager.db;
|
|
69
|
+
|
|
70
|
+
await anotherDB.import({
|
|
71
|
+
directory: path.resolve(__dirname, 'collections'),
|
|
72
|
+
});
|
|
73
|
+
await anotherDB.sync();
|
|
74
|
+
|
|
75
|
+
another.acl.allow('*', '*');
|
|
76
|
+
|
|
77
|
+
return app;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default class WorkflowTestPlugin extends Plugin {
|
|
81
|
+
async load() {
|
|
82
|
+
await this.importCollections(path.resolve(__dirname, 'collections'));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { lodash } from '@tachybase/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
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
customizedSuccess: {
|
|
53
|
+
run(node, input, processor) {
|
|
54
|
+
return {
|
|
55
|
+
status: 100,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
customizedError: {
|
|
61
|
+
run(node, input, processor) {
|
|
62
|
+
return {
|
|
63
|
+
status: -100,
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
syncTrigger: class {
|
|
3
|
+
constructor(public readonly workflow) {}
|
|
4
|
+
on() {}
|
|
5
|
+
off() {}
|
|
6
|
+
sync = true;
|
|
7
|
+
validateEvent() {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
asyncTrigger: class {
|
|
12
|
+
constructor(public readonly workflow) {}
|
|
13
|
+
on() {}
|
|
14
|
+
off() {}
|
|
15
|
+
validateEvent() {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
};
|