Skip to content

Commit

Permalink
fix: Merge pull request #60 from pelias/rename-positive-to-non-negative
Browse files Browse the repository at this point in the history
changed function name from `positive` to `nonnegative`
  • Loading branch information
trescube authored Apr 20, 2017
2 parents ddda6b3 + c3d6e08 commit cef6eb9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
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

0 comments on commit cef6eb9

Please sign in to comment.