@saltcorn/data 1.6.0-alpha.9 → 1.6.0-beta.1
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/dist/base-plugin/actions.d.ts +3 -3
- package/dist/base-plugin/actions.d.ts.map +1 -1
- package/dist/base-plugin/actions.js +59 -17
- package/dist/base-plugin/actions.js.map +1 -1
- package/dist/base-plugin/index.d.ts +10 -5
- package/dist/base-plugin/index.d.ts.map +1 -1
- package/dist/base-plugin/types.d.ts +7 -2
- package/dist/base-plugin/types.d.ts.map +1 -1
- package/dist/base-plugin/types.js +9 -4
- package/dist/base-plugin/types.js.map +1 -1
- package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/edit.js +3 -0
- package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
- package/dist/base-plugin/viewtemplates/filter.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/filter.js +11 -3
- package/dist/base-plugin/viewtemplates/filter.js.map +1 -1
- package/dist/base-plugin/viewtemplates/list.d.ts +2 -1
- package/dist/base-plugin/viewtemplates/list.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/list.js +6 -1
- package/dist/base-plugin/viewtemplates/list.js.map +1 -1
- package/dist/base-plugin/viewtemplates/show.d.ts.map +1 -1
- package/dist/base-plugin/viewtemplates/show.js +3 -0
- package/dist/base-plugin/viewtemplates/show.js.map +1 -1
- package/dist/db/state.d.ts +4 -0
- package/dist/db/state.d.ts.map +1 -1
- package/dist/db/state.js +27 -4
- package/dist/db/state.js.map +1 -1
- package/dist/migrate.d.ts.map +1 -1
- package/dist/migrate.js +9 -4
- package/dist/migrate.js.map +1 -1
- package/dist/migrations/202603101553.d.ts +4 -0
- package/dist/migrations/202603101553.d.ts.map +1 -0
- package/dist/migrations/202603101553.js +22 -0
- package/dist/migrations/202603101553.js.map +1 -0
- package/dist/mobile-mocks/node/assert.d.ts +1 -0
- package/dist/mobile-mocks/node/assert.d.ts.map +1 -0
- package/dist/mobile-mocks/node/assert.js +2 -0
- package/dist/mobile-mocks/node/assert.js.map +1 -0
- package/dist/models/expression.d.ts +1 -1
- package/dist/models/expression.d.ts.map +1 -1
- package/dist/models/expression.js +51 -16
- package/dist/models/expression.js.map +1 -1
- package/dist/models/field.d.ts.map +1 -1
- package/dist/models/field.js +67 -10
- package/dist/models/field.js.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/internal/push_message_helper.d.ts.map +1 -1
- package/dist/models/internal/push_message_helper.js +5 -2
- package/dist/models/internal/push_message_helper.js.map +1 -1
- package/dist/models/metadata.d.ts +2 -1
- package/dist/models/metadata.d.ts.map +1 -1
- package/dist/models/metadata.js +5 -0
- package/dist/models/metadata.js.map +1 -1
- package/dist/models/page.d.ts.map +1 -1
- package/dist/models/page.js +3 -1
- package/dist/models/page.js.map +1 -1
- package/dist/models/plugin.d.ts +2 -2
- package/dist/models/plugin.d.ts.map +1 -1
- package/dist/models/plugin.js +2 -2
- package/dist/models/plugin.js.map +1 -1
- package/dist/models/table.d.ts +8 -0
- package/dist/models/table.d.ts.map +1 -1
- package/dist/models/table.js +196 -83
- package/dist/models/table.js.map +1 -1
- package/dist/models/trigger.d.ts.map +1 -1
- package/dist/models/trigger.js +20 -9
- package/dist/models/trigger.js.map +1 -1
- package/dist/models/user.d.ts.map +1 -1
- package/dist/models/user.js +4 -0
- package/dist/models/user.js.map +1 -1
- package/dist/models/workflow.d.ts.map +1 -1
- package/dist/models/workflow.js +6 -0
- package/dist/models/workflow.js.map +1 -1
- package/dist/plugin-helper.d.ts.map +1 -1
- package/dist/plugin-helper.js +4 -0
- package/dist/plugin-helper.js.map +1 -1
- package/dist/viewable_fields.d.ts +2 -2
- package/dist/viewable_fields.d.ts.map +1 -1
- package/dist/viewable_fields.js +13 -8
- package/dist/viewable_fields.js.map +1 -1
- package/package.json +8 -8
- package/webpack.config.js +1 -0
- package/dist/tests/actions.test.d.ts +0 -2
- package/dist/tests/actions.test.d.ts.map +0 -1
- package/dist/tests/actions.test.js +0 -936
- package/dist/tests/actions.test.js.map +0 -1
- package/dist/tests/auth.test.d.ts +0 -2
- package/dist/tests/auth.test.d.ts.map +0 -1
- package/dist/tests/auth.test.js +0 -824
- package/dist/tests/auth.test.js.map +0 -1
- package/dist/tests/auxtest.test.d.ts +0 -2
- package/dist/tests/auxtest.test.d.ts.map +0 -1
- package/dist/tests/auxtest.test.js +0 -562
- package/dist/tests/auxtest.test.js.map +0 -1
- package/dist/tests/base.test.d.ts +0 -2
- package/dist/tests/base.test.d.ts.map +0 -1
- package/dist/tests/base.test.js +0 -30
- package/dist/tests/base.test.js.map +0 -1
- package/dist/tests/calc.test.d.ts +0 -2
- package/dist/tests/calc.test.d.ts.map +0 -1
- package/dist/tests/calc.test.js +0 -1081
- package/dist/tests/calc.test.js.map +0 -1
- package/dist/tests/composite_pk.test.d.ts +0 -2
- package/dist/tests/composite_pk.test.d.ts.map +0 -1
- package/dist/tests/composite_pk.test.js +0 -98
- package/dist/tests/composite_pk.test.js.map +0 -1
- package/dist/tests/config.test.d.ts +0 -2
- package/dist/tests/config.test.d.ts.map +0 -1
- package/dist/tests/config.test.js +0 -86
- package/dist/tests/config.test.js.map +0 -1
- package/dist/tests/db.test.d.ts +0 -2
- package/dist/tests/db.test.d.ts.map +0 -1
- package/dist/tests/db.test.js +0 -178
- package/dist/tests/db.test.js.map +0 -1
- package/dist/tests/discover.test.d.ts +0 -2
- package/dist/tests/discover.test.d.ts.map +0 -1
- package/dist/tests/discover.test.js +0 -245
- package/dist/tests/discover.test.js.map +0 -1
- package/dist/tests/edit.test.d.ts +0 -2
- package/dist/tests/edit.test.d.ts.map +0 -1
- package/dist/tests/edit.test.js +0 -1161
- package/dist/tests/edit.test.js.map +0 -1
- package/dist/tests/email.test.d.ts +0 -2
- package/dist/tests/email.test.d.ts.map +0 -1
- package/dist/tests/email.test.js +0 -255
- package/dist/tests/email.test.js.map +0 -1
- package/dist/tests/exact_views.test.d.ts +0 -2
- package/dist/tests/exact_views.test.d.ts.map +0 -1
- package/dist/tests/exact_views.test.js +0 -1363
- package/dist/tests/exact_views.test.js.map +0 -1
- package/dist/tests/field.test.d.ts +0 -2
- package/dist/tests/field.test.d.ts.map +0 -1
- package/dist/tests/field.test.js +0 -588
- package/dist/tests/field.test.js.map +0 -1
- package/dist/tests/fieldviews.test.d.ts +0 -2
- package/dist/tests/fieldviews.test.d.ts.map +0 -1
- package/dist/tests/fieldviews.test.js +0 -74
- package/dist/tests/fieldviews.test.js.map +0 -1
- package/dist/tests/file.test.d.ts +0 -2
- package/dist/tests/file.test.d.ts.map +0 -1
- package/dist/tests/file.test.js +0 -148
- package/dist/tests/file.test.js.map +0 -1
- package/dist/tests/filter.test.d.ts +0 -2
- package/dist/tests/filter.test.d.ts.map +0 -1
- package/dist/tests/filter.test.js +0 -496
- package/dist/tests/filter.test.js.map +0 -1
- package/dist/tests/form.test.d.ts +0 -2
- package/dist/tests/form.test.d.ts.map +0 -1
- package/dist/tests/form.test.js +0 -264
- package/dist/tests/form.test.js.map +0 -1
- package/dist/tests/list.test.d.ts +0 -2
- package/dist/tests/list.test.d.ts.map +0 -1
- package/dist/tests/list.test.js +0 -1037
- package/dist/tests/list.test.js.map +0 -1
- package/dist/tests/models.test.d.ts +0 -2
- package/dist/tests/models.test.d.ts.map +0 -1
- package/dist/tests/models.test.js +0 -417
- package/dist/tests/models.test.js.map +0 -1
- package/dist/tests/page.test.d.ts +0 -2
- package/dist/tests/page.test.d.ts.map +0 -1
- package/dist/tests/page.test.js +0 -26
- package/dist/tests/page.test.js.map +0 -1
- package/dist/tests/page_group.test.d.ts +0 -2
- package/dist/tests/page_group.test.d.ts.map +0 -1
- package/dist/tests/page_group.test.js +0 -51
- package/dist/tests/page_group.test.js.map +0 -1
- package/dist/tests/plugin.test.d.ts +0 -2
- package/dist/tests/plugin.test.d.ts.map +0 -1
- package/dist/tests/plugin.test.js +0 -60
- package/dist/tests/plugin.test.js.map +0 -1
- package/dist/tests/show.test.d.ts +0 -2
- package/dist/tests/show.test.d.ts.map +0 -1
- package/dist/tests/show.test.js +0 -561
- package/dist/tests/show.test.js.map +0 -1
- package/dist/tests/state.test.d.ts +0 -2
- package/dist/tests/state.test.d.ts.map +0 -1
- package/dist/tests/state.test.js +0 -82
- package/dist/tests/state.test.js.map +0 -1
- package/dist/tests/table.test.d.ts +0 -2
- package/dist/tests/table.test.d.ts.map +0 -1
- package/dist/tests/table.test.js +0 -2717
- package/dist/tests/table.test.js.map +0 -1
- package/dist/tests/table_history.test.d.ts +0 -2
- package/dist/tests/table_history.test.d.ts.map +0 -1
- package/dist/tests/table_history.test.js +0 -413
- package/dist/tests/table_history.test.js.map +0 -1
- package/dist/tests/tag.test.d.ts +0 -2
- package/dist/tests/tag.test.d.ts.map +0 -1
- package/dist/tests/tag.test.js +0 -97
- package/dist/tests/tag.test.js.map +0 -1
- package/dist/tests/user.test.d.ts +0 -2
- package/dist/tests/user.test.d.ts.map +0 -1
- package/dist/tests/user.test.js +0 -441
- package/dist/tests/user.test.js.map +0 -1
- package/dist/tests/view.test.d.ts +0 -2
- package/dist/tests/view.test.d.ts.map +0 -1
- package/dist/tests/view.test.js +0 -699
- package/dist/tests/view.test.js.map +0 -1
- package/dist/tests/workflow.test.d.ts +0 -2
- package/dist/tests/workflow.test.d.ts.map +0 -1
- package/dist/tests/workflow.test.js +0 -303
- package/dist/tests/workflow.test.js.map +0 -1
- package/dist/tests/workflow_run.test.d.ts +0 -2
- package/dist/tests/workflow_run.test.d.ts.map +0 -1
- package/dist/tests/workflow_run.test.js +0 -922
- package/dist/tests/workflow_run.test.js.map +0 -1
|
@@ -1,936 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const trigger_1 = __importDefault(require("../models/trigger"));
|
|
40
|
-
const table_1 = __importDefault(require("../models/table"));
|
|
41
|
-
const field_1 = __importDefault(require("../models/field"));
|
|
42
|
-
const user_1 = __importDefault(require("../models/user"));
|
|
43
|
-
const eventlog_1 = __importDefault(require("../models/eventlog"));
|
|
44
|
-
const scheduler_1 = __importDefault(require("../models/scheduler"));
|
|
45
|
-
const { runScheduler } = scheduler_1.default;
|
|
46
|
-
const db_1 = __importDefault(require("../db"));
|
|
47
|
-
const { getState } = require("../db/state");
|
|
48
|
-
const mocks_1 = __importDefault(require("../tests/mocks"));
|
|
49
|
-
const { plugin_with_routes, getActionCounter, resetActionCounter, mockReqRes, sleep, } = mocks_1.default;
|
|
50
|
-
const assertions_1 = require("../tests/assertions");
|
|
51
|
-
const globals_1 = require("@jest/globals");
|
|
52
|
-
const actions_1 = __importStar(require("../base-plugin/actions"));
|
|
53
|
-
const { duplicate_row, insert_any_row, insert_joined_row, modify_row, delete_rows, } = actions_1.default;
|
|
54
|
-
const utils_1 = __importDefault(require("../utils"));
|
|
55
|
-
const notification_1 = __importDefault(require("../models/notification"));
|
|
56
|
-
const plugin_helper_1 = require("../plugin-helper");
|
|
57
|
-
const { applyAsync, mergeActionResults } = utils_1.default;
|
|
58
|
-
(0, globals_1.afterAll)(db_1.default.close);
|
|
59
|
-
(0, globals_1.beforeAll)(async () => {
|
|
60
|
-
await require("../db/reset_schema")();
|
|
61
|
-
await require("../db/fixtures")();
|
|
62
|
-
});
|
|
63
|
-
jest.setTimeout(20000);
|
|
64
|
-
(0, globals_1.describe)("Action and Trigger model", () => {
|
|
65
|
-
(0, globals_1.it)("should add insert trigger", async () => {
|
|
66
|
-
getState().registerPlugin("mock_plugin", plugin_with_routes());
|
|
67
|
-
resetActionCounter();
|
|
68
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
69
|
-
const table = table_1.default.findOne({ name: "patients" });
|
|
70
|
-
(0, assertions_1.assertIsSet)(table);
|
|
71
|
-
const trigger = await trigger_1.default.create({
|
|
72
|
-
action: "incrementCounter",
|
|
73
|
-
table_id: table.id,
|
|
74
|
-
when_trigger: "Insert",
|
|
75
|
-
name: "incCount",
|
|
76
|
-
});
|
|
77
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
78
|
-
await table.insertRow({ name: "Don Fabrizio" });
|
|
79
|
-
await sleep(10);
|
|
80
|
-
(0, globals_1.expect)(getActionCounter()).toBe(1);
|
|
81
|
-
const trigger1 = await trigger_1.default.findOne({ id: trigger.id });
|
|
82
|
-
(0, globals_1.expect)(!!trigger1).toBe(true);
|
|
83
|
-
(0, globals_1.expect)(trigger1.id).toBe(trigger.id);
|
|
84
|
-
(0, globals_1.expect)(trigger1.toJson).toStrictEqual({
|
|
85
|
-
action: "incrementCounter",
|
|
86
|
-
channel: null,
|
|
87
|
-
configuration: {},
|
|
88
|
-
description: null,
|
|
89
|
-
min_role: 100,
|
|
90
|
-
name: "incCount",
|
|
91
|
-
table_name: "patients",
|
|
92
|
-
when_trigger: "Insert",
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
(0, globals_1.it)("should clone trigger", async () => {
|
|
96
|
-
const trig = await trigger_1.default.findOne({ name: "incCount" });
|
|
97
|
-
(0, assertions_1.assertIsSet)(trig);
|
|
98
|
-
await trig.clone();
|
|
99
|
-
await trig.clone();
|
|
100
|
-
const trig1 = await trigger_1.default.findOne({ name: "incCount-copy" });
|
|
101
|
-
(0, assertions_1.assertIsSet)(trig1);
|
|
102
|
-
const trig2 = await trigger_1.default.findOne({ name: "incCount-copy-1" });
|
|
103
|
-
(0, assertions_1.assertIsSet)(trig2);
|
|
104
|
-
});
|
|
105
|
-
(0, globals_1.it)("should add update trigger", async () => {
|
|
106
|
-
(0, globals_1.expect)(getActionCounter()).toBe(1);
|
|
107
|
-
const table = table_1.default.findOne({ name: "patients" });
|
|
108
|
-
(0, assertions_1.assertIsSet)(table);
|
|
109
|
-
await trigger_1.default.create({
|
|
110
|
-
action: "setCounter",
|
|
111
|
-
table_id: table.id,
|
|
112
|
-
when_trigger: "Update",
|
|
113
|
-
configuration: { number: 17 },
|
|
114
|
-
});
|
|
115
|
-
(0, globals_1.expect)(getActionCounter()).toBe(1);
|
|
116
|
-
const don = await table.getRow({ name: "Don Fabrizio" });
|
|
117
|
-
(0, assertions_1.assertIsSet)(don);
|
|
118
|
-
await table.updateRow({ name: "Don Fabrizio II" }, don.id);
|
|
119
|
-
(0, globals_1.expect)(getActionCounter()).toBe(17);
|
|
120
|
-
});
|
|
121
|
-
(0, globals_1.it)("should add update trigger", async () => {
|
|
122
|
-
(0, globals_1.expect)(getActionCounter()).toBe(17);
|
|
123
|
-
const table = table_1.default.findOne({ name: "patients" });
|
|
124
|
-
(0, assertions_1.assertIsSet)(table);
|
|
125
|
-
await trigger_1.default.create({
|
|
126
|
-
action: "setCounter",
|
|
127
|
-
table_id: table.id,
|
|
128
|
-
when_trigger: "Delete",
|
|
129
|
-
configuration: { number: 37 },
|
|
130
|
-
});
|
|
131
|
-
(0, globals_1.expect)(getActionCounter()).toBe(17);
|
|
132
|
-
await table.deleteRows({ name: "Don Fabrizio" });
|
|
133
|
-
(0, globals_1.expect)(getActionCounter()).toBe(17);
|
|
134
|
-
await table.deleteRows({ name: "Don Fabrizio II" });
|
|
135
|
-
(0, globals_1.expect)(getActionCounter()).toBe(37);
|
|
136
|
-
});
|
|
137
|
-
(0, globals_1.it)("should run js code", async () => {
|
|
138
|
-
const table = table_1.default.findOne({ name: "books" });
|
|
139
|
-
(0, assertions_1.assertIsSet)(table);
|
|
140
|
-
await trigger_1.default.create({
|
|
141
|
-
action: "run_js_code",
|
|
142
|
-
table_id: table.id,
|
|
143
|
-
when_trigger: "Insert",
|
|
144
|
-
configuration: {
|
|
145
|
-
code: `
|
|
146
|
-
const table = Table.findOne({ name: "patients" });
|
|
147
|
-
await table.insertRow({ name: "TriggeredInsert" });
|
|
148
|
-
`,
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
await table.insertRow({ author: "Giuseppe Tomasi", pages: 209 });
|
|
152
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
153
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
154
|
-
await sleep(10);
|
|
155
|
-
const rows = await patients.getRows({ name: "TriggeredInsert" });
|
|
156
|
-
(0, globals_1.expect)(rows.length).toBe(1);
|
|
157
|
-
});
|
|
158
|
-
(0, globals_1.it)("should run webhook", async () => {
|
|
159
|
-
const table = table_1.default.findOne({ name: "books" });
|
|
160
|
-
(0, assertions_1.assertIsSet)(table);
|
|
161
|
-
await trigger_1.default.create({
|
|
162
|
-
action: "webhook",
|
|
163
|
-
table_id: table.id,
|
|
164
|
-
when_trigger: "Update",
|
|
165
|
-
configuration: {
|
|
166
|
-
// from https://requestbin.com/
|
|
167
|
-
// to inspect https://pipedream.com/sources/dc_jku44wk
|
|
168
|
-
url: "https://b6af540a71dce96ec130de5a0c47ada6.m.pipedream.net",
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
const row = await table.getRow({ author: "Giuseppe Tomasi" });
|
|
172
|
-
(0, assertions_1.assertIsSet)(row);
|
|
173
|
-
await table.updateRow({ pages: 210 }, row.id);
|
|
174
|
-
});
|
|
175
|
-
(0, globals_1.it)("should list triggers", async () => {
|
|
176
|
-
//const table = Table.findOne({ name: "books" });
|
|
177
|
-
const triggers = await trigger_1.default.findAllWithTableName();
|
|
178
|
-
const trigger = triggers.find((tr) => tr && tr.table_name === "books" && tr.when_trigger === "Update");
|
|
179
|
-
(0, assertions_1.assertIsSet)(trigger);
|
|
180
|
-
(0, globals_1.expect)(trigger.action).toBe("webhook");
|
|
181
|
-
});
|
|
182
|
-
(0, globals_1.it)("should have options", async () => {
|
|
183
|
-
(0, globals_1.expect)(trigger_1.default.when_options).toContain("Insert");
|
|
184
|
-
});
|
|
185
|
-
(0, globals_1.it)("should get triggers", async () => {
|
|
186
|
-
const table = table_1.default.findOne({ name: "books" });
|
|
187
|
-
(0, assertions_1.assertIsSet)(table);
|
|
188
|
-
const trigger = await trigger_1.default.findOne({
|
|
189
|
-
table_id: table.id,
|
|
190
|
-
when_trigger: "Update",
|
|
191
|
-
});
|
|
192
|
-
(0, globals_1.expect)(trigger.action).toBe("webhook");
|
|
193
|
-
await trigger_1.default.update(trigger.id, { when_trigger: "Insert" });
|
|
194
|
-
const ins_trigger = trigger_1.default.find({
|
|
195
|
-
table_id: table.id,
|
|
196
|
-
when_trigger: "Insert",
|
|
197
|
-
});
|
|
198
|
-
(0, globals_1.expect)(ins_trigger.length).toBe(2);
|
|
199
|
-
await trigger.delete();
|
|
200
|
-
const ins_trigger1 = trigger_1.default.find({
|
|
201
|
-
table_id: table.id,
|
|
202
|
-
when_trigger: "Insert",
|
|
203
|
-
});
|
|
204
|
-
(0, globals_1.expect)(ins_trigger1.length).toBe(1);
|
|
205
|
-
});
|
|
206
|
-
(0, globals_1.it)("should run webhook on insert", async () => {
|
|
207
|
-
const table = table_1.default.findOne({ name: "books" });
|
|
208
|
-
(0, assertions_1.assertIsSet)(table);
|
|
209
|
-
await trigger_1.default.create({
|
|
210
|
-
action: "webhook",
|
|
211
|
-
table_id: table.id,
|
|
212
|
-
when_trigger: "Insert",
|
|
213
|
-
configuration: {
|
|
214
|
-
// from https://requestbin.com/
|
|
215
|
-
// to inspect https://pipedream.com/sources/dc_jku44wk
|
|
216
|
-
url: "https://b6af540a71dce96ec130de5a0c47ada6.m.pipedream.net",
|
|
217
|
-
body: "{foo: author}",
|
|
218
|
-
response_field: "author",
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
const id = await table.insertRow({ author: "NK Jemisin", pages: 901 }, undefined, {});
|
|
222
|
-
const row = await table.getRow({ id });
|
|
223
|
-
(0, globals_1.expect)(['{"success":true}', "Error in workflow"]).toContain(row?.author);
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
(0, globals_1.describe)("base plugin actions", () => {
|
|
227
|
-
(0, globals_1.it)("should insert_any_row", async () => {
|
|
228
|
-
const action = insert_any_row;
|
|
229
|
-
const result = await action.run({
|
|
230
|
-
row: { x: 3, y: 7 },
|
|
231
|
-
configuration: { table: "patients", row_expr: '{name:"Simon1"}' },
|
|
232
|
-
user: { id: 1, role_id: 1 },
|
|
233
|
-
});
|
|
234
|
-
(0, globals_1.expect)(result).toStrictEqual({});
|
|
235
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
236
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
237
|
-
const rows = await patients.getRows({ name: "Simon1" });
|
|
238
|
-
(0, globals_1.expect)(rows.length).toBe(1);
|
|
239
|
-
});
|
|
240
|
-
(0, globals_1.it)("should insert_any_row and return id", async () => {
|
|
241
|
-
const action = insert_any_row;
|
|
242
|
-
const result = await action.run({
|
|
243
|
-
row: { x: 3, y: 7 },
|
|
244
|
-
configuration: {
|
|
245
|
-
table: "patients",
|
|
246
|
-
row_expr: '{name:"Simon9"}',
|
|
247
|
-
id_variable: "myid",
|
|
248
|
-
},
|
|
249
|
-
user: { id: 1, role_id: 1 },
|
|
250
|
-
});
|
|
251
|
-
(0, assertions_1.assertIsRow)(result);
|
|
252
|
-
(0, globals_1.expect)(typeof result.myid).toBe("number");
|
|
253
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
254
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
255
|
-
const rows = await patients.getRows({ name: "Simon9" });
|
|
256
|
-
(0, globals_1.expect)(rows.length).toBe(1);
|
|
257
|
-
});
|
|
258
|
-
(0, globals_1.it)("insert_any_row should upsert", async () => {
|
|
259
|
-
const exrow = await table_1.default.findOne("patients")?.getRow({ name: "Simon9" });
|
|
260
|
-
const id = exrow?.id;
|
|
261
|
-
const action = insert_any_row;
|
|
262
|
-
const result = await action.run({
|
|
263
|
-
row: { x: 3, y: 7 },
|
|
264
|
-
configuration: {
|
|
265
|
-
table: "patients",
|
|
266
|
-
row_expr: `{name:"Simon99", id:${id}}`,
|
|
267
|
-
id_variable: "myid",
|
|
268
|
-
},
|
|
269
|
-
user: { id: 1, role_id: 1 },
|
|
270
|
-
});
|
|
271
|
-
(0, globals_1.expect)(result).toStrictEqual({ myid: id });
|
|
272
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
273
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
274
|
-
const rows = await patients.getRows({ name: "Simon99" });
|
|
275
|
-
(0, globals_1.expect)(rows.length).toBe(1);
|
|
276
|
-
(0, globals_1.expect)(rows[0].id).toBe(id);
|
|
277
|
-
const rows1 = await patients.getRows({ name: "Simon9" });
|
|
278
|
-
(0, globals_1.expect)(rows1.length).toBe(0);
|
|
279
|
-
});
|
|
280
|
-
(0, globals_1.it)("should insert_any_row on arrays", async () => {
|
|
281
|
-
const action = insert_any_row;
|
|
282
|
-
const result = await action.run({
|
|
283
|
-
row: { x: 3, y: 7 },
|
|
284
|
-
configuration: {
|
|
285
|
-
table: "patients",
|
|
286
|
-
row_expr: '[{name:"Simon2"}, {name:"Simon2"}]',
|
|
287
|
-
},
|
|
288
|
-
user: { id: 1, role_id: 1 },
|
|
289
|
-
});
|
|
290
|
-
(0, globals_1.expect)(result).toStrictEqual({});
|
|
291
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
292
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
293
|
-
const rows = await patients.getRows({ name: "Simon2" });
|
|
294
|
-
(0, globals_1.expect)(rows.length).toBe(2);
|
|
295
|
-
});
|
|
296
|
-
(0, globals_1.it)("should insert_any_row on arrays and return ids", async () => {
|
|
297
|
-
const action = insert_any_row;
|
|
298
|
-
const result = await action.run({
|
|
299
|
-
row: { x: 3, y: 7 },
|
|
300
|
-
configuration: {
|
|
301
|
-
table: "patients",
|
|
302
|
-
row_expr: '[{name:"Simon10"}, {name:"Simon11"}]',
|
|
303
|
-
id_variable: "myids",
|
|
304
|
-
},
|
|
305
|
-
user: { id: 1, role_id: 1 },
|
|
306
|
-
});
|
|
307
|
-
(0, assertions_1.assertIsRow)(result);
|
|
308
|
-
(0, globals_1.expect)(result.myids.length).toBe(2);
|
|
309
|
-
(0, globals_1.expect)(typeof result.myids[0]).toBe("number");
|
|
310
|
-
(0, globals_1.expect)(result.myids[0]).toBeGreaterThan(2);
|
|
311
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
312
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
313
|
-
const rows = await patients.getRows({ name: "Simon2" });
|
|
314
|
-
(0, globals_1.expect)(rows.length).toBe(2);
|
|
315
|
-
});
|
|
316
|
-
(0, globals_1.it)("should insert_any_row with field", async () => {
|
|
317
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
318
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
319
|
-
const books = table_1.default.findOne({ name: "books" });
|
|
320
|
-
(0, assertions_1.assertIsSet)(books);
|
|
321
|
-
const action = insert_any_row;
|
|
322
|
-
const result = await action.run({
|
|
323
|
-
row: { pages: 3, author: "Joe" },
|
|
324
|
-
table: books,
|
|
325
|
-
configuration: {
|
|
326
|
-
table: "patients",
|
|
327
|
-
row_expr: '{name:"Si"+row.pages+"mon"+author}',
|
|
328
|
-
},
|
|
329
|
-
user: { id: 1, role_id: 1 },
|
|
330
|
-
});
|
|
331
|
-
(0, globals_1.expect)(result).toStrictEqual({});
|
|
332
|
-
await sleep(10);
|
|
333
|
-
const rows = await patients.getRows({ name: "Si3monJoe" });
|
|
334
|
-
(0, globals_1.expect)(rows.length).toBe(1);
|
|
335
|
-
});
|
|
336
|
-
(0, globals_1.it)("should modify_row", async () => {
|
|
337
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
338
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
339
|
-
const row = await patients.getRow({ name: "Simon1" });
|
|
340
|
-
(0, assertions_1.assertIsSet)(row);
|
|
341
|
-
(0, globals_1.expect)(row.favbook).toBe(null);
|
|
342
|
-
const result = await modify_row.run({
|
|
343
|
-
row,
|
|
344
|
-
table: patients,
|
|
345
|
-
configuration: { row_expr: "{favbook:1}", where: "Database" },
|
|
346
|
-
user: { id: 1, role_id: 1 },
|
|
347
|
-
});
|
|
348
|
-
(0, globals_1.expect)(result).toStrictEqual(undefined);
|
|
349
|
-
const row1 = await patients.getRow({ name: "Simon1" });
|
|
350
|
-
(0, assertions_1.assertIsSet)(row1);
|
|
351
|
-
(0, globals_1.expect)(row1.favbook).toBe(1);
|
|
352
|
-
});
|
|
353
|
-
(0, globals_1.it)("should delete_rows", async () => {
|
|
354
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
355
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
356
|
-
const id1 = await patients.insertRow({ name: "Del1" });
|
|
357
|
-
await patients.insertRow({ name: "Del2" });
|
|
358
|
-
const row = await patients.getRow({ id: id1 });
|
|
359
|
-
(0, assertions_1.assertIsSet)(row);
|
|
360
|
-
const result = await delete_rows.run({
|
|
361
|
-
row,
|
|
362
|
-
table: patients,
|
|
363
|
-
configuration: { delete_triggering_row: true },
|
|
364
|
-
user: { id: 1, role_id: 1 },
|
|
365
|
-
});
|
|
366
|
-
(0, globals_1.expect)(result).toStrictEqual({});
|
|
367
|
-
const row1 = await patients.getRow({ name: "Del1" });
|
|
368
|
-
(0, globals_1.expect)(row1).toBe(null);
|
|
369
|
-
const row1a = await patients.getRow({ name: "Del2" });
|
|
370
|
-
(0, globals_1.expect)(!!row1a).toBe(true);
|
|
371
|
-
const result1 = await delete_rows.run({
|
|
372
|
-
configuration: {
|
|
373
|
-
delete_triggering_row: false,
|
|
374
|
-
delete_where: "{name: 'Del2'}",
|
|
375
|
-
table_name: "patients",
|
|
376
|
-
},
|
|
377
|
-
user: { id: 1, role_id: 1 },
|
|
378
|
-
});
|
|
379
|
-
(0, globals_1.expect)(result1).toStrictEqual({});
|
|
380
|
-
const row2 = await patients.getRow({ name: "Del2" });
|
|
381
|
-
(0, globals_1.expect)(row2).toBe(null);
|
|
382
|
-
});
|
|
383
|
-
(0, globals_1.it)("should duplicate_row", async () => {
|
|
384
|
-
const patients = table_1.default.findOne({ name: "patients" });
|
|
385
|
-
(0, assertions_1.assertIsSet)(patients);
|
|
386
|
-
const rows = await patients.getRows({ name: "Simon1" });
|
|
387
|
-
(0, globals_1.expect)(rows.length).toBe(1);
|
|
388
|
-
const result = await duplicate_row.run({
|
|
389
|
-
row: rows[0],
|
|
390
|
-
table: patients,
|
|
391
|
-
user: { id: 1, role_id: 1 },
|
|
392
|
-
});
|
|
393
|
-
const rows1 = await patients.getRows({ name: "Simon1" });
|
|
394
|
-
(0, globals_1.expect)(rows1.length).toBe(2);
|
|
395
|
-
});
|
|
396
|
-
(0, globals_1.it)("should insert_joined_row", async () => {
|
|
397
|
-
const books = table_1.default.findOne({ name: "books" });
|
|
398
|
-
(0, assertions_1.assertIsSet)(books);
|
|
399
|
-
const book = await books.getRow({ id: 1 });
|
|
400
|
-
(0, assertions_1.assertIsSet)(book);
|
|
401
|
-
const discusses_books = table_1.default.findOne({ name: "discusses_books" });
|
|
402
|
-
(0, assertions_1.assertIsSet)(discusses_books);
|
|
403
|
-
const npats_before = await discusses_books.countRows({});
|
|
404
|
-
const result = await insert_joined_row.run({
|
|
405
|
-
table: discusses_books,
|
|
406
|
-
row: book,
|
|
407
|
-
configuration: { joined_table: `discusses_books.book` },
|
|
408
|
-
user: { id: 1, role_id: 1 },
|
|
409
|
-
});
|
|
410
|
-
const npats_after = await discusses_books.countRows({});
|
|
411
|
-
(0, globals_1.expect)(npats_after).toBe(npats_before + 1);
|
|
412
|
-
});
|
|
413
|
-
(0, globals_1.it)("should notify_user", async () => {
|
|
414
|
-
const books = table_1.default.findOne({ name: "books" });
|
|
415
|
-
(0, assertions_1.assertIsSet)(books);
|
|
416
|
-
const book = await books.getRow({ id: 1 });
|
|
417
|
-
(0, assertions_1.assertIsSet)(book);
|
|
418
|
-
await actions_1.notify_user.run({
|
|
419
|
-
row: book,
|
|
420
|
-
configuration: {
|
|
421
|
-
user_spec: "{id:1}",
|
|
422
|
-
title: "Hello",
|
|
423
|
-
body: "World",
|
|
424
|
-
link: "https://saltcorn.com",
|
|
425
|
-
},
|
|
426
|
-
user: { id: 1, role_id: 1 },
|
|
427
|
-
});
|
|
428
|
-
const notif = await notification_1.default.findOne({ title: "Hello" });
|
|
429
|
-
(0, assertions_1.assertIsSet)(notif);
|
|
430
|
-
(0, globals_1.expect)(notif.user_id).toBe(1);
|
|
431
|
-
(0, globals_1.expect)(notif.body).toBe("World");
|
|
432
|
-
});
|
|
433
|
-
(0, globals_1.it)("should have valid configFields", async () => {
|
|
434
|
-
const books = table_1.default.findOne({ name: "books" });
|
|
435
|
-
(0, assertions_1.assertIsSet)(books);
|
|
436
|
-
for (const [name, action] of Object.entries(actions_1.default)) {
|
|
437
|
-
// @ts-ignore
|
|
438
|
-
if (!action.configFields)
|
|
439
|
-
continue;
|
|
440
|
-
// @ts-ignore
|
|
441
|
-
const configFields = await applyAsync(action.configFields, {
|
|
442
|
-
table: books,
|
|
443
|
-
});
|
|
444
|
-
(0, globals_1.expect)(Array.isArray(configFields)).toBe(true);
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
//TODO recalculate_stored_fields, set_user_language
|
|
448
|
-
});
|
|
449
|
-
(0, globals_1.describe)("Events and eventlog", () => {
|
|
450
|
-
(0, globals_1.it)("should add custom event", async () => {
|
|
451
|
-
await getState().setConfig("custom_events", [
|
|
452
|
-
{
|
|
453
|
-
name: "FooHappened",
|
|
454
|
-
hasChannel: false,
|
|
455
|
-
},
|
|
456
|
-
{
|
|
457
|
-
name: "BarWasHere",
|
|
458
|
-
hasChannel: true,
|
|
459
|
-
},
|
|
460
|
-
]);
|
|
461
|
-
await getState().setConfig("event_log_settings", {
|
|
462
|
-
FooHappened: true,
|
|
463
|
-
BarWasHere: true,
|
|
464
|
-
BarWasHere_channel: "Baz,oldbooks",
|
|
465
|
-
Insert: true,
|
|
466
|
-
Insert_readings: true,
|
|
467
|
-
});
|
|
468
|
-
await getState().refresh_config();
|
|
469
|
-
});
|
|
470
|
-
(0, globals_1.it)("should emit custom event", async () => {
|
|
471
|
-
const evs = await eventlog_1.default.find({ event_type: "FooHappened" });
|
|
472
|
-
(0, globals_1.expect)(evs.length).toBe(0);
|
|
473
|
-
await trigger_1.default.emitEvent("FooHappened");
|
|
474
|
-
await sleep(200);
|
|
475
|
-
const evs1 = await eventlog_1.default.find({ event_type: "FooHappened" });
|
|
476
|
-
(0, globals_1.expect)(evs1.length).toBe(1);
|
|
477
|
-
});
|
|
478
|
-
(0, globals_1.it)("should find with user", async () => {
|
|
479
|
-
const ev = await eventlog_1.default.findOne({ event_type: "FooHappened" });
|
|
480
|
-
(0, assertions_1.assertIsSet)(ev.id);
|
|
481
|
-
const evlog_w_user = await eventlog_1.default.findOneWithUser(ev.id);
|
|
482
|
-
(0, globals_1.expect)(evlog_w_user?.event_type).toBe("FooHappened");
|
|
483
|
-
});
|
|
484
|
-
(0, globals_1.it)("should emit custom event with channel", async () => {
|
|
485
|
-
const evs = await eventlog_1.default.find({ event_type: "BarWasHere" });
|
|
486
|
-
(0, globals_1.expect)(evs.length).toBe(0);
|
|
487
|
-
await trigger_1.default.emitEvent("BarWasHere");
|
|
488
|
-
await trigger_1.default.emitEvent("BarWasHere", "Zap");
|
|
489
|
-
await trigger_1.default.emitEvent("BarWasHere", "Baz");
|
|
490
|
-
await sleep(100);
|
|
491
|
-
const evs1 = await eventlog_1.default.find({ event_type: "BarWasHere" });
|
|
492
|
-
(0, globals_1.expect)(evs1.length).toBe(1);
|
|
493
|
-
});
|
|
494
|
-
(0, globals_1.it)("should emit custom event with array payload", async () => {
|
|
495
|
-
const evs = await eventlog_1.default.find({ event_type: "BarWasHere" });
|
|
496
|
-
trigger_1.default.emitEvent("BarWasHere", "Baz", {}, [{ x: 1 }, { x: 2 }]);
|
|
497
|
-
await sleep(200);
|
|
498
|
-
const evs1 = await eventlog_1.default.find({ event_type: "BarWasHere" }, { orderBy: "id" });
|
|
499
|
-
(0, globals_1.expect)(evs1.length).toBe(evs.length + 1);
|
|
500
|
-
(0, globals_1.expect)(Array.isArray(evs1[evs1.length - 1].payload)).toBe(true);
|
|
501
|
-
});
|
|
502
|
-
(0, globals_1.it)("should emit custom event with object payload", async () => {
|
|
503
|
-
const evs = await eventlog_1.default.find({ event_type: "BarWasHere" });
|
|
504
|
-
trigger_1.default.emitEvent("BarWasHere", "Baz", {}, { x: 1 });
|
|
505
|
-
await sleep(200);
|
|
506
|
-
const evs1 = await eventlog_1.default.find({ event_type: "BarWasHere" }, { orderBy: "id" });
|
|
507
|
-
(0, globals_1.expect)(evs1.length).toBe(evs.length + 1);
|
|
508
|
-
(0, globals_1.expect)(evs1[evs1.length - 1].payload.x).toBe(1);
|
|
509
|
-
});
|
|
510
|
-
(0, globals_1.it)("should emit custom event with string payload", async () => {
|
|
511
|
-
const evs = await eventlog_1.default.find({ event_type: "BarWasHere" });
|
|
512
|
-
trigger_1.default.emitEvent("BarWasHere", "Baz", {}, "Hello!");
|
|
513
|
-
await sleep(200);
|
|
514
|
-
const evs1 = await eventlog_1.default.find({ event_type: "BarWasHere" }, { orderBy: "id" });
|
|
515
|
-
(0, globals_1.expect)(evs1.length).toBe(evs.length + 1);
|
|
516
|
-
(0, globals_1.expect)(evs1[evs1.length - 1].payload).toBe("Hello!");
|
|
517
|
-
});
|
|
518
|
-
(0, globals_1.it)("should emit custom event with null payload", async () => {
|
|
519
|
-
const evs = await eventlog_1.default.find({ event_type: "BarWasHere" });
|
|
520
|
-
trigger_1.default.emitEvent("BarWasHere", "Baz", {}, null);
|
|
521
|
-
await sleep(200);
|
|
522
|
-
const evs1 = await eventlog_1.default.find({ event_type: "BarWasHere" }, { orderBy: "id" });
|
|
523
|
-
(0, globals_1.expect)(evs1.length).toBe(evs.length + 1);
|
|
524
|
-
(0, globals_1.expect)(evs1[evs1.length - 1].payload).toBe(null);
|
|
525
|
-
});
|
|
526
|
-
(0, globals_1.it)("should emit custom event with bool payload", async () => {
|
|
527
|
-
const evs = await eventlog_1.default.find({ event_type: "BarWasHere" });
|
|
528
|
-
trigger_1.default.emitEvent("BarWasHere", "Baz", {}, true);
|
|
529
|
-
await sleep(200);
|
|
530
|
-
const evs1 = await eventlog_1.default.find({ event_type: "BarWasHere" }, { orderBy: "id" });
|
|
531
|
-
(0, globals_1.expect)(evs1.length).toBe(evs.length + 1);
|
|
532
|
-
(0, globals_1.expect)(evs1[evs1.length - 1].payload).toBe(true);
|
|
533
|
-
});
|
|
534
|
-
(0, globals_1.it)("should emit table event", async () => {
|
|
535
|
-
await trigger_1.default.emitEvent("Insert", "readings");
|
|
536
|
-
const evs = await eventlog_1.default.find({ event_type: "Insert" });
|
|
537
|
-
(0, globals_1.expect)(evs.length).toBe(0);
|
|
538
|
-
await sleep(100);
|
|
539
|
-
const evs1 = await eventlog_1.default.find({ event_type: "Insert" });
|
|
540
|
-
(0, globals_1.expect)(evs1.length).toBe(1);
|
|
541
|
-
});
|
|
542
|
-
(0, globals_1.it)("should run emit_event action", async () => {
|
|
543
|
-
const books = table_1.default.findOne({ name: "books" });
|
|
544
|
-
(0, assertions_1.assertIsSet)(books);
|
|
545
|
-
const book = await books.getRow({ id: 1 });
|
|
546
|
-
(0, assertions_1.assertIsSet)(book);
|
|
547
|
-
const r = await actions_1.emit_event.run({
|
|
548
|
-
row: book,
|
|
549
|
-
configuration: {
|
|
550
|
-
eventType: "BarWasHere",
|
|
551
|
-
channel: "oldbooks",
|
|
552
|
-
},
|
|
553
|
-
user: { id: 1, role_id: 1 },
|
|
554
|
-
});
|
|
555
|
-
await sleep(100);
|
|
556
|
-
const ev = await eventlog_1.default.findOne({
|
|
557
|
-
event_type: "BarWasHere",
|
|
558
|
-
channel: "oldbooks",
|
|
559
|
-
});
|
|
560
|
-
(0, assertions_1.assertIsSet)(ev);
|
|
561
|
-
(0, globals_1.expect)(ev.payload.pages).toBe(967);
|
|
562
|
-
});
|
|
563
|
-
});
|
|
564
|
-
(0, globals_1.describe)("Scheduler", () => {
|
|
565
|
-
(0, globals_1.it)("should run and tick", async () => {
|
|
566
|
-
getState().registerPlugin("mock_plugin", plugin_with_routes());
|
|
567
|
-
resetActionCounter();
|
|
568
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
569
|
-
await trigger_1.default.create({
|
|
570
|
-
action: "incrementCounter",
|
|
571
|
-
when_trigger: "Often",
|
|
572
|
-
});
|
|
573
|
-
let stopSched = false;
|
|
574
|
-
runScheduler({
|
|
575
|
-
stop_when: () => stopSched,
|
|
576
|
-
tickSeconds: 1,
|
|
577
|
-
watchReaper: undefined,
|
|
578
|
-
port: undefined,
|
|
579
|
-
disableScheduler: undefined,
|
|
580
|
-
});
|
|
581
|
-
await sleep(500);
|
|
582
|
-
(0, globals_1.expect)(getActionCounter()).toBe(1);
|
|
583
|
-
await sleep(1200);
|
|
584
|
-
(0, globals_1.expect)(getActionCounter() > 1).toBe(true);
|
|
585
|
-
stopSched = true;
|
|
586
|
-
await sleep(1200);
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
(0, globals_1.describe)("Validate action", () => {
|
|
590
|
-
(0, globals_1.it)("it should setup", async () => {
|
|
591
|
-
const persons = await table_1.default.create("ValidatedTable");
|
|
592
|
-
await field_1.default.create({
|
|
593
|
-
table: persons,
|
|
594
|
-
name: "name",
|
|
595
|
-
type: "String",
|
|
596
|
-
});
|
|
597
|
-
await field_1.default.create({
|
|
598
|
-
table: persons,
|
|
599
|
-
name: "age",
|
|
600
|
-
type: "Integer",
|
|
601
|
-
});
|
|
602
|
-
await trigger_1.default.create({
|
|
603
|
-
action: "run_js_code",
|
|
604
|
-
table_id: persons.id,
|
|
605
|
-
when_trigger: "Validate",
|
|
606
|
-
configuration: {
|
|
607
|
-
code: `
|
|
608
|
-
if(age && age<16) return {error: "Must be 16+ to qualify"}
|
|
609
|
-
if(!row.name) return {set_fields: {name: "PersonAged"+age}}
|
|
610
|
-
`,
|
|
611
|
-
},
|
|
612
|
-
});
|
|
613
|
-
});
|
|
614
|
-
(0, globals_1.it)("it should insert valid rows", async () => {
|
|
615
|
-
const table = table_1.default.findOne({ name: "ValidatedTable" });
|
|
616
|
-
(0, assertions_1.assertIsSet)(table);
|
|
617
|
-
await table.insertRow({ name: "Mike", age: 19 });
|
|
618
|
-
const row = await table.getRow({ name: "Mike" });
|
|
619
|
-
(0, assertions_1.assertIsSet)(row);
|
|
620
|
-
(0, globals_1.expect)(row.age).toBe(19);
|
|
621
|
-
});
|
|
622
|
-
(0, globals_1.it)("it should not insert invalid rows", async () => {
|
|
623
|
-
const table = table_1.default.findOne({ name: "ValidatedTable" });
|
|
624
|
-
(0, assertions_1.assertIsSet)(table);
|
|
625
|
-
await table.insertRow({ name: "Fred", age: 14 });
|
|
626
|
-
const row = await table.getRow({ name: "Fred" });
|
|
627
|
-
(0, globals_1.expect)(row).toBe(null);
|
|
628
|
-
});
|
|
629
|
-
(0, globals_1.it)("it should set fields", async () => {
|
|
630
|
-
const table = table_1.default.findOne({ name: "ValidatedTable" });
|
|
631
|
-
(0, assertions_1.assertIsSet)(table);
|
|
632
|
-
await table.insertRow({ age: 25 });
|
|
633
|
-
const row = await table.getRow({ age: 25 });
|
|
634
|
-
(0, assertions_1.assertIsSet)(row);
|
|
635
|
-
(0, globals_1.expect)(row.name).toBe("PersonAged25");
|
|
636
|
-
});
|
|
637
|
-
(0, globals_1.it)("it should not update to invalid row", async () => {
|
|
638
|
-
const table = table_1.default.findOne({ name: "ValidatedTable" });
|
|
639
|
-
(0, assertions_1.assertIsSet)(table);
|
|
640
|
-
const row = await table.getRow({ name: "Mike" });
|
|
641
|
-
(0, assertions_1.assertIsSet)(row);
|
|
642
|
-
const upres = await table.updateRow({ name: "Mike", age: 12 }, row.id);
|
|
643
|
-
(0, globals_1.expect)(upres).toBe("Must be 16+ to qualify");
|
|
644
|
-
const row1 = await table.getRow({ id: row.id });
|
|
645
|
-
(0, assertions_1.assertIsSet)(row1);
|
|
646
|
-
(0, globals_1.expect)(row1.age).toBe(19);
|
|
647
|
-
(0, globals_1.expect)(row1.name).toBe("Mike");
|
|
648
|
-
});
|
|
649
|
-
(0, globals_1.it)("it should update to valid row", async () => {
|
|
650
|
-
const table = table_1.default.findOne({ name: "ValidatedTable" });
|
|
651
|
-
(0, assertions_1.assertIsSet)(table);
|
|
652
|
-
const row = await table.getRow({ name: "Mike" });
|
|
653
|
-
(0, assertions_1.assertIsSet)(row);
|
|
654
|
-
const upres = await table.updateRow({ name: "Mike", age: 29 }, row.id);
|
|
655
|
-
(0, globals_1.expect)(upres).toBe(undefined);
|
|
656
|
-
const row1 = await table.getRow({ id: row.id });
|
|
657
|
-
(0, assertions_1.assertIsSet)(row1);
|
|
658
|
-
(0, globals_1.expect)(row1.age).toBe(29);
|
|
659
|
-
(0, globals_1.expect)(row1.name).toBe("Mike");
|
|
660
|
-
});
|
|
661
|
-
(0, globals_1.it)("it should not change missing fields on update", async () => {
|
|
662
|
-
const table = table_1.default.findOne({ name: "ValidatedTable" });
|
|
663
|
-
(0, assertions_1.assertIsSet)(table);
|
|
664
|
-
const row = await table.getRow({ name: "Mike" });
|
|
665
|
-
(0, assertions_1.assertIsSet)(row);
|
|
666
|
-
const upres = await table.updateRow({ age: 31 }, row.id);
|
|
667
|
-
(0, globals_1.expect)(upres).toBe(undefined);
|
|
668
|
-
const row1 = await table.getRow({ id: row.id });
|
|
669
|
-
(0, assertions_1.assertIsSet)(row1);
|
|
670
|
-
(0, globals_1.expect)(row1.age).toBe(31);
|
|
671
|
-
(0, globals_1.expect)(row1.name).toBe("Mike");
|
|
672
|
-
});
|
|
673
|
-
});
|
|
674
|
-
(0, globals_1.describe)("Validate to create email", () => {
|
|
675
|
-
(0, globals_1.it)("it should setup field", async () => {
|
|
676
|
-
await field_1.default.create({
|
|
677
|
-
table: user_1.default.table,
|
|
678
|
-
name: "username",
|
|
679
|
-
type: "String",
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
/*it("it should not create user without email", async () => {
|
|
683
|
-
async function create_user() {
|
|
684
|
-
await User.create({
|
|
685
|
-
username: "tomn18",
|
|
686
|
-
password: "s3cr3t893",
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
expect(create_user).rejects.toThrow();
|
|
690
|
-
const u = await User.findOne({ username: "tomn18" });
|
|
691
|
-
expect(u).toBe(null);
|
|
692
|
-
}); */
|
|
693
|
-
(0, globals_1.it)("it should setup", async () => {
|
|
694
|
-
await trigger_1.default.create({
|
|
695
|
-
action: "run_js_code",
|
|
696
|
-
table_id: user_1.default.table.id,
|
|
697
|
-
when_trigger: "Validate",
|
|
698
|
-
configuration: {
|
|
699
|
-
code: `if(!row.email) return {set_fields: {email: row.username+"@anonymous.com"}}; else return {}`,
|
|
700
|
-
},
|
|
701
|
-
});
|
|
702
|
-
});
|
|
703
|
-
(0, globals_1.it)("it should set new user email in Validate", async () => {
|
|
704
|
-
await user_1.default.create({
|
|
705
|
-
username: "tomn19",
|
|
706
|
-
password: "s3cr3t893",
|
|
707
|
-
});
|
|
708
|
-
const u = await user_1.default.findOne({ username: "tomn19" });
|
|
709
|
-
(0, assertions_1.assertIsSet)(u);
|
|
710
|
-
(0, globals_1.expect)(u.username).toBe("tomn19");
|
|
711
|
-
(0, globals_1.expect)(u.email).toBe("tomn19@anonymous.com");
|
|
712
|
-
});
|
|
713
|
-
});
|
|
714
|
-
(0, globals_1.describe)("mergeActionResults", () => {
|
|
715
|
-
(0, globals_1.it)("it should merge errors", async () => {
|
|
716
|
-
const result = { error: "Foo" };
|
|
717
|
-
mergeActionResults(result, { error: "Bar" });
|
|
718
|
-
(0, globals_1.expect)(result.error).toStrictEqual(["Foo", "Bar"]);
|
|
719
|
-
});
|
|
720
|
-
(0, globals_1.it)("it should overwrite other keys", async () => {
|
|
721
|
-
const result = { error0: "Foo" };
|
|
722
|
-
mergeActionResults(result, { error0: "Bar" });
|
|
723
|
-
(0, globals_1.expect)(result.error0).toStrictEqual("Bar");
|
|
724
|
-
});
|
|
725
|
-
(0, globals_1.it)("it should merge set_fields", async () => {
|
|
726
|
-
const result = {};
|
|
727
|
-
mergeActionResults(result, { set_fields: { y: 2 } });
|
|
728
|
-
mergeActionResults(result, { set_fields: { z: 3 } });
|
|
729
|
-
(0, globals_1.expect)(result).toStrictEqual({ set_fields: { y: 2, z: 3 } });
|
|
730
|
-
});
|
|
731
|
-
});
|
|
732
|
-
(0, globals_1.describe)("multistep triggers", () => {
|
|
733
|
-
(0, globals_1.it)("should run", async () => {
|
|
734
|
-
const trigger = await trigger_1.default.findOne({ name: "MySteps" });
|
|
735
|
-
const runres = await trigger.runWithoutRow({});
|
|
736
|
-
(0, globals_1.expect)(runres.error).toBe("errrr");
|
|
737
|
-
(0, globals_1.expect)(runres.notify).toBe("note");
|
|
738
|
-
(0, globals_1.expect)(runres.notify_success).toBe("fooo");
|
|
739
|
-
});
|
|
740
|
-
});
|
|
741
|
-
(0, globals_1.describe)("run_action_column", () => {
|
|
742
|
-
(0, globals_1.it)("should run state action", async () => {
|
|
743
|
-
const runres = await (0, plugin_helper_1.run_action_column)({
|
|
744
|
-
req: mockReqRes.req,
|
|
745
|
-
col: {
|
|
746
|
-
type: "action",
|
|
747
|
-
block: false,
|
|
748
|
-
rndid: "2d6f57",
|
|
749
|
-
nsteps: 1,
|
|
750
|
-
confirm: false,
|
|
751
|
-
minRole: 100,
|
|
752
|
-
isFormula: {},
|
|
753
|
-
action_icon: "",
|
|
754
|
-
action_name: "toast",
|
|
755
|
-
action_label: "",
|
|
756
|
-
configuration: {
|
|
757
|
-
text: "note2",
|
|
758
|
-
run_where: "Server",
|
|
759
|
-
notify_type: "Notify",
|
|
760
|
-
},
|
|
761
|
-
},
|
|
762
|
-
});
|
|
763
|
-
(0, globals_1.expect)(runres).toStrictEqual({ notify: "note2" });
|
|
764
|
-
});
|
|
765
|
-
(0, globals_1.it)("should run trigger action", async () => {
|
|
766
|
-
const runres = await (0, plugin_helper_1.run_action_column)({
|
|
767
|
-
req: mockReqRes.req,
|
|
768
|
-
col: {
|
|
769
|
-
type: "action",
|
|
770
|
-
block: false,
|
|
771
|
-
rndid: "2d6f57",
|
|
772
|
-
nsteps: 1,
|
|
773
|
-
confirm: false,
|
|
774
|
-
minRole: 100,
|
|
775
|
-
isFormula: {},
|
|
776
|
-
action_icon: "",
|
|
777
|
-
action_name: "Toast1",
|
|
778
|
-
action_label: "",
|
|
779
|
-
configuration: {},
|
|
780
|
-
},
|
|
781
|
-
});
|
|
782
|
-
(0, globals_1.expect)(runres).toStrictEqual({ notify_success: "fooo" });
|
|
783
|
-
});
|
|
784
|
-
(0, globals_1.it)("should run multistep builder", async () => {
|
|
785
|
-
const runres = await (0, plugin_helper_1.run_action_column)({
|
|
786
|
-
req: mockReqRes.req,
|
|
787
|
-
col: {
|
|
788
|
-
type: "action",
|
|
789
|
-
block: false,
|
|
790
|
-
rndid: "5f990e",
|
|
791
|
-
nsteps: "2",
|
|
792
|
-
confirm: false,
|
|
793
|
-
minRole: 100,
|
|
794
|
-
isFormula: {},
|
|
795
|
-
action_icon: "",
|
|
796
|
-
action_name: "Multi-step action",
|
|
797
|
-
action_label: "",
|
|
798
|
-
configuration: {
|
|
799
|
-
steps: [
|
|
800
|
-
{
|
|
801
|
-
code: "1;",
|
|
802
|
-
run_where: "Server",
|
|
803
|
-
},
|
|
804
|
-
{
|
|
805
|
-
text: "note3",
|
|
806
|
-
notify_type: "Notify",
|
|
807
|
-
},
|
|
808
|
-
{
|
|
809
|
-
text: "succ3",
|
|
810
|
-
notify_type: "Success",
|
|
811
|
-
},
|
|
812
|
-
],
|
|
813
|
-
},
|
|
814
|
-
step_action_names: ["run_js_code", "toast", "toast"],
|
|
815
|
-
},
|
|
816
|
-
});
|
|
817
|
-
(0, globals_1.expect)(runres).toStrictEqual({ notify: "note3", notify_success: "succ3" });
|
|
818
|
-
});
|
|
819
|
-
(0, globals_1.it)("should run multistep builder with trigger step", async () => {
|
|
820
|
-
const runres = await (0, plugin_helper_1.run_action_column)({
|
|
821
|
-
req: mockReqRes.req,
|
|
822
|
-
col: {
|
|
823
|
-
type: "action",
|
|
824
|
-
block: false,
|
|
825
|
-
rndid: "45a31c",
|
|
826
|
-
nsteps: "2",
|
|
827
|
-
confirm: false,
|
|
828
|
-
minRole: 100,
|
|
829
|
-
isFormula: {},
|
|
830
|
-
action_icon: "",
|
|
831
|
-
action_name: "Multi-step action",
|
|
832
|
-
action_label: "",
|
|
833
|
-
configuration: {
|
|
834
|
-
steps: [
|
|
835
|
-
{
|
|
836
|
-
text: "note3",
|
|
837
|
-
notify_type: "Notify",
|
|
838
|
-
},
|
|
839
|
-
{
|
|
840
|
-
text: "succ3",
|
|
841
|
-
notify_type: "Success",
|
|
842
|
-
},
|
|
843
|
-
],
|
|
844
|
-
},
|
|
845
|
-
step_action_names: ["toast", "Toast1"],
|
|
846
|
-
},
|
|
847
|
-
});
|
|
848
|
-
(0, globals_1.expect)(runres).toStrictEqual({ notify: "note3", notify_success: "fooo" });
|
|
849
|
-
});
|
|
850
|
-
(0, globals_1.it)("should run multitrigger step", async () => {
|
|
851
|
-
const runres = await (0, plugin_helper_1.run_action_column)({
|
|
852
|
-
req: mockReqRes.req,
|
|
853
|
-
col: {
|
|
854
|
-
type: "action",
|
|
855
|
-
block: false,
|
|
856
|
-
rndid: "cd9965",
|
|
857
|
-
nsteps: 1,
|
|
858
|
-
confirm: false,
|
|
859
|
-
minRole: 100,
|
|
860
|
-
isFormula: {},
|
|
861
|
-
action_icon: "",
|
|
862
|
-
action_name: "MySteps",
|
|
863
|
-
action_label: "",
|
|
864
|
-
configuration: {},
|
|
865
|
-
},
|
|
866
|
-
});
|
|
867
|
-
(0, globals_1.expect)(runres.error).toBe("errrr");
|
|
868
|
-
(0, globals_1.expect)(runres.notify).toBe("note");
|
|
869
|
-
(0, globals_1.expect)(runres.notify_success).toBe("fooo");
|
|
870
|
-
});
|
|
871
|
-
});
|
|
872
|
-
(0, globals_1.describe)("plain_password_triggers", () => {
|
|
873
|
-
const secret = "fw78fgfw$Efgy";
|
|
874
|
-
(0, globals_1.it)("should set up trigger", async () => {
|
|
875
|
-
getState().registerPlugin("mock_plugin", plugin_with_routes());
|
|
876
|
-
resetActionCounter();
|
|
877
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
878
|
-
await trigger_1.default.create({
|
|
879
|
-
action: "evalCounter",
|
|
880
|
-
table_id: user_1.default.table.id,
|
|
881
|
-
when_trigger: "Insert",
|
|
882
|
-
name: "incCountIfPlainPassIns",
|
|
883
|
-
configuration: {
|
|
884
|
-
number_expr: `row.plain_password==="${secret}" ? 1 : 0`,
|
|
885
|
-
},
|
|
886
|
-
});
|
|
887
|
-
await trigger_1.default.create({
|
|
888
|
-
action: "evalCounter",
|
|
889
|
-
table_id: user_1.default.table.id,
|
|
890
|
-
when_trigger: "Update",
|
|
891
|
-
name: "incCountIfPlainPassUpd",
|
|
892
|
-
configuration: {
|
|
893
|
-
number_expr: `row.plain_password==="${secret}" ? 1 : 0`,
|
|
894
|
-
},
|
|
895
|
-
});
|
|
896
|
-
});
|
|
897
|
-
(0, globals_1.it)("should not pass password on update without setting", async () => {
|
|
898
|
-
const u = await user_1.default.findOne({ email: "staff@foo.com" });
|
|
899
|
-
(0, assertions_1.assertIsSet)(u);
|
|
900
|
-
resetActionCounter();
|
|
901
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
902
|
-
await u.changePasswordTo(secret);
|
|
903
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
904
|
-
});
|
|
905
|
-
(0, globals_1.it)("should not pass password on create without setting", async () => {
|
|
906
|
-
resetActionCounter();
|
|
907
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
908
|
-
await user_1.default.create({
|
|
909
|
-
email: "user1@foo.com",
|
|
910
|
-
password: secret,
|
|
911
|
-
role_id: 80,
|
|
912
|
-
});
|
|
913
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
914
|
-
});
|
|
915
|
-
(0, globals_1.it)("should pass password on update with setting", async () => {
|
|
916
|
-
await getState().setConfig("plain_password_triggers", true);
|
|
917
|
-
const u = await user_1.default.findOne({ email: "staff@foo.com" });
|
|
918
|
-
(0, assertions_1.assertIsSet)(u);
|
|
919
|
-
resetActionCounter();
|
|
920
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
921
|
-
await u.changePasswordTo(secret);
|
|
922
|
-
(0, globals_1.expect)(getActionCounter()).toBe(1);
|
|
923
|
-
});
|
|
924
|
-
(0, globals_1.it)("should pass password on create with setting", async () => {
|
|
925
|
-
await getState().setConfig("plain_password_triggers", true);
|
|
926
|
-
resetActionCounter();
|
|
927
|
-
(0, globals_1.expect)(getActionCounter()).toBe(0);
|
|
928
|
-
await user_1.default.create({
|
|
929
|
-
email: "user2@foo.com",
|
|
930
|
-
password: secret,
|
|
931
|
-
role_id: 80,
|
|
932
|
-
});
|
|
933
|
-
(0, globals_1.expect)(getActionCounter()).toBe(1);
|
|
934
|
-
});
|
|
935
|
-
});
|
|
936
|
-
//# sourceMappingURL=actions.test.js.map
|