@tsed/formio 8.11.0 → 8.11.2-rc.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/lib/esm/FormioModule.js +0 -1
- package/lib/esm/builder/FormioMapper.js +0 -1
- package/lib/esm/components/AlterActions.js +0 -1
- package/lib/esm/components/AlterAudit.js +0 -1
- package/lib/esm/components/AlterHost.js +0 -1
- package/lib/esm/components/AlterLog.js +0 -1
- package/lib/esm/components/AlterSkip.js +0 -1
- package/lib/esm/components/AlterTemplateExportSteps.js +0 -1
- package/lib/esm/components/AlterTemplateImportSteps.js +0 -1
- package/lib/esm/decorators/action.js +0 -1
- package/lib/esm/decorators/actionCtx.js +0 -1
- package/lib/esm/decorators/alter.js +0 -1
- package/lib/esm/decorators/on.js +0 -1
- package/lib/esm/decorators/useFormioAuth.js +0 -1
- package/lib/esm/domain/AlterHook.js +0 -1
- package/lib/esm/domain/Formio.js +0 -1
- package/lib/esm/domain/FormioAction.js +0 -1
- package/lib/esm/domain/FormioActionsIndex.js +0 -1
- package/lib/esm/domain/FormioAuth.js +0 -1
- package/lib/esm/domain/FormioBaseModel.js +0 -1
- package/lib/esm/domain/FormioConfig.js +0 -1
- package/lib/esm/domain/FormioCtxMapper.js +0 -1
- package/lib/esm/domain/FormioDecodedToken.js +0 -1
- package/lib/esm/domain/FormioErrors.js +0 -1
- package/lib/esm/domain/FormioHooks.js +0 -1
- package/lib/esm/domain/FormioJs.js +0 -1
- package/lib/esm/domain/FormioModels.js +0 -1
- package/lib/esm/domain/FormioRouter.js +0 -1
- package/lib/esm/domain/FormioSettings.js +0 -1
- package/lib/esm/domain/FormioTemplate.js +0 -1
- package/lib/esm/domain/FormioTemplateUtil.js +0 -1
- package/lib/esm/domain/FormioUpdate.js +0 -1
- package/lib/esm/domain/FormioUtils.js +0 -1
- package/lib/esm/domain/OnHook.js +0 -1
- package/lib/esm/domain/Resource.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/middlewares/FormioAuthMiddleware.js +0 -1
- package/lib/esm/services/FormioAuthService.js +0 -1
- package/lib/esm/services/FormioDatabase.js +0 -1
- package/lib/esm/services/FormioHooksService.js +0 -1
- package/lib/esm/services/FormioInstaller.js +0 -1
- package/lib/esm/services/FormioRepository.js +0 -1
- package/lib/esm/services/FormioService.js +0 -1
- package/lib/esm/utils/isMongoId.js +0 -1
- package/package.json +13 -10
- package/lib/esm/FormioModule.js.map +0 -1
- package/lib/esm/builder/FormioMapper.js.map +0 -1
- package/lib/esm/components/AlterActions.js.map +0 -1
- package/lib/esm/components/AlterAudit.js.map +0 -1
- package/lib/esm/components/AlterHost.js.map +0 -1
- package/lib/esm/components/AlterLog.js.map +0 -1
- package/lib/esm/components/AlterSkip.js.map +0 -1
- package/lib/esm/components/AlterTemplateExportSteps.js.map +0 -1
- package/lib/esm/components/AlterTemplateImportSteps.js.map +0 -1
- package/lib/esm/decorators/action.js.map +0 -1
- package/lib/esm/decorators/actionCtx.js.map +0 -1
- package/lib/esm/decorators/alter.js.map +0 -1
- package/lib/esm/decorators/on.js.map +0 -1
- package/lib/esm/decorators/useFormioAuth.js.map +0 -1
- package/lib/esm/domain/AlterHook.js.map +0 -1
- package/lib/esm/domain/Formio.js.map +0 -1
- package/lib/esm/domain/FormioAction.js.map +0 -1
- package/lib/esm/domain/FormioActionsIndex.js.map +0 -1
- package/lib/esm/domain/FormioAuth.js.map +0 -1
- package/lib/esm/domain/FormioBaseModel.js.map +0 -1
- package/lib/esm/domain/FormioConfig.js.map +0 -1
- package/lib/esm/domain/FormioCtxMapper.js.map +0 -1
- package/lib/esm/domain/FormioDecodedToken.js.map +0 -1
- package/lib/esm/domain/FormioErrors.js.map +0 -1
- package/lib/esm/domain/FormioHooks.js.map +0 -1
- package/lib/esm/domain/FormioJs.js.map +0 -1
- package/lib/esm/domain/FormioModels.js.map +0 -1
- package/lib/esm/domain/FormioRouter.js.map +0 -1
- package/lib/esm/domain/FormioSettings.js.map +0 -1
- package/lib/esm/domain/FormioTemplate.js.map +0 -1
- package/lib/esm/domain/FormioTemplateUtil.js.map +0 -1
- package/lib/esm/domain/FormioUpdate.js.map +0 -1
- package/lib/esm/domain/FormioUtils.js.map +0 -1
- package/lib/esm/domain/OnHook.js.map +0 -1
- package/lib/esm/domain/Resource.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/middlewares/FormioAuthMiddleware.js.map +0 -1
- package/lib/esm/services/FormioAuthService.js.map +0 -1
- package/lib/esm/services/FormioDatabase.js.map +0 -1
- package/lib/esm/services/FormioHooksService.js.map +0 -1
- package/lib/esm/services/FormioInstaller.js.map +0 -1
- package/lib/esm/services/FormioRepository.js.map +0 -1
- package/lib/esm/services/FormioService.js.map +0 -1
- package/lib/esm/utils/isMongoId.js.map +0 -1
- package/src/FormioModule.spec.ts +0 -113
- package/src/FormioModule.ts +0 -130
- package/src/builder/FormioMapper.spec.ts +0 -93
- package/src/builder/FormioMapper.ts +0 -71
- package/src/components/AlterActions.spec.ts +0 -376
- package/src/components/AlterActions.ts +0 -136
- package/src/components/AlterAudit.spec.ts +0 -19
- package/src/components/AlterAudit.ts +0 -12
- package/src/components/AlterHost.spec.ts +0 -20
- package/src/components/AlterHost.ts +0 -11
- package/src/components/AlterLog.spec.ts +0 -19
- package/src/components/AlterLog.ts +0 -12
- package/src/components/AlterSkip.spec.ts +0 -44
- package/src/components/AlterSkip.ts +0 -28
- package/src/components/AlterTemplateExportSteps.spec.ts +0 -99
- package/src/components/AlterTemplateExportSteps.ts +0 -58
- package/src/components/AlterTemplateImportSteps.spec.ts +0 -70
- package/src/components/AlterTemplateImportSteps.ts +0 -50
- package/src/decorators/action.ts +0 -20
- package/src/decorators/actionCtx.spec.ts +0 -25
- package/src/decorators/actionCtx.ts +0 -29
- package/src/decorators/alter.spec.ts +0 -16
- package/src/decorators/alter.ts +0 -19
- package/src/decorators/on.spec.ts +0 -16
- package/src/decorators/on.ts +0 -19
- package/src/decorators/useFormioAuth.spec.ts +0 -15
- package/src/decorators/useFormioAuth.ts +0 -12
- package/src/domain/AlterHook.ts +0 -3
- package/src/domain/Formio.ts +0 -122
- package/src/domain/FormioAction.ts +0 -30
- package/src/domain/FormioActionsIndex.ts +0 -19
- package/src/domain/FormioAuth.ts +0 -83
- package/src/domain/FormioBaseModel.ts +0 -14
- package/src/domain/FormioConfig.ts +0 -63
- package/src/domain/FormioCtxMapper.ts +0 -8
- package/src/domain/FormioDecodedToken.ts +0 -13
- package/src/domain/FormioErrors.ts +0 -53
- package/src/domain/FormioHooks.ts +0 -207
- package/src/domain/FormioJs.ts +0 -18
- package/src/domain/FormioModels.ts +0 -48
- package/src/domain/FormioRouter.ts +0 -10
- package/src/domain/FormioSettings.ts +0 -61
- package/src/domain/FormioTemplate.ts +0 -9
- package/src/domain/FormioTemplateUtil.ts +0 -15
- package/src/domain/FormioUpdate.ts +0 -23
- package/src/domain/FormioUtils.ts +0 -331
- package/src/domain/OnHook.ts +0 -3
- package/src/domain/Resource.ts +0 -21
- package/src/index.ts +0 -46
- package/src/middlewares/FormioAuthMiddleware.spec.ts +0 -61
- package/src/middlewares/FormioAuthMiddleware.ts +0 -34
- package/src/services/FormioAuthService.spec.ts +0 -396
- package/src/services/FormioAuthService.ts +0 -228
- package/src/services/FormioDatabase.spec.ts +0 -326
- package/src/services/FormioDatabase.ts +0 -165
- package/src/services/FormioHooksService.spec.ts +0 -156
- package/src/services/FormioHooksService.ts +0 -92
- package/src/services/FormioInstaller.spec.ts +0 -146
- package/src/services/FormioInstaller.ts +0 -46
- package/src/services/FormioRepository.spec.ts +0 -114
- package/src/services/FormioRepository.ts +0 -49
- package/src/services/FormioService.spec.ts +0 -368
- package/src/services/FormioService.ts +0 -134
- package/src/utils/isMongoId.ts +0 -3
- package/vitest.config.mts +0 -21
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
2
|
-
|
|
3
|
-
import {FormioDatabase} from "./FormioDatabase.js";
|
|
4
|
-
import {FormioService} from "./FormioService.js";
|
|
5
|
-
|
|
6
|
-
async function createServiceFixture() {
|
|
7
|
-
const formioService = {
|
|
8
|
-
mongoose: {
|
|
9
|
-
models: {
|
|
10
|
-
role: {
|
|
11
|
-
find: vi.fn().mockResolvedValue([{_id: "role_id", machineName: "role_machine"}])
|
|
12
|
-
},
|
|
13
|
-
form: class {
|
|
14
|
-
static countDocuments = vi.fn();
|
|
15
|
-
static find = vi.fn().mockResolvedValue([{_id: "form_id", machineName: "form_machine"}]);
|
|
16
|
-
static findOne = vi.fn().mockReturnThis();
|
|
17
|
-
static findOneAndUpdate = vi.fn();
|
|
18
|
-
static updateOne = vi.fn().mockReturnThis();
|
|
19
|
-
static lean = vi.fn().mockReturnThis();
|
|
20
|
-
static exec = vi.fn();
|
|
21
|
-
|
|
22
|
-
constructor(public ctrOpts: any) {
|
|
23
|
-
Object.assign(this, ctrOpts);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
save(): any {}
|
|
27
|
-
|
|
28
|
-
toObject() {
|
|
29
|
-
return this.ctrOpts;
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
action: {
|
|
33
|
-
find: vi.fn().mockResolvedValue([{_id: "action_id", machineName: "action_machine"}])
|
|
34
|
-
},
|
|
35
|
-
submission: class {
|
|
36
|
-
static find = vi.fn().mockResolvedValue([]);
|
|
37
|
-
static findOneAndUpdate = vi.fn().mockImplementation((o, o1) => ({...o, ...o1}));
|
|
38
|
-
|
|
39
|
-
constructor(o: any) {
|
|
40
|
-
Object.assign(this, {
|
|
41
|
-
...o,
|
|
42
|
-
_id: o._id || "newID"
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
token: {},
|
|
47
|
-
actionItem: {}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
util: {
|
|
51
|
-
idToBson: vi.fn()
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const service = await PlatformTest.invoke<FormioDatabase>(FormioDatabase, [
|
|
55
|
-
{
|
|
56
|
-
token: FormioService,
|
|
57
|
-
use: formioService
|
|
58
|
-
}
|
|
59
|
-
]);
|
|
60
|
-
|
|
61
|
-
return {service, formioService};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
describe("FormioDatabase", () => {
|
|
65
|
-
beforeEach(() => PlatformTest.create());
|
|
66
|
-
afterEach(PlatformTest.reset);
|
|
67
|
-
|
|
68
|
-
describe("getFormioMapper()", () => {
|
|
69
|
-
it("should return the mapper", async () => {
|
|
70
|
-
const {service, formioService} = await createServiceFixture();
|
|
71
|
-
|
|
72
|
-
const mapper = await service.getFormioMapper();
|
|
73
|
-
|
|
74
|
-
expect([...mapper.ctxData.forms.entries()]).toEqual([
|
|
75
|
-
[
|
|
76
|
-
"form_id",
|
|
77
|
-
{
|
|
78
|
-
_id: "form_id",
|
|
79
|
-
machineName: "form_machine"
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
[
|
|
83
|
-
"$machineName:form_machine",
|
|
84
|
-
{
|
|
85
|
-
_id: "form_id",
|
|
86
|
-
machineName: "form_machine"
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
]);
|
|
90
|
-
expect([...mapper.ctxData.actions.entries()]).toEqual([
|
|
91
|
-
[
|
|
92
|
-
"action_id",
|
|
93
|
-
{
|
|
94
|
-
_id: "action_id",
|
|
95
|
-
machineName: "action_machine"
|
|
96
|
-
}
|
|
97
|
-
],
|
|
98
|
-
[
|
|
99
|
-
"$machineName:action_machine",
|
|
100
|
-
{
|
|
101
|
-
_id: "action_id",
|
|
102
|
-
machineName: "action_machine"
|
|
103
|
-
}
|
|
104
|
-
]
|
|
105
|
-
]);
|
|
106
|
-
expect([...mapper.ctxData.roles.entries()]).toEqual([
|
|
107
|
-
[
|
|
108
|
-
"role_id",
|
|
109
|
-
{
|
|
110
|
-
_id: "role_id",
|
|
111
|
-
machineName: "role_machine"
|
|
112
|
-
}
|
|
113
|
-
],
|
|
114
|
-
[
|
|
115
|
-
"$machineName:role_machine",
|
|
116
|
-
{
|
|
117
|
-
_id: "role_id",
|
|
118
|
-
machineName: "role_machine"
|
|
119
|
-
}
|
|
120
|
-
]
|
|
121
|
-
]);
|
|
122
|
-
|
|
123
|
-
expect(formioService.mongoose.models.form.find).toHaveBeenCalledWith({
|
|
124
|
-
deleted: {$eq: null}
|
|
125
|
-
});
|
|
126
|
-
expect(formioService.mongoose.models.role.find).toHaveBeenCalledWith({
|
|
127
|
-
deleted: {$eq: null}
|
|
128
|
-
});
|
|
129
|
-
expect(formioService.mongoose.models.action.find).toHaveBeenCalledWith({
|
|
130
|
-
deleted: {$eq: null}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe("hasForm()", () => {
|
|
135
|
-
it("should return true when database contain forms", async () => {
|
|
136
|
-
const {service, formioService} = await createServiceFixture();
|
|
137
|
-
formioService.mongoose.models.form.countDocuments.mockResolvedValue(6);
|
|
138
|
-
|
|
139
|
-
expect(await service.hasForms()).toEqual(true);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should return false when database has no forms", async () => {
|
|
143
|
-
const {service, formioService} = await createServiceFixture();
|
|
144
|
-
formioService.mongoose.models.form.countDocuments.mockResolvedValue(0);
|
|
145
|
-
|
|
146
|
-
expect(await service.hasForms()).toEqual(false);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
describe("submissionModel()", () => {
|
|
150
|
-
it("should return the submissionModel", async () => {
|
|
151
|
-
const {service, formioService} = await createServiceFixture();
|
|
152
|
-
expect(service.submissionModel).toEqual(formioService.mongoose.models.submission);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe("tokenModel()", () => {
|
|
156
|
-
it("should return the tokenModel", async () => {
|
|
157
|
-
const {service, formioService} = await createServiceFixture();
|
|
158
|
-
expect(service.tokenModel).toEqual(formioService.mongoose.models.token);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
describe("actionItemModel()", () => {
|
|
162
|
-
it("should return the actionItemModel", async () => {
|
|
163
|
-
const {service, formioService} = await createServiceFixture();
|
|
164
|
-
expect(service.actionItemModel).toEqual(formioService.mongoose.models.actionItem);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe("importFormIfNotExists()", () => {
|
|
168
|
-
it("should return create the form if not exists", async () => {
|
|
169
|
-
const {service, formioService} = await createServiceFixture();
|
|
170
|
-
const onCreate = vi.fn();
|
|
171
|
-
const form: any = {
|
|
172
|
-
name: "name"
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
formioService.mongoose.models.form.countDocuments.mockResolvedValue(false);
|
|
176
|
-
formioService.mongoose.models.form.exec.mockResolvedValue({
|
|
177
|
-
_id: "id",
|
|
178
|
-
name: "name"
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const result = await service.importFormIfNotExists(form, onCreate);
|
|
182
|
-
|
|
183
|
-
expect(result).toEqual({
|
|
184
|
-
_id: "id",
|
|
185
|
-
name: "name"
|
|
186
|
-
});
|
|
187
|
-
expect(onCreate).toHaveBeenCalledTimes(1);
|
|
188
|
-
});
|
|
189
|
-
it("should not create form is exists", async () => {
|
|
190
|
-
const {service, formioService} = await createServiceFixture();
|
|
191
|
-
const onCreate = vi.fn();
|
|
192
|
-
const form: any = {
|
|
193
|
-
name: "name"
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
formioService.mongoose.models.form.countDocuments.mockResolvedValue(true);
|
|
197
|
-
formioService.mongoose.models.form.exec.mockResolvedValue({
|
|
198
|
-
_id: "id",
|
|
199
|
-
name: "name"
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
const result = await service.importFormIfNotExists(form, onCreate);
|
|
203
|
-
|
|
204
|
-
expect(result).toEqual({
|
|
205
|
-
_id: "id",
|
|
206
|
-
name: "name"
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
describe("getSubmissions()", () => {
|
|
211
|
-
it("should return submissions", async () => {
|
|
212
|
-
const {service} = await createServiceFixture();
|
|
213
|
-
|
|
214
|
-
const result = await service.getSubmissions();
|
|
215
|
-
|
|
216
|
-
expect(result).toEqual([]);
|
|
217
|
-
expect(service.submissionModel.find).toHaveBeenCalledWith({deleted: {$eq: null}});
|
|
218
|
-
});
|
|
219
|
-
it("should return submissions with query", async () => {
|
|
220
|
-
const {service} = await createServiceFixture();
|
|
221
|
-
|
|
222
|
-
const result = await service.getSubmissions({
|
|
223
|
-
form: "id"
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
expect(result).toEqual([]);
|
|
227
|
-
expect(service.submissionModel.find).toHaveBeenCalledWith({deleted: {$eq: null}, form: "id"});
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
describe("saveSubmissions()", () => {
|
|
231
|
-
it("should create submission", async () => {
|
|
232
|
-
const {service} = await createServiceFixture();
|
|
233
|
-
|
|
234
|
-
const result = await service.saveSubmission({
|
|
235
|
-
data: {}
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
expect(result).toEqual({
|
|
239
|
-
_id: "newID",
|
|
240
|
-
data: {}
|
|
241
|
-
});
|
|
242
|
-
expect(service.submissionModel.findOneAndUpdate).toHaveBeenCalledWith(
|
|
243
|
-
{_id: "newID"},
|
|
244
|
-
{_id: "newID", data: {}},
|
|
245
|
-
{
|
|
246
|
-
new: true,
|
|
247
|
-
upsert: true
|
|
248
|
-
}
|
|
249
|
-
);
|
|
250
|
-
});
|
|
251
|
-
it("should update submission", async () => {
|
|
252
|
-
const {service} = await createServiceFixture();
|
|
253
|
-
|
|
254
|
-
const result = await service.saveSubmission({
|
|
255
|
-
_id: "id",
|
|
256
|
-
data: {}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
expect(result).toEqual({
|
|
260
|
-
_id: "id",
|
|
261
|
-
data: {}
|
|
262
|
-
});
|
|
263
|
-
expect(service.submissionModel.findOneAndUpdate).toHaveBeenCalledWith(
|
|
264
|
-
{_id: "id"},
|
|
265
|
-
{
|
|
266
|
-
_id: "id",
|
|
267
|
-
data: {}
|
|
268
|
-
},
|
|
269
|
-
{new: true, upsert: true}
|
|
270
|
-
);
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
describe("importSubmission()", () => {
|
|
274
|
-
it("should import submission", async () => {
|
|
275
|
-
const {service} = await createServiceFixture();
|
|
276
|
-
|
|
277
|
-
vi.spyOn(service, "saveSubmission").mockResolvedValue({} as any);
|
|
278
|
-
|
|
279
|
-
const result = await service.importSubmission({
|
|
280
|
-
_id: "id",
|
|
281
|
-
data: {}
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
expect(result).toEqual({});
|
|
285
|
-
expect(service.saveSubmission).toHaveBeenCalledWith({_id: "id", data: {}});
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
describe("getForm", () => {
|
|
289
|
-
it("should return form from id", async () => {
|
|
290
|
-
const {service, formioService} = await createServiceFixture();
|
|
291
|
-
|
|
292
|
-
await service.getForm("605f0d40fe971372e448bcad");
|
|
293
|
-
|
|
294
|
-
expect(formioService.mongoose.models.form.findOne).toHaveBeenCalledWith({
|
|
295
|
-
_id: "605f0d40fe971372e448bcad",
|
|
296
|
-
deleted: {$eq: null}
|
|
297
|
-
});
|
|
298
|
-
expect(formioService.mongoose.models.form.lean).toHaveBeenCalledWith();
|
|
299
|
-
expect(formioService.mongoose.models.form.exec).toHaveBeenCalledWith();
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("should return form from machineName", async () => {
|
|
303
|
-
const {service, formioService} = await createServiceFixture();
|
|
304
|
-
|
|
305
|
-
await service.getForm("name");
|
|
306
|
-
|
|
307
|
-
expect(formioService.mongoose.models.form.findOne).toHaveBeenCalledWith({
|
|
308
|
-
name: {$eq: "name"},
|
|
309
|
-
deleted: {$eq: null}
|
|
310
|
-
});
|
|
311
|
-
expect(formioService.mongoose.models.form.lean).toHaveBeenCalledWith();
|
|
312
|
-
expect(formioService.mongoose.models.form.exec).toHaveBeenCalledWith();
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
describe("idToBson", () => {
|
|
316
|
-
beforeEach(() => {});
|
|
317
|
-
it("should convert id", async () => {
|
|
318
|
-
const {service, formioService} = await createServiceFixture();
|
|
319
|
-
formioService.util.idToBson.mockReturnValue({bson: "bson"});
|
|
320
|
-
expect(service.idToBson("id")).toEqual({bson: "bson"});
|
|
321
|
-
expect(service.idToBson(["id"])).toEqual({$in: [{bson: "bson"}]});
|
|
322
|
-
expect(service.idToBson({_id: "id"})).toEqual({bson: "bson"});
|
|
323
|
-
expect(service.idToBson()).toEqual(undefined);
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
});
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import {isArray, isObject, isString, toMap as tMap} from "@tsed/core";
|
|
2
|
-
import {Inject, Injectable} from "@tsed/di";
|
|
3
|
-
import {FormioAction, FormioActionItem, FormioForm, FormioRole, FormioSubmission, FormioToken} from "@tsed/formio-types";
|
|
4
|
-
import {MongooseDocument, MongooseModel} from "@tsed/mongoose";
|
|
5
|
-
import omit from "lodash/omit.js";
|
|
6
|
-
import type {FilterQuery} from "mongoose";
|
|
7
|
-
|
|
8
|
-
import {FormioMapper} from "../builder/FormioMapper.js";
|
|
9
|
-
import {isMongoId} from "../utils/isMongoId.js";
|
|
10
|
-
import {FormioService} from "./FormioService.js";
|
|
11
|
-
|
|
12
|
-
function toMap<T>(list: any[]) {
|
|
13
|
-
return tMap<string, MongooseDocument<T>>(list, (o: any) => [o._id.toString(), `$machineName:${o.name || o.machineName}`]);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@Injectable()
|
|
17
|
-
export class FormioDatabase {
|
|
18
|
-
@Inject()
|
|
19
|
-
protected formio: FormioService;
|
|
20
|
-
|
|
21
|
-
get models() {
|
|
22
|
-
return this.formio.mongoose.models;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get roleModel(): MongooseModel<FormioRole> {
|
|
26
|
-
return this.models.role;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get formModel(): MongooseModel<FormioForm> {
|
|
30
|
-
return this.models.form;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get actionModel(): MongooseModel<FormioAction> {
|
|
34
|
-
return this.models.action;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get submissionModel(): MongooseModel<FormioSubmission> {
|
|
38
|
-
return this.models.submission;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get tokenModel(): MongooseModel<FormioToken> {
|
|
42
|
-
return this.models.token;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get actionItemModel(): MongooseModel<FormioActionItem> {
|
|
46
|
-
return this.models.actionItem;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async getFormioMapper(): Promise<FormioMapper> {
|
|
50
|
-
const [roles, forms, actions] = await Promise.all([
|
|
51
|
-
this.roleModel.find({
|
|
52
|
-
deleted: {$eq: null}
|
|
53
|
-
}),
|
|
54
|
-
this.formModel.find({
|
|
55
|
-
deleted: {$eq: null}
|
|
56
|
-
}),
|
|
57
|
-
this.actionModel.find({
|
|
58
|
-
deleted: {$eq: null}
|
|
59
|
-
})
|
|
60
|
-
]);
|
|
61
|
-
|
|
62
|
-
return new FormioMapper({
|
|
63
|
-
forms: toMap<FormioForm>(forms),
|
|
64
|
-
actions: toMap<FormioAction>(actions),
|
|
65
|
-
roles: toMap<FormioRole>(roles)
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async hasForms(): Promise<boolean> {
|
|
70
|
-
return (await this.formModel.countDocuments()) > 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async hasForm(name: string): Promise<boolean> {
|
|
74
|
-
return !!(await this.formModel.countDocuments({name: {$eq: name}}));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getForm(nameOrId: string) {
|
|
78
|
-
return this.formModel
|
|
79
|
-
.findOne({
|
|
80
|
-
deleted: {$eq: null},
|
|
81
|
-
...(isMongoId(nameOrId)
|
|
82
|
-
? {
|
|
83
|
-
_id: nameOrId
|
|
84
|
-
}
|
|
85
|
-
: {name: {$eq: nameOrId}})
|
|
86
|
-
})
|
|
87
|
-
.lean()
|
|
88
|
-
.exec();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Import form previously exported by export tool.
|
|
93
|
-
* This method transform alias to a real mongoose _id
|
|
94
|
-
* @param form
|
|
95
|
-
* @param onCreate
|
|
96
|
-
*/
|
|
97
|
-
async importFormIfNotExists(form: FormioForm, onCreate?: (form: FormioForm) => any) {
|
|
98
|
-
if (!(await this.hasForm(form.name))) {
|
|
99
|
-
const createForm = await this.importForm(form);
|
|
100
|
-
|
|
101
|
-
onCreate && (await onCreate(createForm));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return this.getForm(form.name);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Import form previously exported by export tool.
|
|
109
|
-
* This method transform alias to a real mongoose _id
|
|
110
|
-
* @param form
|
|
111
|
-
*/
|
|
112
|
-
async importForm(form: FormioForm) {
|
|
113
|
-
const mapper = await this.getFormioMapper();
|
|
114
|
-
|
|
115
|
-
return this.saveForm(mapper.mapToImport(form));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
saveForm(form: FormioForm) {
|
|
119
|
-
form = new this.formModel(omit(form, ["__v"]) as any);
|
|
120
|
-
|
|
121
|
-
return this.formModel.findOneAndUpdate({_id: form._id}, form, {upsert: true, new: true});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
getSubmissions<Data>(
|
|
125
|
-
query: FilterQuery<MongooseModel<FormioSubmission<Data>>> = {}
|
|
126
|
-
): Promise<MongooseDocument<FormioSubmission<Data>>[]> {
|
|
127
|
-
return this.submissionModel.find({
|
|
128
|
-
...query,
|
|
129
|
-
deleted: {$eq: null}
|
|
130
|
-
}) as any;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Import submission previously exported by export tool.
|
|
135
|
-
* This method transform alias to a real mongoose _id
|
|
136
|
-
* @param submission
|
|
137
|
-
*/
|
|
138
|
-
async importSubmission<Data = any>(submission: Omit<Partial<FormioSubmission<Data>>, "form"> & {form?: any}) {
|
|
139
|
-
const mapper = await this.getFormioMapper();
|
|
140
|
-
|
|
141
|
-
return this.saveSubmission(mapper.mapToImport(submission));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
saveSubmission<Data = any>(submission: Partial<FormioSubmission<Data>>) {
|
|
145
|
-
submission = new this.submissionModel(omit(submission, ["__v"]));
|
|
146
|
-
|
|
147
|
-
return this.submissionModel.findOneAndUpdate(
|
|
148
|
-
{
|
|
149
|
-
_id: submission._id
|
|
150
|
-
},
|
|
151
|
-
submission,
|
|
152
|
-
{new: true, upsert: true}
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
idToBson(form?: any) {
|
|
157
|
-
if (isArray(form)) {
|
|
158
|
-
return {$in: form.map(this.formio.util.idToBson)};
|
|
159
|
-
} else if (isObject(form)) {
|
|
160
|
-
return this.formio.util.idToBson((form as any)._id);
|
|
161
|
-
} else if (isString(form)) {
|
|
162
|
-
return this.formio.util.idToBson(form);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import {Store} from "@tsed/core";
|
|
2
|
-
import {Provider} from "@tsed/di";
|
|
3
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
4
|
-
|
|
5
|
-
import {FormioHooksService} from "./FormioHooksService.js";
|
|
6
|
-
import {FormioService} from "./FormioService.js";
|
|
7
|
-
|
|
8
|
-
describe("FormioHooksService", () => {
|
|
9
|
-
beforeEach(PlatformTest.create);
|
|
10
|
-
afterEach(PlatformTest.reset);
|
|
11
|
-
|
|
12
|
-
it("should wrap multiple 'alter' hooks", async () => {
|
|
13
|
-
const service = await PlatformTest.invoke<FormioHooksService>(FormioHooksService);
|
|
14
|
-
|
|
15
|
-
class Alter1 {
|
|
16
|
-
transform(value: any) {
|
|
17
|
-
return value + ":1";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
class Alter2 {
|
|
22
|
-
transform(value: any) {
|
|
23
|
-
return value + ":2";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
Store.from(Alter1).set("formio:alter:name", "hookName");
|
|
28
|
-
Store.from(Alter2).set("formio:alter:name", "hookName");
|
|
29
|
-
|
|
30
|
-
vi.spyOn(service as any, "getProviders").mockReturnValue([new Provider(Alter1), new Provider(Alter2)]);
|
|
31
|
-
|
|
32
|
-
const hooks: any = service.getHooks();
|
|
33
|
-
|
|
34
|
-
expect(hooks.alter.hookName).toBeInstanceOf(Function);
|
|
35
|
-
|
|
36
|
-
expect(hooks.alter.hookName("init")).toEqual("init:1:2");
|
|
37
|
-
});
|
|
38
|
-
it("should wrap multiple 'alter' hooks with args", async () => {
|
|
39
|
-
const service = await PlatformTest.invoke<FormioHooksService>(FormioHooksService);
|
|
40
|
-
|
|
41
|
-
class Alter1 {
|
|
42
|
-
transform(value: any, ...args: any[]) {
|
|
43
|
-
return `${value}:1(${args.join(",")})`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class Alter2 {
|
|
48
|
-
transform(value: any, ...args: any[]) {
|
|
49
|
-
return `${value}:2(${args.join(",")})`;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
Store.from(Alter1).set("formio:alter:name", "hookName");
|
|
54
|
-
Store.from(Alter2).set("formio:alter:name", "hookName");
|
|
55
|
-
|
|
56
|
-
vi.spyOn(service as any, "getProviders").mockReturnValue([new Provider(Alter1), new Provider(Alter2)]);
|
|
57
|
-
|
|
58
|
-
const hooks: any = service.getHooks();
|
|
59
|
-
|
|
60
|
-
expect(hooks.alter.hookName).toBeInstanceOf(Function);
|
|
61
|
-
|
|
62
|
-
expect(hooks.alter.hookName("init", "hello")).toEqual("init:1(hello):2(hello)");
|
|
63
|
-
});
|
|
64
|
-
it("should wrap multiple 'on' hooks", async () => {
|
|
65
|
-
const service = await PlatformTest.invoke<FormioHooksService>(FormioHooksService);
|
|
66
|
-
|
|
67
|
-
class On1 {
|
|
68
|
-
on(value: any) {
|
|
69
|
-
return value + ":1";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
class On2 {
|
|
74
|
-
on(value: any) {
|
|
75
|
-
return value + ":2";
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
Store.from(On1).set("formio:on:name", "hookName");
|
|
80
|
-
Store.from(On2).set("formio:on:name", "hookName");
|
|
81
|
-
|
|
82
|
-
vi.spyOn(service as any, "getProviders").mockReturnValue([new Provider(On1), new Provider(On2)]);
|
|
83
|
-
|
|
84
|
-
const hooks: any = service.getHooks();
|
|
85
|
-
|
|
86
|
-
expect(hooks.on.hookName).toBeInstanceOf(Function);
|
|
87
|
-
expect(hooks.on.hookName("init")).toEqual("init:2");
|
|
88
|
-
});
|
|
89
|
-
it("should return settings method", async () => {
|
|
90
|
-
const formio = {
|
|
91
|
-
hook: {
|
|
92
|
-
settings: vi.fn()
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const service = await PlatformTest.invoke<FormioHooksService>(FormioHooksService, [
|
|
97
|
-
{
|
|
98
|
-
use: formio,
|
|
99
|
-
token: FormioService
|
|
100
|
-
}
|
|
101
|
-
]);
|
|
102
|
-
|
|
103
|
-
expect(service.settings).toEqual(formio.hook.settings);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should return invoke method", async () => {
|
|
107
|
-
const formio = {
|
|
108
|
-
hook: {
|
|
109
|
-
invoke: vi.fn()
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const service = await PlatformTest.invoke<FormioHooksService>(FormioHooksService, [
|
|
114
|
-
{
|
|
115
|
-
use: formio,
|
|
116
|
-
token: FormioService
|
|
117
|
-
}
|
|
118
|
-
]);
|
|
119
|
-
|
|
120
|
-
expect(service.invoke).toEqual(formio.hook.invoke);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("should return alter method", async () => {
|
|
124
|
-
const formio = {
|
|
125
|
-
hook: {
|
|
126
|
-
alter: vi.fn()
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const service = await PlatformTest.invoke<FormioHooksService>(FormioHooksService, [
|
|
131
|
-
{
|
|
132
|
-
use: formio,
|
|
133
|
-
token: FormioService
|
|
134
|
-
}
|
|
135
|
-
]);
|
|
136
|
-
|
|
137
|
-
expect(service.alter).toEqual(formio.hook.alter);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("should return alterAsync method", async () => {
|
|
141
|
-
const formio = {
|
|
142
|
-
hook: {
|
|
143
|
-
alter: vi.fn()
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const service = await PlatformTest.invoke<FormioHooksService>(FormioHooksService, [
|
|
148
|
-
{
|
|
149
|
-
use: formio,
|
|
150
|
-
token: FormioService
|
|
151
|
-
}
|
|
152
|
-
]);
|
|
153
|
-
|
|
154
|
-
expect(typeof service.alterAsync).toEqual("function");
|
|
155
|
-
});
|
|
156
|
-
});
|