-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decouple min/max validations from required for integer, float and string fields #1464
Changes from 1 commit
251b085
912a6c3
2a9f97b
80cd559
4039a75
3f7bd0f
c7f2b54
43f17f6
e2eb48c
da2d0f1
08435cd
19528e6
e2d00cb
2a4b1ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,7 +339,7 @@ describe('Schemas', function() { | |
}); | ||
}); | ||
|
||
it('should keep an empty submitted field value null when there is a min / max configuration for a integer field type', function(done) { | ||
it('should keep an empty submitted field value null when there is a min / max configuration for an integer field type', function(done) { | ||
var schema = apos.schemas.compose({ | ||
addFields: [ | ||
{ | ||
|
@@ -418,7 +418,61 @@ describe('Schemas', function() { | |
}); | ||
}); | ||
|
||
it('should override the saved value if min and max value has been set and the submitted value is out of range for a integer field type', function(done) { | ||
it('should allow saving of a 0 value if there is no min value set for an integer type field', function(done) { | ||
var schema = apos.schemas.compose({ | ||
addFields: [ | ||
{ | ||
type: 'integer', | ||
name: 'price', | ||
label: 'Price' | ||
} | ||
] | ||
}); | ||
assert(schema.length === 1); | ||
var input = { | ||
price: '0' | ||
}; | ||
var req = apos.tasks.getReq(); | ||
var result = {}; | ||
// var result = { password: 'serious' }; | ||
return apos.schemas.convert(req, schema, 'form', input, result, function(err) { | ||
assert(!err); | ||
assert(_.keys(result).length === 1); | ||
// hashing is not the business of schemas, see the | ||
// apostrophe-users module | ||
assert(result.price === 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should allow saving of a 0 value if there is no min value set for a float type field', function(done) { | ||
var schema = apos.schemas.compose({ | ||
addFields: [ | ||
{ | ||
type: 'float', | ||
name: 'price', | ||
label: 'Price' | ||
} | ||
] | ||
}); | ||
assert(schema.length === 1); | ||
var input = { | ||
price: '0' | ||
}; | ||
var req = apos.tasks.getReq(); | ||
var result = {}; | ||
// var result = { password: 'serious' }; | ||
return apos.schemas.convert(req, schema, 'form', input, result, function(err) { | ||
assert(!err); | ||
assert(_.keys(result).length === 1); | ||
// hashing is not the business of schemas, see the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can lose this comment too. Was meant to explain why the password schema field appears to save plaintext (the users module takes care of converting it to a hash before it's actually saved). This isn't a password field so not in play here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, copy / paste, will review all the tests I added to remove any extra comments. |
||
// apostrophe-users module | ||
assert(result.price === 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should override the saved value if min and max value has been set and the submitted value is out of range for an integer field type', function(done) { | ||
var schema = apos.schemas.compose({ | ||
addFields: [ | ||
{ | ||
|
@@ -476,7 +530,7 @@ describe('Schemas', function() { | |
}); | ||
}); | ||
|
||
it('should ensure a min value is being set to the configured min value if a lower value is submitted for a integer field type', function(done) { | ||
it('should ensure a min value is being set to the configured min value if a lower value is submitted for an integer field type', function(done) { | ||
var schema = apos.schemas.compose({ | ||
addFields: [ | ||
{ | ||
|
@@ -526,7 +580,7 @@ describe('Schemas', function() { | |
}); | ||
}); | ||
|
||
it('should ensure a max value is being set to the max if a higher value is submitted for a integer field type', function(done) { | ||
it('should ensure a max value is being set to the max if a higher value is submitted for an integer field type', function(done) { | ||
var schema = apos.schemas.compose({ | ||
addFields: [ | ||
{ | ||
|
@@ -576,7 +630,7 @@ describe('Schemas', function() { | |
}); | ||
}); | ||
|
||
it('should not modify a value if the submitted value is within min and max for a integer field type', function(done) { | ||
it('should not modify a value if the submitted value is within min and max for an integer field type', function(done) { | ||
var schema = apos.schemas.compose({ | ||
addFields: [ | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove this commented code re password: serious