@strapi/strapi 4.10.1 → 4.10.2
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/develop/action.js +22 -3
- 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,204 +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('Time 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
|
-
modelName: 'test-model',
|
|
29
|
-
uid: 'test-uid',
|
|
30
|
-
privateAttributes: [],
|
|
31
|
-
options: {},
|
|
32
|
-
attributes: {
|
|
33
|
-
attrTimestampUnique: { type: 'timestamp', 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.timestamp(
|
|
42
|
-
{
|
|
43
|
-
attr: { type: 'timestamp' },
|
|
44
|
-
model: fakeModel,
|
|
45
|
-
updatedAttribute: {
|
|
46
|
-
name: 'attrTimestampUnique',
|
|
47
|
-
value: '1638140400',
|
|
48
|
-
},
|
|
49
|
-
entity: null,
|
|
50
|
-
},
|
|
51
|
-
{ isDraft: false }
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
await validator('1638140400');
|
|
56
|
-
|
|
57
|
-
expect(fakeFindOne).not.toHaveBeenCalled();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('it does not validates the unique constraint if the attribute value is `null`', async () => {
|
|
61
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
62
|
-
|
|
63
|
-
const validator = strapiUtils.validateYupSchema(
|
|
64
|
-
validators
|
|
65
|
-
.timestamp(
|
|
66
|
-
{
|
|
67
|
-
attr: { type: 'timestamp', unique: true },
|
|
68
|
-
model: fakeModel,
|
|
69
|
-
updatedAttribute: {
|
|
70
|
-
name: 'attrTimestampUnique',
|
|
71
|
-
value: null,
|
|
72
|
-
},
|
|
73
|
-
entity: null,
|
|
74
|
-
},
|
|
75
|
-
{ isDraft: false }
|
|
76
|
-
)
|
|
77
|
-
.nullable()
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
await validator(null);
|
|
81
|
-
expect(fakeFindOne).not.toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('it validates the unique constraint if there is no other record in the database', async () => {
|
|
85
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
86
|
-
|
|
87
|
-
const validator = strapiUtils.validateYupSchema(
|
|
88
|
-
validators.timestamp(
|
|
89
|
-
{
|
|
90
|
-
attr: { type: 'timestamp', unique: true },
|
|
91
|
-
model: fakeModel,
|
|
92
|
-
updatedAttribute: {
|
|
93
|
-
name: 'attrTimestampUnique',
|
|
94
|
-
value: '1638140400',
|
|
95
|
-
},
|
|
96
|
-
entity: null,
|
|
97
|
-
},
|
|
98
|
-
{ isDraft: false }
|
|
99
|
-
)
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
expect(await validator('1638140400')).toBe('1638140400');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('it fails the validation of the unique constraint if the database contains a record with the same attribute value', async () => {
|
|
106
|
-
expect.assertions(1);
|
|
107
|
-
fakeFindOne.mockResolvedValueOnce({ attrTimestampUnique: '1638140400' });
|
|
108
|
-
|
|
109
|
-
const validator = strapiUtils.validateYupSchema(
|
|
110
|
-
validators.timestamp(
|
|
111
|
-
{
|
|
112
|
-
attr: { type: 'timestamp', unique: true },
|
|
113
|
-
model: fakeModel,
|
|
114
|
-
updatedAttribute: {
|
|
115
|
-
name: 'attrTimestampUnique',
|
|
116
|
-
value: '1638140400',
|
|
117
|
-
},
|
|
118
|
-
entity: null,
|
|
119
|
-
},
|
|
120
|
-
{ isDraft: false }
|
|
121
|
-
)
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
await validator('1638140400');
|
|
126
|
-
} catch (err) {
|
|
127
|
-
expect(err).toBeInstanceOf(YupValidationError);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
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 () => {
|
|
132
|
-
fakeFindOne.mockResolvedValueOnce({ attrTimestampUnique: '1638140400' });
|
|
133
|
-
|
|
134
|
-
const validator = strapiUtils.validateYupSchema(
|
|
135
|
-
validators.timestamp(
|
|
136
|
-
{
|
|
137
|
-
attr: { type: 'timestamp', unique: true },
|
|
138
|
-
model: fakeModel,
|
|
139
|
-
updatedAttribute: {
|
|
140
|
-
name: 'attrTimestampUnique',
|
|
141
|
-
value: '1638140400',
|
|
142
|
-
},
|
|
143
|
-
entity: { id: 1, attrTimestampUnique: '1638140400' },
|
|
144
|
-
},
|
|
145
|
-
{ isDraft: false }
|
|
146
|
-
)
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
expect(await validator('1638140400')).toBe('1638140400');
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test('it checks the database for records with the same value for the checked attribute', async () => {
|
|
153
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
154
|
-
|
|
155
|
-
const validator = strapiUtils.validateYupSchema(
|
|
156
|
-
validators.timestamp(
|
|
157
|
-
{
|
|
158
|
-
attr: { type: 'timestamp', unique: true },
|
|
159
|
-
model: fakeModel,
|
|
160
|
-
updatedAttribute: {
|
|
161
|
-
name: 'attrTimestampUnique',
|
|
162
|
-
value: '1638140400',
|
|
163
|
-
},
|
|
164
|
-
entity: null,
|
|
165
|
-
},
|
|
166
|
-
{ isDraft: false }
|
|
167
|
-
)
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
await validator('1638140400');
|
|
171
|
-
|
|
172
|
-
expect(fakeFindOne).toHaveBeenCalledWith({
|
|
173
|
-
select: ['id'],
|
|
174
|
-
where: { attrTimestampUnique: '1638140400' },
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
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 () => {
|
|
179
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
180
|
-
|
|
181
|
-
const validator = strapiUtils.validateYupSchema(
|
|
182
|
-
validators.timestamp(
|
|
183
|
-
{
|
|
184
|
-
attr: { type: 'timestamp', unique: true },
|
|
185
|
-
model: fakeModel,
|
|
186
|
-
updatedAttribute: {
|
|
187
|
-
name: 'attrTimestampUnique',
|
|
188
|
-
value: '1638140400',
|
|
189
|
-
},
|
|
190
|
-
entity: { id: 1, attrTimestampUnique: '1000000000' },
|
|
191
|
-
},
|
|
192
|
-
{ isDraft: false }
|
|
193
|
-
)
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
await validator('1638140400');
|
|
197
|
-
|
|
198
|
-
expect(fakeFindOne).toHaveBeenCalledWith({
|
|
199
|
-
select: ['id'],
|
|
200
|
-
where: { $and: [{ attrTimestampUnique: '1638140400' }, { $not: { id: 1 } }] },
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|
|
@@ -1,229 +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('UID validator', () => {
|
|
10
|
-
const fakeFindOne = jest.fn();
|
|
11
|
-
|
|
12
|
-
global.strapi = {
|
|
13
|
-
db: {
|
|
14
|
-
query: jest.fn(() => ({
|
|
15
|
-
findOne: fakeFindOne,
|
|
16
|
-
})),
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
jest.clearAllMocks();
|
|
22
|
-
fakeFindOne.mockReset();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const fakeModel = {
|
|
26
|
-
kind: 'contentType',
|
|
27
|
-
modelName: 'test-model',
|
|
28
|
-
uid: 'test-uid',
|
|
29
|
-
privateAttributes: [],
|
|
30
|
-
options: {},
|
|
31
|
-
attributes: {
|
|
32
|
-
attrUidUnique: { type: 'uid' },
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
describe('unique', () => {
|
|
37
|
-
test('it validates the unique constraint if there is no other record in the database', async () => {
|
|
38
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
39
|
-
|
|
40
|
-
const validator = strapiUtils.validateYupSchema(
|
|
41
|
-
validators.uid(
|
|
42
|
-
{
|
|
43
|
-
attr: { type: 'uid', unique: true },
|
|
44
|
-
model: fakeModel,
|
|
45
|
-
updatedAttribute: { name: 'attrUidUnique', value: 'non-unique-uid' },
|
|
46
|
-
entity: null,
|
|
47
|
-
},
|
|
48
|
-
{ isDraft: false }
|
|
49
|
-
)
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
expect(await validator('non-unique-uid')).toBe('non-unique-uid');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('it does not validates the unique constraint if the attribute value is `null`', async () => {
|
|
56
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
57
|
-
|
|
58
|
-
const validator = strapiUtils.validateYupSchema(
|
|
59
|
-
validators
|
|
60
|
-
.uid(
|
|
61
|
-
{
|
|
62
|
-
attr: { type: 'uid', unique: true },
|
|
63
|
-
model: fakeModel,
|
|
64
|
-
updatedAttribute: { name: 'attrUidUnique', value: null },
|
|
65
|
-
entity: null,
|
|
66
|
-
},
|
|
67
|
-
{ isDraft: false }
|
|
68
|
-
)
|
|
69
|
-
.nullable()
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
await validator(null);
|
|
73
|
-
|
|
74
|
-
expect(fakeFindOne).not.toHaveBeenCalled();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('it always validates the unique constraint even if the attribute is not set as unique', async () => {
|
|
78
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
79
|
-
|
|
80
|
-
const validator = strapiUtils.validateYupSchema(
|
|
81
|
-
validators.uid(
|
|
82
|
-
{
|
|
83
|
-
attr: { type: 'uid' },
|
|
84
|
-
model: fakeModel,
|
|
85
|
-
updatedAttribute: { name: 'attrUidUnique', value: 'non-unique-uid' },
|
|
86
|
-
entity: null,
|
|
87
|
-
},
|
|
88
|
-
{ isDraft: false }
|
|
89
|
-
)
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(await validator('non-unique-uid')).toBe('non-unique-uid');
|
|
93
|
-
expect(fakeFindOne).toHaveBeenCalledWith({
|
|
94
|
-
select: ['id'],
|
|
95
|
-
where: { attrUidUnique: 'non-unique-uid' },
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('it fails the validation of the unique constraint if the database contains a record with the same attribute value', async () => {
|
|
100
|
-
expect.assertions(1);
|
|
101
|
-
fakeFindOne.mockResolvedValueOnce({ attrUidUnique: 'unique-uid' });
|
|
102
|
-
|
|
103
|
-
const validator = strapiUtils.validateYupSchema(
|
|
104
|
-
validators.uid(
|
|
105
|
-
{
|
|
106
|
-
attr: { type: 'uid', unique: true },
|
|
107
|
-
model: fakeModel,
|
|
108
|
-
updatedAttribute: { name: 'attrUidUnique', value: 'unique-uid' },
|
|
109
|
-
entity: null,
|
|
110
|
-
},
|
|
111
|
-
{ isDraft: false }
|
|
112
|
-
)
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
await validator('unique-uid');
|
|
117
|
-
} catch (err) {
|
|
118
|
-
expect(err).toBeInstanceOf(YupValidationError);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
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 () => {
|
|
123
|
-
fakeFindOne.mockResolvedValueOnce({ attrUidUnique: 'unchanged-unique-uid' });
|
|
124
|
-
|
|
125
|
-
const validator = strapiUtils.validateYupSchema(
|
|
126
|
-
validators.uid(
|
|
127
|
-
{
|
|
128
|
-
attr: { type: 'uid', unique: true },
|
|
129
|
-
model: fakeModel,
|
|
130
|
-
updatedAttribute: { name: 'attrUidUnique', value: 'unchanged-unique-uid' },
|
|
131
|
-
entity: { id: 1, attrUidUnique: 'unchanged-unique-uid' },
|
|
132
|
-
},
|
|
133
|
-
{ isDraft: false }
|
|
134
|
-
)
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
expect(await validator('unchanged-unique-uid')).toBe('unchanged-unique-uid');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
test('it checks the database for records with the same value for the checked attribute', async () => {
|
|
141
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
142
|
-
|
|
143
|
-
const validator = strapiUtils.validateYupSchema(
|
|
144
|
-
validators.uid(
|
|
145
|
-
{
|
|
146
|
-
attr: { type: 'uid', unique: true },
|
|
147
|
-
model: fakeModel,
|
|
148
|
-
updatedAttribute: { name: 'attrUidUnique', value: 'unique-uid' },
|
|
149
|
-
entity: null,
|
|
150
|
-
},
|
|
151
|
-
{ isDraft: false }
|
|
152
|
-
)
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
await validator('unique-uid');
|
|
156
|
-
|
|
157
|
-
expect(fakeFindOne).toHaveBeenCalledWith({
|
|
158
|
-
select: ['id'],
|
|
159
|
-
where: { attrUidUnique: 'unique-uid' },
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
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 () => {
|
|
164
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
165
|
-
|
|
166
|
-
const validator = strapiUtils.validateYupSchema(
|
|
167
|
-
validators.uid(
|
|
168
|
-
{
|
|
169
|
-
attr: { type: 'uid', unique: true },
|
|
170
|
-
model: fakeModel,
|
|
171
|
-
updatedAttribute: { name: 'attrUidUnique', value: 'unique-uid' },
|
|
172
|
-
entity: { id: 1, attrUidUnique: 'other-uid' },
|
|
173
|
-
},
|
|
174
|
-
{ isDraft: false }
|
|
175
|
-
)
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
await validator('unique-uid');
|
|
179
|
-
|
|
180
|
-
expect(fakeFindOne).toHaveBeenCalledWith({
|
|
181
|
-
select: ['id'],
|
|
182
|
-
where: { $and: [{ attrUidUnique: 'unique-uid' }, { $not: { id: 1 } }] },
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
describe('regExp', () => {
|
|
188
|
-
test('it fails to validate the uid if it does not fit the requried format', async () => {
|
|
189
|
-
expect.assertions(1);
|
|
190
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
191
|
-
|
|
192
|
-
const validator = strapiUtils.validateYupSchema(
|
|
193
|
-
validators.uid(
|
|
194
|
-
{
|
|
195
|
-
attr: { type: 'uid', unique: true },
|
|
196
|
-
model: fakeModel,
|
|
197
|
-
updatedAttribute: { name: 'attrUidUnique', value: 'non-unique-uid' },
|
|
198
|
-
entity: null,
|
|
199
|
-
},
|
|
200
|
-
{ isDraft: false }
|
|
201
|
-
)
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
await validator('wrongly\\formated||UID');
|
|
206
|
-
} catch (err) {
|
|
207
|
-
expect(err).toBeInstanceOf(YupValidationError);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
test('it validate the uid if it fit the required format', async () => {
|
|
212
|
-
fakeFindOne.mockResolvedValueOnce(null);
|
|
213
|
-
|
|
214
|
-
const validator = strapiUtils.validateYupSchema(
|
|
215
|
-
validators.uid(
|
|
216
|
-
{
|
|
217
|
-
attr: { type: 'uid', unique: true },
|
|
218
|
-
model: fakeModel,
|
|
219
|
-
updatedAttribute: { name: 'attrUidUnique', value: 'non-unique-uid' },
|
|
220
|
-
entity: null,
|
|
221
|
-
},
|
|
222
|
-
{ isDraft: false }
|
|
223
|
-
)
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
expect(await validator('properly.formated-uid')).toBe('properly.formated-uid');
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const crypto = require('crypto');
|
|
4
|
-
const { generateAdminUserHash } = require('../admin-user-hash');
|
|
5
|
-
const createContext = require('../../../../../../../test/helpers/create-context');
|
|
6
|
-
|
|
7
|
-
describe('user email hash', () => {
|
|
8
|
-
test('should create a hash from admin user email', () => {
|
|
9
|
-
const state = {
|
|
10
|
-
user: {
|
|
11
|
-
email: 'testemail@strapi.io',
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const ctx = createContext({}, { state });
|
|
16
|
-
|
|
17
|
-
const strapi = {
|
|
18
|
-
requestContext: {
|
|
19
|
-
get: jest.fn(() => ctx),
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const hash = crypto.createHash('sha256').update('testemail@strapi.io').digest('hex');
|
|
24
|
-
|
|
25
|
-
const userId = generateAdminUserHash(strapi);
|
|
26
|
-
expect(userId).toBe(hash);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should return empty string if user is not available on ctx', () => {
|
|
30
|
-
const ctx = createContext({}, {});
|
|
31
|
-
|
|
32
|
-
const strapi = {
|
|
33
|
-
requestContext: {
|
|
34
|
-
get: jest.fn(() => ctx),
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const userId = generateAdminUserHash(strapi);
|
|
39
|
-
expect(userId).toBe('');
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
jest.mock('node-fetch', () => jest.fn(() => Promise.resolve()));
|
|
4
|
-
|
|
5
|
-
const { get } = require('lodash/fp');
|
|
6
|
-
const metrics = require('../index');
|
|
7
|
-
|
|
8
|
-
const fetch = jest.fn(() => Promise.resolve());
|
|
9
|
-
|
|
10
|
-
describe('metrics', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
fetch.mockClear();
|
|
13
|
-
});
|
|
14
|
-
test('Initializes a middleware', () => {
|
|
15
|
-
const use = jest.fn();
|
|
16
|
-
|
|
17
|
-
const metricsInstance = metrics({
|
|
18
|
-
config: {
|
|
19
|
-
get(path) {
|
|
20
|
-
return get(path, this);
|
|
21
|
-
},
|
|
22
|
-
uuid: 'test',
|
|
23
|
-
environment: 'dev',
|
|
24
|
-
info: {
|
|
25
|
-
strapi: '0.0.0',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
server: {
|
|
29
|
-
use,
|
|
30
|
-
},
|
|
31
|
-
dirs: {
|
|
32
|
-
app: {
|
|
33
|
-
root: process.cwd(),
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
requestContext: {
|
|
37
|
-
get: jest.fn(() => ({})),
|
|
38
|
-
},
|
|
39
|
-
fetch,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
metricsInstance.register();
|
|
43
|
-
|
|
44
|
-
expect(use).toHaveBeenCalled();
|
|
45
|
-
|
|
46
|
-
metricsInstance.destroy();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('Does not init middleware if disabled', () => {
|
|
50
|
-
const use = jest.fn();
|
|
51
|
-
|
|
52
|
-
const metricsInstance = metrics({
|
|
53
|
-
config: {
|
|
54
|
-
get(path) {
|
|
55
|
-
return get(path, this);
|
|
56
|
-
},
|
|
57
|
-
uuid: false,
|
|
58
|
-
environment: 'dev',
|
|
59
|
-
info: {
|
|
60
|
-
strapi: '0.0.0',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
server: {
|
|
64
|
-
use,
|
|
65
|
-
},
|
|
66
|
-
dirs: {
|
|
67
|
-
app: {
|
|
68
|
-
root: process.cwd(),
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
requestContext: {
|
|
72
|
-
get: jest.fn(() => ({})),
|
|
73
|
-
},
|
|
74
|
-
fetch,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
metricsInstance.register();
|
|
78
|
-
|
|
79
|
-
expect(use).not.toHaveBeenCalled();
|
|
80
|
-
|
|
81
|
-
metricsInstance.destroy();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('Send payload with meta', () => {
|
|
85
|
-
const { send } = metrics({
|
|
86
|
-
config: {
|
|
87
|
-
get(path) {
|
|
88
|
-
return get(path, this);
|
|
89
|
-
},
|
|
90
|
-
uuid: 'test',
|
|
91
|
-
environment: 'dev',
|
|
92
|
-
info: {
|
|
93
|
-
strapi: '0.0.0',
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
server: {
|
|
97
|
-
use() {},
|
|
98
|
-
},
|
|
99
|
-
dirs: {
|
|
100
|
-
app: {
|
|
101
|
-
root: process.cwd(),
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
requestContext: {
|
|
105
|
-
get: jest.fn(() => ({})),
|
|
106
|
-
},
|
|
107
|
-
fetch,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
send('someEvent');
|
|
111
|
-
|
|
112
|
-
expect(fetch).toHaveBeenCalled();
|
|
113
|
-
expect(fetch.mock.calls[0][0]).toBe('https://analytics.strapi.io/api/v2/track');
|
|
114
|
-
expect(fetch.mock.calls[0][1].method).toBe('POST');
|
|
115
|
-
expect(JSON.parse(fetch.mock.calls[0][1].body)).toMatchObject({
|
|
116
|
-
event: 'someEvent',
|
|
117
|
-
groupProperties: {
|
|
118
|
-
projectType: 'Community',
|
|
119
|
-
projectId: 'test',
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
fetch.mockClear();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('Does not send payload when disabled', () => {
|
|
127
|
-
const { send } = metrics({
|
|
128
|
-
config: {
|
|
129
|
-
get(path) {
|
|
130
|
-
return get(path, this);
|
|
131
|
-
},
|
|
132
|
-
uuid: false,
|
|
133
|
-
packageJsonStrapi: {},
|
|
134
|
-
environment: 'dev',
|
|
135
|
-
info: {
|
|
136
|
-
strapi: '0.0.0',
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
server: {
|
|
140
|
-
use() {},
|
|
141
|
-
},
|
|
142
|
-
dirs: {
|
|
143
|
-
app: {
|
|
144
|
-
root: process.cwd(),
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
requestContext: {
|
|
148
|
-
get: jest.fn(() => ({})),
|
|
149
|
-
},
|
|
150
|
-
fetch,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
send('someEvent');
|
|
154
|
-
|
|
155
|
-
expect(fetch).not.toHaveBeenCalled();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const isTruthyEnvVar = require('../is-truthy');
|
|
4
|
-
|
|
5
|
-
describe('isTruthyEnvVar', () => {
|
|
6
|
-
test('Handles boolean strings', () => {
|
|
7
|
-
expect(isTruthyEnvVar('true')).toBe(true);
|
|
8
|
-
|
|
9
|
-
expect(isTruthyEnvVar('false')).toBe(false);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('Handle numbers', () => {
|
|
13
|
-
expect(isTruthyEnvVar(1)).toBe(true);
|
|
14
|
-
|
|
15
|
-
expect(isTruthyEnvVar(-1)).toBe(false);
|
|
16
|
-
expect(isTruthyEnvVar(0)).toBe(false);
|
|
17
|
-
expect(isTruthyEnvVar(2)).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('Handles default booleans', () => {
|
|
21
|
-
expect(isTruthyEnvVar(true)).toBe(true);
|
|
22
|
-
expect(isTruthyEnvVar(false)).toBe(false);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('Handles all the other values', () => {
|
|
26
|
-
expect(isTruthyEnvVar(null)).toBe(false);
|
|
27
|
-
expect(isTruthyEnvVar(undefined)).toBe(false);
|
|
28
|
-
expect(isTruthyEnvVar({})).toBe(false);
|
|
29
|
-
expect(isTruthyEnvVar([])).toBe(false);
|
|
30
|
-
expect(isTruthyEnvVar(new Date())).toBe(false);
|
|
31
|
-
expect(isTruthyEnvVar('some text')).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
});
|