@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,278 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const strapiUtils = require('@strapi/utils');
|
|
4
|
-
const {
|
|
5
|
-
errors: { YupValidationError },
|
|
6
|
-
} = require('@strapi/utils');
|
|
7
|
-
const validators = require('../validators');
|
|
8
|
-
|
|
9
|
-
describe('Integer validator', () => {
|
|
10
|
-
describe('unique', () => {
|
|
11
|
-
const fakeFindOne = jest.fn();
|
|
12
|
-
|
|
13
|
-
global.strapi = {
|
|
14
|
-
db: {
|
|
15
|
-
query: jest.fn(() => ({
|
|
16
|
-
findOne: fakeFindOne,
|
|
17
|
-
})),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
jest.clearAllMocks();
|
|
23
|
-
fakeFindOne.mockReset();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const fakeModel = {
|
|
27
|
-
kind: 'contentType',
|
|
28
|
-
uid: 'test-uid',
|
|
29
|
-
modelName: 'test-model',
|
|
30
|
-
privateAttributes: [],
|
|
31
|
-
options: {},
|
|
32
|
-
attributes: {
|
|
33
|
-
attrIntegerUnique: { type: 'integer', unique: true },
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
test('it does not validates the unique constraint if the attribute is not set as unique', async () => {
|
|
38
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
39
|
-
|
|
40
|
-
const validator = strapiUtils.validateYupSchema(
|
|
41
|
-
validators.integer(
|
|
42
|
-
{
|
|
43
|
-
attr: { type: 'integer' },
|
|
44
|
-
model: fakeModel,
|
|
45
|
-
updatedAttribute: { name: 'attrIntegerUnique', value: 1 },
|
|
46
|
-
entity: null,
|
|
47
|
-
},
|
|
48
|
-
{ isDraft: false }
|
|
49
|
-
)
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
await validator(1);
|
|
53
|
-
|
|
54
|
-
expect(fakeFindOne).not.toHaveBeenCalled();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('it does not validates the unique constraint if the attribute value is `null`', async () => {
|
|
58
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
59
|
-
|
|
60
|
-
const validator = strapiUtils.validateYupSchema(
|
|
61
|
-
validators
|
|
62
|
-
.integer(
|
|
63
|
-
{
|
|
64
|
-
attr: { type: 'integer', unique: true },
|
|
65
|
-
model: fakeModel,
|
|
66
|
-
updatedAttribute: { name: 'attrIntegerUnique', value: null },
|
|
67
|
-
entity: null,
|
|
68
|
-
},
|
|
69
|
-
{ isDraft: false }
|
|
70
|
-
)
|
|
71
|
-
.nullable()
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
await validator(null);
|
|
75
|
-
|
|
76
|
-
expect(fakeFindOne).not.toHaveBeenCalled();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('it validates the unique constraint if there is no other record in the database', async () => {
|
|
80
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
81
|
-
|
|
82
|
-
const validator = strapiUtils.validateYupSchema(
|
|
83
|
-
validators.integer(
|
|
84
|
-
{
|
|
85
|
-
attr: { type: 'integer', unique: true },
|
|
86
|
-
model: fakeModel,
|
|
87
|
-
updatedAttribute: { name: 'attrIntegerUnique', value: 2 },
|
|
88
|
-
entity: null,
|
|
89
|
-
},
|
|
90
|
-
{ isDraft: false }
|
|
91
|
-
)
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
expect(await validator(1)).toBe(1);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test('it fails the validation of the unique constraint if the database contains a record with the same attribute value', async () => {
|
|
98
|
-
expect.assertions(1);
|
|
99
|
-
fakeFindOne.mockResolvedValueOnce({ attrIntegerUnique: 2 });
|
|
100
|
-
|
|
101
|
-
const validator = strapiUtils.validateYupSchema(
|
|
102
|
-
validators.integer(
|
|
103
|
-
{
|
|
104
|
-
attr: { type: 'integer', unique: true },
|
|
105
|
-
model: fakeModel,
|
|
106
|
-
updatedAttribute: { name: 'attrIntegerUnique', value: 2 },
|
|
107
|
-
entity: null,
|
|
108
|
-
},
|
|
109
|
-
{ isDraft: false }
|
|
110
|
-
)
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
await validator(2);
|
|
115
|
-
} catch (err) {
|
|
116
|
-
expect(err).toBeInstanceOf(YupValidationError);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test('it validates the unique constraint if the attribute data has not changed even if there is a record in the database with the same attribute value', async () => {
|
|
121
|
-
fakeFindOne.mockResolvedValueOnce({ attrIntegerUnique: 3 });
|
|
122
|
-
|
|
123
|
-
const validator = strapiUtils.validateYupSchema(
|
|
124
|
-
validators.integer(
|
|
125
|
-
{
|
|
126
|
-
attr: { type: 'integer', unique: true },
|
|
127
|
-
model: fakeModel,
|
|
128
|
-
updatedAttribute: { name: 'attrIntegerUnique', value: 3 },
|
|
129
|
-
entity: { id: 1, attrIntegerUnique: 3 },
|
|
130
|
-
},
|
|
131
|
-
{ isDraft: false }
|
|
132
|
-
)
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
expect(await validator(3)).toBe(3);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test('it checks the database for records with the same value for the checked attribute', async () => {
|
|
139
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
140
|
-
|
|
141
|
-
const validator = strapiUtils.validateYupSchema(
|
|
142
|
-
validators.integer(
|
|
143
|
-
{
|
|
144
|
-
attr: { type: 'integer', unique: true },
|
|
145
|
-
model: fakeModel,
|
|
146
|
-
updatedAttribute: { name: 'attrIntegerUnique', value: 4 },
|
|
147
|
-
entity: null,
|
|
148
|
-
},
|
|
149
|
-
{ isDraft: false }
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
await validator(4);
|
|
154
|
-
|
|
155
|
-
expect(fakeFindOne).toHaveBeenCalledWith({
|
|
156
|
-
select: ['id'],
|
|
157
|
-
where: { attrIntegerUnique: 4 },
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
test('it checks the database for records with the same value but not the same id for the checked attribute if an entity is passed', async () => {
|
|
162
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
163
|
-
|
|
164
|
-
const validator = strapiUtils.validateYupSchema(
|
|
165
|
-
validators.integer(
|
|
166
|
-
{
|
|
167
|
-
attr: { type: 'integer', unique: true },
|
|
168
|
-
model: fakeModel,
|
|
169
|
-
updatedAttribute: { name: 'attrIntegerUnique', value: 5 },
|
|
170
|
-
entity: { id: 1, attrIntegerUnique: 42 },
|
|
171
|
-
},
|
|
172
|
-
{ isDraft: false }
|
|
173
|
-
)
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
await validator(5);
|
|
177
|
-
|
|
178
|
-
expect(fakeFindOne).toHaveBeenCalledWith({
|
|
179
|
-
select: ['id'],
|
|
180
|
-
where: { $and: [{ attrIntegerUnique: 5 }, { $not: { id: 1 } }] },
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
describe('min', () => {
|
|
186
|
-
test('it does not validates the min constraint if the attribute min is not a number', async () => {
|
|
187
|
-
const validator = strapiUtils.validateYupSchema(
|
|
188
|
-
validators.integer(
|
|
189
|
-
{
|
|
190
|
-
attr: { type: 'integer', minLength: '123' },
|
|
191
|
-
},
|
|
192
|
-
{ isDraft: false }
|
|
193
|
-
)
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
expect(await validator(1)).toBe(1);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
test('it fails the validation if the integer is lower than the define min', async () => {
|
|
200
|
-
expect.assertions(1);
|
|
201
|
-
|
|
202
|
-
const validator = strapiUtils.validateYupSchema(
|
|
203
|
-
validators.integer(
|
|
204
|
-
{
|
|
205
|
-
attr: { type: 'integer', min: 3 },
|
|
206
|
-
},
|
|
207
|
-
{ isDraft: false }
|
|
208
|
-
)
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
try {
|
|
212
|
-
await validator(1);
|
|
213
|
-
} catch (err) {
|
|
214
|
-
expect(err).toBeInstanceOf(YupValidationError);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test('it validates the min constraint if the integer is higher than the define min', async () => {
|
|
219
|
-
const validator = strapiUtils.validateYupSchema(
|
|
220
|
-
validators.integer(
|
|
221
|
-
{
|
|
222
|
-
attr: { type: 'integer', min: 3 },
|
|
223
|
-
},
|
|
224
|
-
{ isDraft: false }
|
|
225
|
-
)
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
expect(await validator(4)).toBe(4);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
describe('max', () => {
|
|
233
|
-
test('it does not validates the max constraint if the attribute max is not an integer', async () => {
|
|
234
|
-
const validator = strapiUtils.validateYupSchema(
|
|
235
|
-
validators.integer(
|
|
236
|
-
{
|
|
237
|
-
attr: { type: 'integer', maxLength: '123' },
|
|
238
|
-
},
|
|
239
|
-
{ isDraft: false }
|
|
240
|
-
)
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
expect(await validator(1)).toBe(1);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
test('it fails the validation if the number is integer than the define max', async () => {
|
|
247
|
-
expect.assertions(1);
|
|
248
|
-
|
|
249
|
-
const validator = strapiUtils.validateYupSchema(
|
|
250
|
-
validators.integer(
|
|
251
|
-
{
|
|
252
|
-
attr: { type: 'integer', max: 3 },
|
|
253
|
-
},
|
|
254
|
-
{ isDraft: false }
|
|
255
|
-
)
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
try {
|
|
259
|
-
await validator(4);
|
|
260
|
-
} catch (err) {
|
|
261
|
-
expect(err).toBeInstanceOf(YupValidationError);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test('it validates the max constraint if the integer is lower than the define max', async () => {
|
|
266
|
-
const validator = strapiUtils.validateYupSchema(
|
|
267
|
-
validators.integer(
|
|
268
|
-
{
|
|
269
|
-
attr: { type: 'integer', max: 3 },
|
|
270
|
-
},
|
|
271
|
-
{ isDraft: false }
|
|
272
|
-
)
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
expect(await validator(2)).toBe(2);
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { ValidationError } = require('@strapi/utils').errors;
|
|
4
|
-
|
|
5
|
-
const entityValidator = require('../..');
|
|
6
|
-
const { models, existentIDs, nonExistentIds } = require('./utils/relations.testdata');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Test that relations can be successfully validated and non existent relations
|
|
10
|
-
* can be detected at the Attribute level.
|
|
11
|
-
*/
|
|
12
|
-
describe('Entity validator | Relations | Attribute', () => {
|
|
13
|
-
const strapi = {
|
|
14
|
-
components: {
|
|
15
|
-
'basic.dev-compo': {},
|
|
16
|
-
},
|
|
17
|
-
db: {
|
|
18
|
-
query() {
|
|
19
|
-
return {
|
|
20
|
-
count: ({
|
|
21
|
-
where: {
|
|
22
|
-
id: { $in },
|
|
23
|
-
},
|
|
24
|
-
}) => existentIDs.filter((value) => $in.includes(value)).length,
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
errors: {
|
|
29
|
-
badRequest: jest.fn(),
|
|
30
|
-
},
|
|
31
|
-
getModel: (uid) => models.get(uid),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
describe('Success', () => {
|
|
35
|
-
const testData = [
|
|
36
|
-
[
|
|
37
|
-
'Connect',
|
|
38
|
-
{
|
|
39
|
-
categories: {
|
|
40
|
-
disconnect: [],
|
|
41
|
-
connect: [
|
|
42
|
-
{
|
|
43
|
-
id: existentIDs[0],
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
[
|
|
50
|
-
'Set',
|
|
51
|
-
{
|
|
52
|
-
categories: {
|
|
53
|
-
set: [
|
|
54
|
-
{
|
|
55
|
-
id: existentIDs[0],
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
[
|
|
62
|
-
'Number',
|
|
63
|
-
{
|
|
64
|
-
categories: existentIDs[0],
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
[
|
|
68
|
-
'Array',
|
|
69
|
-
{
|
|
70
|
-
categories: existentIDs.slice(-Math.floor(existentIDs.length / 2)),
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
];
|
|
74
|
-
test.each(testData)('%s', async (__, input = {}) => {
|
|
75
|
-
global.strapi = strapi;
|
|
76
|
-
const res = entityValidator.validateEntityCreation(models.get('api::dev.dev'), input, {
|
|
77
|
-
isDraft: true,
|
|
78
|
-
});
|
|
79
|
-
await expect(res).resolves.not.toThrowError();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('Error', () => {
|
|
84
|
-
const expectError = new ValidationError(
|
|
85
|
-
`2 relation(s) of type api::category.category associated with this entity do not exist`
|
|
86
|
-
);
|
|
87
|
-
const testData = [
|
|
88
|
-
[
|
|
89
|
-
'Connect',
|
|
90
|
-
{
|
|
91
|
-
categories: {
|
|
92
|
-
disconnect: [],
|
|
93
|
-
connect: [existentIDs[0], ...nonExistentIds.slice(-2)].map((id) => ({
|
|
94
|
-
id,
|
|
95
|
-
})),
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
[
|
|
100
|
-
'Set',
|
|
101
|
-
{
|
|
102
|
-
categories: {
|
|
103
|
-
set: [existentIDs[0], ...nonExistentIds.slice(-2)].map((id) => ({ id })),
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
[
|
|
108
|
-
'Number',
|
|
109
|
-
{
|
|
110
|
-
categories: nonExistentIds.slice(-2),
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
];
|
|
114
|
-
|
|
115
|
-
test.each(testData)('%s', async (__, input = {}) => {
|
|
116
|
-
global.strapi = strapi;
|
|
117
|
-
const res = entityValidator.validateEntityCreation(models.get('api::dev.dev'), input, {
|
|
118
|
-
isDraft: true,
|
|
119
|
-
});
|
|
120
|
-
await expect(res).rejects.toThrowError(expectError);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { ValidationError } = require('@strapi/utils').errors;
|
|
4
|
-
|
|
5
|
-
const entityValidator = require('../..');
|
|
6
|
-
const { models, nonExistentIds, existentIDs } = require('./utils/relations.testdata');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Test that relations can be successfully validated and non existent relations
|
|
10
|
-
* can be detected at the Component level.
|
|
11
|
-
*/
|
|
12
|
-
describe('Entity validator | Relations | Component Level', () => {
|
|
13
|
-
const strapi = {
|
|
14
|
-
components: {
|
|
15
|
-
'basic.dev-compo': {},
|
|
16
|
-
},
|
|
17
|
-
db: {
|
|
18
|
-
query() {
|
|
19
|
-
return {
|
|
20
|
-
count: ({
|
|
21
|
-
where: {
|
|
22
|
-
id: { $in },
|
|
23
|
-
},
|
|
24
|
-
}) => existentIDs.filter((value) => $in.includes(value)).length,
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
errors: {
|
|
29
|
-
badRequest: jest.fn(),
|
|
30
|
-
},
|
|
31
|
-
getModel: (uid) => models.get(uid),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
describe('Single Component', () => {
|
|
35
|
-
describe('Success', () => {
|
|
36
|
-
const testData = [
|
|
37
|
-
[
|
|
38
|
-
'Connect',
|
|
39
|
-
{
|
|
40
|
-
sCom: {
|
|
41
|
-
categories: {
|
|
42
|
-
disconnect: [],
|
|
43
|
-
connect: [
|
|
44
|
-
{
|
|
45
|
-
id: existentIDs[0],
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
[
|
|
53
|
-
'Set',
|
|
54
|
-
{
|
|
55
|
-
sCom: {
|
|
56
|
-
categories: {
|
|
57
|
-
set: [
|
|
58
|
-
{
|
|
59
|
-
id: existentIDs[0],
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
[
|
|
67
|
-
'Number',
|
|
68
|
-
{
|
|
69
|
-
sCom: {
|
|
70
|
-
categories: existentIDs[0],
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
[
|
|
75
|
-
'Array',
|
|
76
|
-
{
|
|
77
|
-
sCom: {
|
|
78
|
-
categories: existentIDs.slice(-3),
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
test.each(testData)('%s', async (__, input = {}) => {
|
|
85
|
-
global.strapi = strapi;
|
|
86
|
-
const res = entityValidator.validateEntityCreation(models.get('api::dev.dev'), input, {
|
|
87
|
-
isDraft: true,
|
|
88
|
-
});
|
|
89
|
-
await expect(res).resolves.not.toThrowError();
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe('Error', () => {
|
|
94
|
-
const expectedError = new ValidationError(
|
|
95
|
-
`1 relation(s) of type api::category.category associated with this entity do not exist`
|
|
96
|
-
);
|
|
97
|
-
const testData = [
|
|
98
|
-
[
|
|
99
|
-
'Connect',
|
|
100
|
-
{
|
|
101
|
-
sCom: {
|
|
102
|
-
categories: {
|
|
103
|
-
disconnect: [],
|
|
104
|
-
connect: [
|
|
105
|
-
{
|
|
106
|
-
id: nonExistentIds[0],
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
[
|
|
114
|
-
'Set',
|
|
115
|
-
{
|
|
116
|
-
sCom: {
|
|
117
|
-
categories: {
|
|
118
|
-
set: [
|
|
119
|
-
{
|
|
120
|
-
id: nonExistentIds[0],
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
[
|
|
128
|
-
'Number',
|
|
129
|
-
{
|
|
130
|
-
sCom: {
|
|
131
|
-
categories: nonExistentIds[0],
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
[
|
|
136
|
-
'Array',
|
|
137
|
-
{
|
|
138
|
-
sCom: {
|
|
139
|
-
categories: [nonExistentIds[0]],
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
];
|
|
144
|
-
|
|
145
|
-
test.each(testData)('%s', async (__, input = {}) => {
|
|
146
|
-
global.strapi = strapi;
|
|
147
|
-
const res = entityValidator.validateEntityCreation(models.get('api::dev.dev'), input, {
|
|
148
|
-
isDraft: true,
|
|
149
|
-
});
|
|
150
|
-
await expect(res).rejects.toThrowError(expectedError);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe('Repeatable Component', () => {
|
|
156
|
-
describe('Success', () => {
|
|
157
|
-
const testData = [
|
|
158
|
-
[
|
|
159
|
-
'Connect',
|
|
160
|
-
{
|
|
161
|
-
rCom: [
|
|
162
|
-
{
|
|
163
|
-
categories: {
|
|
164
|
-
disconnect: [],
|
|
165
|
-
connect: [
|
|
166
|
-
{
|
|
167
|
-
id: existentIDs[0],
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
[
|
|
176
|
-
'Set',
|
|
177
|
-
{
|
|
178
|
-
rCom: [
|
|
179
|
-
{
|
|
180
|
-
categories: {
|
|
181
|
-
set: existentIDs.slice(-Math.floor(existentIDs.length / 2)).map((id) => ({
|
|
182
|
-
id,
|
|
183
|
-
})),
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
],
|
|
187
|
-
},
|
|
188
|
-
],
|
|
189
|
-
[
|
|
190
|
-
'Number',
|
|
191
|
-
{
|
|
192
|
-
rCom: [
|
|
193
|
-
{
|
|
194
|
-
categories: existentIDs[0],
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
[
|
|
200
|
-
'Array',
|
|
201
|
-
{
|
|
202
|
-
rCom: [
|
|
203
|
-
{
|
|
204
|
-
categories: existentIDs.slice(-Math.floor(existentIDs.length / 2)),
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
},
|
|
208
|
-
],
|
|
209
|
-
];
|
|
210
|
-
|
|
211
|
-
test.each(testData)('%s', async (__, input = {}) => {
|
|
212
|
-
global.strapi = strapi;
|
|
213
|
-
const res = entityValidator.validateEntityCreation(models.get('api::dev.dev'), input, {
|
|
214
|
-
isDraft: true,
|
|
215
|
-
});
|
|
216
|
-
await expect(res).resolves.not.toThrowError();
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
describe('Error', () => {
|
|
221
|
-
const expectedError = new ValidationError(
|
|
222
|
-
`4 relation(s) of type api::category.category associated with this entity do not exist`
|
|
223
|
-
);
|
|
224
|
-
const testData = [
|
|
225
|
-
[
|
|
226
|
-
'Connect',
|
|
227
|
-
{
|
|
228
|
-
rCom: [
|
|
229
|
-
{
|
|
230
|
-
categories: {
|
|
231
|
-
disconnect: [],
|
|
232
|
-
connect: [existentIDs[0], ...nonExistentIds.slice(-4)].map((id) => ({
|
|
233
|
-
id,
|
|
234
|
-
})),
|
|
235
|
-
},
|
|
236
|
-
},
|
|
237
|
-
],
|
|
238
|
-
},
|
|
239
|
-
],
|
|
240
|
-
[
|
|
241
|
-
'Set',
|
|
242
|
-
{
|
|
243
|
-
rCom: [
|
|
244
|
-
{
|
|
245
|
-
categories: {
|
|
246
|
-
set: [existentIDs[0], ...nonExistentIds.slice(-4)].map((id) => ({
|
|
247
|
-
id,
|
|
248
|
-
})),
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
],
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
[
|
|
255
|
-
'Array',
|
|
256
|
-
{
|
|
257
|
-
rCom: [
|
|
258
|
-
{
|
|
259
|
-
categories: nonExistentIds.slice(-4),
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
},
|
|
263
|
-
],
|
|
264
|
-
];
|
|
265
|
-
|
|
266
|
-
test.each(testData)('%s', async (__, input = {}) => {
|
|
267
|
-
global.strapi = strapi;
|
|
268
|
-
const res = entityValidator.validateEntityCreation(models.get('api::dev.dev'), input, {
|
|
269
|
-
isDraft: true,
|
|
270
|
-
});
|
|
271
|
-
await expect(res).rejects.toThrowError(expectedError);
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
});
|