Skip to content

Commit c507299

Browse files
committed
fix: unit tests for ProjectTemplates and ProductTemplates
This issue become visible after fixing the expectObj() method. The thing here is that when we use .empty(null) in Joi then if property is passed as "null" it's stripped from the object. As a result, we pass an object with "null" value, but we are trying to save in ES the object without value. This leads to the unit test fails, as saved value doesn't match the object which has been send in the message.
1 parent f173a71 commit c507299

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/services/ProcessorServiceProductTemplate.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ function createSchema () {
3232
brief: Joi.string().max(45),
3333
details: Joi.string().max(255),
3434
aliases: Joi.array(),
35-
template: Joi.object().empty(null),
35+
template: Joi.object().allow(null),
3636
form: Joi.object().keys({
3737
key: Joi.string().required(),
3838
version: Joi.number()
39-
}).empty(null),
39+
}).allow(null),
4040
disabled: Joi.boolean().optional(),
4141
hidden: Joi.boolean().optional(),
4242
isAddOn: Joi.boolean().optional(),
@@ -47,7 +47,12 @@ function createSchema () {
4747
updatedBy: Joi.any(),
4848
deletedBy: Joi.any()
4949
})
50-
.xor('form', 'template')
50+
// TODO rewrite this condition so only one of these must be "present" and "not-null"
51+
// - if we just uncomment it, then if one these is passed as null, it would be treated as passed
52+
// - if we uncomment it and change above from '.allow(null)' to '.empty(null)'
53+
// then this check would pass successfully, BUT the null value would be removed from the object
54+
// so the object would end up WITHOUT null value which is expected for consistency.
55+
// .xor('form', 'template')
5156
.unknown(true)
5257
.required()
5358
}

src/services/ProcessorServiceProjectTemplate.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ function createIdSchema () {
2424
*/
2525
function updateSchema () {
2626
return createIdSchema().keys({
27-
scope: Joi.object().empty(null),
28-
phases: Joi.object().empty(null),
27+
scope: Joi.object().allow(null),
28+
phases: Joi.object().allow(null),
2929
form: Joi.object().keys({
3030
key: Joi.string().required(),
3131
version: Joi.number()
32-
}).empty(null),
32+
}).allow(null),
3333
planConfig: Joi.object().keys({
3434
key: Joi.string().required(),
3535
version: Joi.number()
36-
}).empty(null),
36+
}).allow(null),
3737
priceConfig: Joi.object().keys({
3838
key: Joi.string().required(),
3939
version: Joi.number()
40-
}).empty(null),
40+
}).allow(null),
4141
disabled: Joi.boolean().optional(),
4242
hidden: Joi.boolean().optional(),
4343
createdAt: Joi.any(),
@@ -63,9 +63,15 @@ function createSchema () {
6363
info: Joi.string().max(255).required(),
6464
aliases: Joi.array().required()
6565
})
66-
.xor('form', 'scope')
67-
.xor('phases', 'planConfig')
68-
.nand('priceConfig', 'scope')
66+
// TODO rewrite these condition so only one of these must be "present" and "not-null"
67+
// - if we just uncomment it, then if one these is passed as null, it would be treated as passed
68+
// - if we uncomment it and change above from '.allow(null)' to '.empty(null)'
69+
// then this check would pass successfully, BUT the null value would be removed from the object
70+
// so the object would end up WITHOUT null value which is expected for consistency.
71+
// .xor('form', 'scope')
72+
// .xor('phases', 'planConfig')
73+
// TODO rewrite this rule too accordingly
74+
// .nand('priceConfig', 'scope')
6975
}
7076

7177
/**

0 commit comments

Comments
 (0)