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

changed function name from positive to nonnegative #60

Merged
merged 1 commit into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,15 @@ Document.prototype.hasAddress = model.hasChild( 'address_parts' );
// population
Document.prototype.setPopulation = model.set( 'population', null, null )
.validate( valid.type('number') )
.validate( valid.positive() );
.validate( valid.nonnegative() );

Document.prototype.getPopulation = model.get( 'population' );

// popularity
Document.prototype.setPopularity = model.set( 'popularity', null, null )
.transform( transform.roundify() )
.validate( valid.type('number') )
.validate( valid.positive() );
.validate( valid.nonnegative() );

Document.prototype.getPopularity = model.get( 'popularity' );

Expand Down
1 change: 1 addition & 0 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var tests = [
require('./DocumentMapperStream.js'),
require('./util/transform.js'),
require('./util/model.js'),
require('./util/valid.js'),
require('./serialize/test.js'),
];

Expand Down
32 changes: 32 additions & 0 deletions test/util/valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const valid = require('../../util/valid');

module.exports.tests = {};

module.exports.tests.nonnegative = (test) => {
test('nonnegative should throw error if value is less than 0', (t) => {
t.throws(valid.nonnegative().bind(null, -1), /invalid document type, expecting: 0 or a positive number, got: -1/);
t.end();
});

test('nonnegative should not throw error if value is 0', (t) => {
t.doesNotThrow(valid.nonnegative().bind(null, 0), '0 should be allowed');
t.end();
});

test('nonnegative should not throw error if value is greater than 0', (t) => {
t.doesNotThrow(valid.nonnegative().bind(null, 1), '1 should be allowed');
t.end();
});

};

module.exports.all = (tape, common) => {

function test(name, testFunction) {
return tape(`valid: ${name}`, testFunction);
}

for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};
2 changes: 1 addition & 1 deletion util/valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports.truthy = function(){
};
};

module.exports.positive = function(){
module.exports.nonnegative = function(){
return function( val ){
if( val < 0 ){
throw new PeliasModelError( 'invalid document type, expecting: 0 or a positive number, got: ' + val );
Expand Down