@strapi/strapi 4.10.1-experimental.0 → 4.10.2-alpha.0
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/commands/actions/{build → build-command}/command.js +1 -1
- package/lib/commands/actions/telemetry/enable/action.js +3 -3
- package/lib/commands/index.js +1 -1
- package/lib/core/loaders/apis.js +5 -0
- package/lib/utils/machine-id.js +2 -2
- package/package.json +16 -17
- package/coverage/clover.xml +0 -1613
- package/coverage/coverage-final.json +0 -48
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/commands/__tests__/data-transfer/shared/index.html +0 -116
- package/coverage/lcov-report/commands/__tests__/data-transfer/shared/transfer.test.utils.js.html +0 -133
- package/coverage/lcov-report/commands/admin-create.js.html +0 -424
- package/coverage/lcov-report/commands/admin-reset.js.html +0 -241
- package/coverage/lcov-report/commands/generate-template.js.html +0 -373
- package/coverage/lcov-report/commands/index.html +0 -146
- package/coverage/lcov-report/commands/transfer/export.js.html +0 -619
- package/coverage/lcov-report/commands/transfer/import.js.html +0 -562
- package/coverage/lcov-report/commands/transfer/index.html +0 -146
- package/coverage/lcov-report/commands/transfer/transfer.js.html +0 -532
- package/coverage/lcov-report/commands/utils/helpers.js.html +0 -430
- package/coverage/lcov-report/commands/utils/index.html +0 -116
- package/coverage/lcov-report/core/registries/custom-fields.js.html +0 -301
- package/coverage/lcov-report/core/registries/index.html +0 -116
- package/coverage/lcov-report/core-api/controller/collection-type.js.html +0 -418
- package/coverage/lcov-report/core-api/controller/index.html +0 -161
- package/coverage/lcov-report/core-api/controller/index.js.html +0 -220
- package/coverage/lcov-report/core-api/controller/single-type.js.html +0 -274
- package/coverage/lcov-report/core-api/controller/transform.js.html +0 -376
- package/coverage/lcov-report/core-api/service/collection-type.js.html +0 -325
- package/coverage/lcov-report/core-api/service/index.html +0 -161
- package/coverage/lcov-report/core-api/service/index.js.html +0 -220
- package/coverage/lcov-report/core-api/service/pagination.js.html +0 -460
- package/coverage/lcov-report/core-api/service/single-type.js.html +0 -301
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -386
- package/coverage/lcov-report/load/filepath-to-prop-path.js.html +0 -151
- package/coverage/lcov-report/load/index.html +0 -116
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/services/content-api/index.html +0 -116
- package/coverage/lcov-report/services/content-api/index.js.html +0 -307
- package/coverage/lcov-report/services/content-api/permissions/engine.js.html +0 -100
- package/coverage/lcov-report/services/content-api/permissions/index.html +0 -131
- package/coverage/lcov-report/services/content-api/permissions/index.js.html +0 -529
- package/coverage/lcov-report/services/content-api/permissions/providers/action.js.html +0 -142
- package/coverage/lcov-report/services/content-api/permissions/providers/condition.js.html +0 -142
- package/coverage/lcov-report/services/content-api/permissions/providers/index.html +0 -146
- package/coverage/lcov-report/services/content-api/permissions/providers/index.js.html +0 -112
- package/coverage/lcov-report/services/core-store.js.html +0 -520
- package/coverage/lcov-report/services/entity-service/attributes/index.html +0 -131
- package/coverage/lcov-report/services/entity-service/attributes/index.js.html +0 -178
- package/coverage/lcov-report/services/entity-service/attributes/transforms.js.html +0 -145
- package/coverage/lcov-report/services/entity-service/components.js.html +0 -1246
- package/coverage/lcov-report/services/entity-service/index.html +0 -146
- package/coverage/lcov-report/services/entity-service/index.js.html +0 -1120
- package/coverage/lcov-report/services/entity-service/params.js.html +0 -112
- package/coverage/lcov-report/services/entity-validator/__tests__/relations/utils/index.html +0 -116
- package/coverage/lcov-report/services/entity-validator/__tests__/relations/utils/relations.testdata.js.html +0 -544
- package/coverage/lcov-report/services/entity-validator/index.html +0 -131
- package/coverage/lcov-report/services/entity-validator/index.js.html +0 -1231
- package/coverage/lcov-report/services/entity-validator/validators.js.html +0 -733
- package/coverage/lcov-report/services/event-hub.js.html +0 -319
- package/coverage/lcov-report/services/fs.js.html +0 -259
- package/coverage/lcov-report/services/index.html +0 -161
- package/coverage/lcov-report/services/metrics/admin-user-hash.js.html +0 -148
- package/coverage/lcov-report/services/metrics/index.html +0 -206
- package/coverage/lcov-report/services/metrics/index.js.html +0 -265
- package/coverage/lcov-report/services/metrics/is-truthy.js.html +0 -112
- package/coverage/lcov-report/services/metrics/middleware.js.html +0 -184
- package/coverage/lcov-report/services/metrics/rate-limiter.js.html +0 -166
- package/coverage/lcov-report/services/metrics/sender.js.html +0 -394
- package/coverage/lcov-report/services/metrics/stringify-deep.js.html +0 -151
- package/coverage/lcov-report/services/utils/index.html +0 -116
- package/coverage/lcov-report/services/utils/upload-files.js.html +0 -322
- package/coverage/lcov-report/services/worker-queue.js.html +0 -262
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/utils/convert-custom-field-type.js.html +0 -151
- package/coverage/lcov-report/utils/index.html +0 -146
- package/coverage/lcov-report/utils/machine-id.js.html +0 -127
- package/coverage/lcov-report/utils/url-from-segments.js.html +0 -121
- package/lib/commands/__tests__/commands.test.js +0 -20
- package/lib/commands/__tests__/commands.test.utils.js +0 -16
- package/lib/commands/actions/admin/create-user/__tests__/admin.create-user.test.js +0 -450
- package/lib/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.js +0 -145
- package/lib/commands/actions/export/__tests__/export.test.js +0 -175
- package/lib/commands/actions/import/__tests__/import.test.js +0 -143
- package/lib/commands/actions/templates/generate/__tests__/templates.generate.js +0 -118
- package/lib/commands/actions/transfer/__tests__/transfer.test.js +0 -178
- package/lib/core/registries/__tests__/custom-fields.test.js +0 -152
- package/lib/core-api/__tests__/controller.test.js +0 -39
- package/lib/core-api/controller/__tests__/transform.test.js +0 -226
- package/lib/core-api/service/__tests__/index.test.js +0 -127
- package/lib/core-api/service/__tests__/pagination.test.js +0 -275
- package/lib/load/__tests__/filepath-to-prop-path.test.js +0 -30
- package/lib/middlewares/__tests__/errors.test.js +0 -21
- package/lib/services/__tests__/content-api-permissions.test.js +0 -291
- package/lib/services/__tests__/core-store.test.js +0 -148
- package/lib/services/__tests__/event-hub.test.js +0 -126
- package/lib/services/__tests__/fs.test.js +0 -78
- package/lib/services/__tests__/worker-queue.test.js +0 -47
- package/lib/services/entity-service/__tests__/entity-service-events.test.js +0 -117
- package/lib/services/entity-service/__tests__/entity-service.test.js +0 -587
- package/lib/services/entity-validator/__tests__/biginteger-validators.test.js +0 -220
- package/lib/services/entity-validator/__tests__/date-validators.test.js +0 -183
- package/lib/services/entity-validator/__tests__/datetime-validators.test.js +0 -183
- package/lib/services/entity-validator/__tests__/email-validators.test.js +0 -56
- package/lib/services/entity-validator/__tests__/enumeration-validators.test.js +0 -43
- package/lib/services/entity-validator/__tests__/float-validators.test.js +0 -278
- package/lib/services/entity-validator/__tests__/index.test.js +0 -609
- package/lib/services/entity-validator/__tests__/integer-validators.test.js +0 -278
- package/lib/services/entity-validator/__tests__/relations/attribute-level.test.js +0 -123
- package/lib/services/entity-validator/__tests__/relations/component-level.test.js +0 -275
- package/lib/services/entity-validator/__tests__/relations/dynamic-zone-level.test.js +0 -159
- package/lib/services/entity-validator/__tests__/relations/media-level.test.js +0 -74
- package/lib/services/entity-validator/__tests__/relations/utils/relations.testdata.js +0 -153
- package/lib/services/entity-validator/__tests__/string-validators.test.js +0 -374
- package/lib/services/entity-validator/__tests__/time-validators.test.js +0 -183
- package/lib/services/entity-validator/__tests__/timestamp-validators.test.js +0 -204
- package/lib/services/entity-validator/__tests__/uid-validators.test.js +0 -229
- package/lib/services/metrics/__tests__/admin-user-hash.test.js +0 -41
- package/lib/services/metrics/__tests__/index.test.js +0 -157
- package/lib/services/metrics/__tests__/is-truthy.js +0 -33
- package/lib/services/metrics/__tests__/middleware.test.js +0 -60
- package/lib/services/metrics/__tests__/rate-limiter.test.js +0 -50
- package/lib/services/metrics/__tests__/stringify-deep.test.js +0 -27
- package/lib/utils/__tests__/convert-custom-field-type.test.js +0 -69
- package/lib/utils/__tests__/url-from-segments.test.js +0 -40
- /package/lib/commands/actions/{build → build-command}/action.js +0 -0
|
@@ -1,609 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const entityValidator = require('..');
|
|
4
|
-
|
|
5
|
-
describe('Entity validator', () => {
|
|
6
|
-
const modelBase = { uid: 'api::test.test' };
|
|
7
|
-
describe('Published input', () => {
|
|
8
|
-
describe('General Errors', () => {
|
|
9
|
-
let model;
|
|
10
|
-
global.strapi = {
|
|
11
|
-
errors: {
|
|
12
|
-
badRequest: jest.fn(),
|
|
13
|
-
},
|
|
14
|
-
getModel: () => model,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
it('Throws a badRequest error on invalid input', async () => {
|
|
18
|
-
model = {
|
|
19
|
-
...modelBase,
|
|
20
|
-
attributes: {
|
|
21
|
-
title: {
|
|
22
|
-
type: 'string',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const input = { title: 1234 };
|
|
28
|
-
|
|
29
|
-
expect.hasAssertions();
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
await entityValidator.validateEntityCreation(model, input);
|
|
33
|
-
} catch (e) {
|
|
34
|
-
expect(e).toMatchObject({
|
|
35
|
-
name: 'ValidationError',
|
|
36
|
-
message: 'title must be a `string` type, but the final value was: `1234`.',
|
|
37
|
-
details: {
|
|
38
|
-
errors: [
|
|
39
|
-
{
|
|
40
|
-
path: ['title'],
|
|
41
|
-
message: 'title must be a `string` type, but the final value was: `1234`.',
|
|
42
|
-
name: 'ValidationError',
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('Returns data on valid input', async () => {
|
|
51
|
-
model = {
|
|
52
|
-
...modelBase,
|
|
53
|
-
attributes: {
|
|
54
|
-
title: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const input = { title: 'test Title' };
|
|
61
|
-
|
|
62
|
-
expect.hasAssertions();
|
|
63
|
-
|
|
64
|
-
const data = await entityValidator.validateEntityCreation(model, input);
|
|
65
|
-
expect(data).toEqual(input);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('Returns casted data when possible', async () => {
|
|
69
|
-
model = {
|
|
70
|
-
...modelBase,
|
|
71
|
-
attributes: {
|
|
72
|
-
title: {
|
|
73
|
-
type: 'string',
|
|
74
|
-
},
|
|
75
|
-
number: {
|
|
76
|
-
type: 'integer',
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const input = { title: 'Test', number: '123' };
|
|
82
|
-
|
|
83
|
-
expect.hasAssertions();
|
|
84
|
-
|
|
85
|
-
const data = await entityValidator.validateEntityCreation(model, input);
|
|
86
|
-
expect(data).toEqual({
|
|
87
|
-
title: 'Test',
|
|
88
|
-
number: 123,
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('Throws on required not respected', async () => {
|
|
93
|
-
model = {
|
|
94
|
-
...modelBase,
|
|
95
|
-
attributes: {
|
|
96
|
-
title: {
|
|
97
|
-
type: 'string',
|
|
98
|
-
required: true,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
expect.hasAssertions();
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
await entityValidator.validateEntityCreation(model, {});
|
|
107
|
-
} catch (e) {
|
|
108
|
-
expect(e).toMatchObject({
|
|
109
|
-
name: 'ValidationError',
|
|
110
|
-
message: 'title must be defined.',
|
|
111
|
-
details: {
|
|
112
|
-
errors: [
|
|
113
|
-
{
|
|
114
|
-
path: ['title'],
|
|
115
|
-
message: 'title must be defined.',
|
|
116
|
-
name: 'ValidationError',
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
await entityValidator.validateEntityCreation(model, { title: null });
|
|
125
|
-
} catch (e) {
|
|
126
|
-
expect(e).toMatchObject({
|
|
127
|
-
name: 'ValidationError',
|
|
128
|
-
message: 'title must be a `string` type, but the final value was: `null`.',
|
|
129
|
-
details: {
|
|
130
|
-
errors: [
|
|
131
|
-
{
|
|
132
|
-
path: ['title'],
|
|
133
|
-
message: 'title must be a `string` type, but the final value was: `null`.',
|
|
134
|
-
name: 'ValidationError',
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('Supports custom field types', async () => {
|
|
143
|
-
model = {
|
|
144
|
-
...modelBase,
|
|
145
|
-
attributes: {
|
|
146
|
-
uuid: {
|
|
147
|
-
type: 'uuid',
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const input = { uuid: '2479d6d7-2497-478d-8a34-a9e8ce45f8a7' };
|
|
153
|
-
|
|
154
|
-
expect.hasAssertions();
|
|
155
|
-
|
|
156
|
-
const data = await entityValidator.validateEntityCreation(model, input);
|
|
157
|
-
expect(data).toEqual({
|
|
158
|
-
uuid: '2479d6d7-2497-478d-8a34-a9e8ce45f8a7',
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe('String validator', () => {
|
|
164
|
-
test('Throws on min length not respected', async () => {
|
|
165
|
-
global.strapi = {
|
|
166
|
-
errors: {
|
|
167
|
-
badRequest: jest.fn(),
|
|
168
|
-
},
|
|
169
|
-
getModel: () => model,
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const model = {
|
|
173
|
-
...modelBase,
|
|
174
|
-
attributes: {
|
|
175
|
-
title: {
|
|
176
|
-
type: 'string',
|
|
177
|
-
minLength: 10,
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const input = { title: 'tooSmall' };
|
|
183
|
-
|
|
184
|
-
expect.hasAssertions();
|
|
185
|
-
|
|
186
|
-
try {
|
|
187
|
-
await entityValidator.validateEntityCreation(model, input);
|
|
188
|
-
} catch (e) {
|
|
189
|
-
expect(e).toMatchObject({
|
|
190
|
-
name: 'ValidationError',
|
|
191
|
-
message: 'title must be at least 10 characters',
|
|
192
|
-
details: {
|
|
193
|
-
errors: [
|
|
194
|
-
{
|
|
195
|
-
path: ['title'],
|
|
196
|
-
message: 'title must be at least 10 characters',
|
|
197
|
-
name: 'ValidationError',
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test('Throws on max length not respected', async () => {
|
|
206
|
-
const model = {
|
|
207
|
-
...modelBase,
|
|
208
|
-
attributes: {
|
|
209
|
-
title: {
|
|
210
|
-
type: 'string',
|
|
211
|
-
maxLength: 2,
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const input = { title: 'tooLong' };
|
|
217
|
-
|
|
218
|
-
expect.hasAssertions();
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
await entityValidator.validateEntityCreation(model, input);
|
|
222
|
-
} catch (e) {
|
|
223
|
-
expect(e).toMatchObject({
|
|
224
|
-
name: 'ValidationError',
|
|
225
|
-
message: 'title must be at most 2 characters',
|
|
226
|
-
details: {
|
|
227
|
-
errors: [
|
|
228
|
-
{
|
|
229
|
-
path: ['title'],
|
|
230
|
-
message: 'title must be at most 2 characters',
|
|
231
|
-
name: 'ValidationError',
|
|
232
|
-
},
|
|
233
|
-
],
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
test('Allows empty strings even when required', async () => {
|
|
240
|
-
const model = {
|
|
241
|
-
...modelBase,
|
|
242
|
-
attributes: {
|
|
243
|
-
title: {
|
|
244
|
-
type: 'string',
|
|
245
|
-
required: true,
|
|
246
|
-
},
|
|
247
|
-
},
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const input = { title: '' };
|
|
251
|
-
|
|
252
|
-
expect.hasAssertions();
|
|
253
|
-
|
|
254
|
-
const data = await entityValidator.validateEntityCreation(model, input);
|
|
255
|
-
expect(data).toEqual(input);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test('Assign default values', async () => {
|
|
259
|
-
const model = {
|
|
260
|
-
...modelBase,
|
|
261
|
-
attributes: {
|
|
262
|
-
title: {
|
|
263
|
-
type: 'string',
|
|
264
|
-
required: true,
|
|
265
|
-
default: 'New',
|
|
266
|
-
},
|
|
267
|
-
type: {
|
|
268
|
-
type: 'string',
|
|
269
|
-
default: 'test',
|
|
270
|
-
},
|
|
271
|
-
testDate: {
|
|
272
|
-
type: 'date',
|
|
273
|
-
required: true,
|
|
274
|
-
default: '2020-04-01T04:00:00.000Z',
|
|
275
|
-
},
|
|
276
|
-
testJSON: {
|
|
277
|
-
type: 'date',
|
|
278
|
-
required: true,
|
|
279
|
-
default: {
|
|
280
|
-
foo: 1,
|
|
281
|
-
bar: 2,
|
|
282
|
-
},
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
await expect(entityValidator.validateEntityCreation(model, {})).resolves.toMatchObject({
|
|
288
|
-
title: 'New',
|
|
289
|
-
type: 'test',
|
|
290
|
-
testDate: '2020-04-01T04:00:00.000Z',
|
|
291
|
-
testJSON: {
|
|
292
|
-
foo: 1,
|
|
293
|
-
bar: 2,
|
|
294
|
-
},
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test("Don't assign default value if empty string", async () => {
|
|
299
|
-
const model = {
|
|
300
|
-
...modelBase,
|
|
301
|
-
attributes: {
|
|
302
|
-
title: {
|
|
303
|
-
type: 'string',
|
|
304
|
-
required: true,
|
|
305
|
-
default: 'default',
|
|
306
|
-
},
|
|
307
|
-
content: {
|
|
308
|
-
type: 'string',
|
|
309
|
-
default: 'default',
|
|
310
|
-
},
|
|
311
|
-
},
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
await expect(
|
|
315
|
-
entityValidator.validateEntityCreation(model, {
|
|
316
|
-
title: '',
|
|
317
|
-
content: '',
|
|
318
|
-
})
|
|
319
|
-
).resolves.toMatchObject({
|
|
320
|
-
title: '',
|
|
321
|
-
content: '',
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
describe('Draft input', () => {
|
|
328
|
-
describe('General Errors', () => {
|
|
329
|
-
it('Throws a badRequest error on invalid input', async () => {
|
|
330
|
-
global.strapi = {
|
|
331
|
-
errors: {
|
|
332
|
-
badRequest: jest.fn(),
|
|
333
|
-
},
|
|
334
|
-
getModel: () => model,
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
const model = {
|
|
338
|
-
...modelBase,
|
|
339
|
-
attributes: {
|
|
340
|
-
title: {
|
|
341
|
-
type: 'string',
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
const input = { title: 1234 };
|
|
347
|
-
|
|
348
|
-
expect.hasAssertions();
|
|
349
|
-
|
|
350
|
-
try {
|
|
351
|
-
await entityValidator.validateEntityCreation(model, input, { isDraft: true });
|
|
352
|
-
} catch (e) {
|
|
353
|
-
expect(e).toMatchObject({
|
|
354
|
-
name: 'ValidationError',
|
|
355
|
-
message: 'title must be a `string` type, but the final value was: `1234`.',
|
|
356
|
-
details: {
|
|
357
|
-
errors: [
|
|
358
|
-
{
|
|
359
|
-
path: ['title'],
|
|
360
|
-
message: 'title must be a `string` type, but the final value was: `1234`.',
|
|
361
|
-
name: 'ValidationError',
|
|
362
|
-
},
|
|
363
|
-
],
|
|
364
|
-
},
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it('Returns data on valid input', async () => {
|
|
370
|
-
const model = {
|
|
371
|
-
...modelBase,
|
|
372
|
-
attributes: {
|
|
373
|
-
title: {
|
|
374
|
-
type: 'string',
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
const input = { title: 'test Title' };
|
|
380
|
-
|
|
381
|
-
expect.hasAssertions();
|
|
382
|
-
|
|
383
|
-
const data = await entityValidator.validateEntityCreation(model, input, { isDraft: true });
|
|
384
|
-
expect(data).toEqual(input);
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it('Returns casted data when possible', async () => {
|
|
388
|
-
const model = {
|
|
389
|
-
...modelBase,
|
|
390
|
-
attributes: {
|
|
391
|
-
title: {
|
|
392
|
-
type: 'string',
|
|
393
|
-
},
|
|
394
|
-
number: {
|
|
395
|
-
type: 'integer',
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const input = { title: 'Test', number: '123' };
|
|
401
|
-
|
|
402
|
-
expect.hasAssertions();
|
|
403
|
-
|
|
404
|
-
const data = await entityValidator.validateEntityCreation(model, input, { isDraft: true });
|
|
405
|
-
expect(data).toEqual({
|
|
406
|
-
title: 'Test',
|
|
407
|
-
number: 123,
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
test('Does not throws on required not respected', async () => {
|
|
412
|
-
const model = {
|
|
413
|
-
...modelBase,
|
|
414
|
-
attributes: {
|
|
415
|
-
title: {
|
|
416
|
-
type: 'string',
|
|
417
|
-
required: true,
|
|
418
|
-
},
|
|
419
|
-
},
|
|
420
|
-
};
|
|
421
|
-
|
|
422
|
-
expect.hasAssertions();
|
|
423
|
-
|
|
424
|
-
let data = await entityValidator.validateEntityCreation(model, {}, { isDraft: true });
|
|
425
|
-
expect(data).toEqual({});
|
|
426
|
-
|
|
427
|
-
data = await entityValidator.validateEntityCreation(
|
|
428
|
-
model,
|
|
429
|
-
{ title: null },
|
|
430
|
-
{ isDraft: true }
|
|
431
|
-
);
|
|
432
|
-
expect(data).toEqual({ title: null });
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it('Supports custom field types', async () => {
|
|
436
|
-
const model = {
|
|
437
|
-
...modelBase,
|
|
438
|
-
attributes: {
|
|
439
|
-
uuid: {
|
|
440
|
-
type: 'uuid',
|
|
441
|
-
},
|
|
442
|
-
},
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
const input = { uuid: '2479d6d7-2497-478d-8a34-a9e8ce45f8a7' };
|
|
446
|
-
|
|
447
|
-
expect.hasAssertions();
|
|
448
|
-
|
|
449
|
-
const data = await entityValidator.validateEntityCreation(model, input, { isDraft: true });
|
|
450
|
-
expect(data).toEqual({
|
|
451
|
-
uuid: '2479d6d7-2497-478d-8a34-a9e8ce45f8a7',
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
describe('String validator', () => {
|
|
457
|
-
test('Does not throws on min length not respected', async () => {
|
|
458
|
-
const model = {
|
|
459
|
-
...modelBase,
|
|
460
|
-
attributes: {
|
|
461
|
-
title: {
|
|
462
|
-
type: 'string',
|
|
463
|
-
minLength: 10,
|
|
464
|
-
},
|
|
465
|
-
},
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
global.strapi = {
|
|
469
|
-
errors: {
|
|
470
|
-
badRequest: jest.fn(),
|
|
471
|
-
},
|
|
472
|
-
getModel: () => model,
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
const input = { title: 'tooSmall' };
|
|
476
|
-
|
|
477
|
-
expect.hasAssertions();
|
|
478
|
-
|
|
479
|
-
const data = await entityValidator.validateEntityCreation(model, input, { isDraft: true });
|
|
480
|
-
expect(data).toEqual(input);
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
test('Throws on max length not respected', async () => {
|
|
484
|
-
const model = {
|
|
485
|
-
...modelBase,
|
|
486
|
-
attributes: {
|
|
487
|
-
title: {
|
|
488
|
-
type: 'string',
|
|
489
|
-
maxLength: 2,
|
|
490
|
-
},
|
|
491
|
-
},
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
const input = { title: 'tooLong' };
|
|
495
|
-
|
|
496
|
-
expect.hasAssertions();
|
|
497
|
-
|
|
498
|
-
try {
|
|
499
|
-
await entityValidator.validateEntityCreation(model, input, { isDraft: true });
|
|
500
|
-
} catch (e) {
|
|
501
|
-
expect(e).toMatchObject({
|
|
502
|
-
name: 'ValidationError',
|
|
503
|
-
message: 'title must be at most 2 characters',
|
|
504
|
-
details: {
|
|
505
|
-
errors: [
|
|
506
|
-
{
|
|
507
|
-
path: ['title'],
|
|
508
|
-
message: 'title must be at most 2 characters',
|
|
509
|
-
name: 'ValidationError',
|
|
510
|
-
},
|
|
511
|
-
],
|
|
512
|
-
},
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
test('Allows empty strings even when required', async () => {
|
|
518
|
-
const model = {
|
|
519
|
-
...modelBase,
|
|
520
|
-
attributes: {
|
|
521
|
-
title: {
|
|
522
|
-
type: 'string',
|
|
523
|
-
},
|
|
524
|
-
},
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
const input = { title: '' };
|
|
528
|
-
|
|
529
|
-
expect.hasAssertions();
|
|
530
|
-
|
|
531
|
-
const data = await entityValidator.validateEntityCreation(model, input, { isDraft: true });
|
|
532
|
-
expect(data).toEqual(input);
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
test('Assign default values', async () => {
|
|
536
|
-
const model = {
|
|
537
|
-
...modelBase,
|
|
538
|
-
attributes: {
|
|
539
|
-
title: {
|
|
540
|
-
type: 'string',
|
|
541
|
-
required: true,
|
|
542
|
-
default: 'New',
|
|
543
|
-
},
|
|
544
|
-
type: {
|
|
545
|
-
type: 'string',
|
|
546
|
-
default: 'test',
|
|
547
|
-
},
|
|
548
|
-
testDate: {
|
|
549
|
-
type: 'date',
|
|
550
|
-
required: true,
|
|
551
|
-
default: '2020-04-01T04:00:00.000Z',
|
|
552
|
-
},
|
|
553
|
-
testJSON: {
|
|
554
|
-
type: 'date',
|
|
555
|
-
required: true,
|
|
556
|
-
default: {
|
|
557
|
-
foo: 1,
|
|
558
|
-
bar: 2,
|
|
559
|
-
},
|
|
560
|
-
},
|
|
561
|
-
},
|
|
562
|
-
};
|
|
563
|
-
|
|
564
|
-
await expect(
|
|
565
|
-
entityValidator.validateEntityCreation(model, {}, { isDraft: true })
|
|
566
|
-
).resolves.toMatchObject({
|
|
567
|
-
title: 'New',
|
|
568
|
-
type: 'test',
|
|
569
|
-
testDate: '2020-04-01T04:00:00.000Z',
|
|
570
|
-
testJSON: {
|
|
571
|
-
foo: 1,
|
|
572
|
-
bar: 2,
|
|
573
|
-
},
|
|
574
|
-
});
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
test("Don't assign default value if empty string", async () => {
|
|
578
|
-
const model = {
|
|
579
|
-
...modelBase,
|
|
580
|
-
attributes: {
|
|
581
|
-
title: {
|
|
582
|
-
type: 'string',
|
|
583
|
-
required: true,
|
|
584
|
-
default: 'default',
|
|
585
|
-
},
|
|
586
|
-
content: {
|
|
587
|
-
type: 'string',
|
|
588
|
-
default: 'default',
|
|
589
|
-
},
|
|
590
|
-
},
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
-
await expect(
|
|
594
|
-
entityValidator.validateEntityCreation(
|
|
595
|
-
model,
|
|
596
|
-
{
|
|
597
|
-
title: '',
|
|
598
|
-
content: '',
|
|
599
|
-
},
|
|
600
|
-
{ isDraft: true }
|
|
601
|
-
)
|
|
602
|
-
).resolves.toMatchObject({
|
|
603
|
-
title: '',
|
|
604
|
-
content: '',
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
});
|