Skip to content
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

Merged
merged 14 commits into from
Jul 6, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 59 additions & 5 deletions test/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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' };
Copy link
Member

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

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
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down