Browse Source

add predicate that checks for sources=['whosonfirst']

pull/912/head
Stephen Hess 7 years ago
parent
commit
44896d7569
  1. 3
      controller/predicates/is_request_sources_only_whosonfirst.js
  2. 115
      test/unit/controller/predicates/is_request_sources_only_whosonfirst.js

3
controller/predicates/is_request_sources_only_whosonfirst.js

@ -0,0 +1,3 @@
const _ = require('lodash');
module.exports = (req, res) => _.isEqual(_.get(req, 'clean.sources', []), ['whosonfirst']);

115
test/unit/controller/predicates/is_request_sources_only_whosonfirst.js

@ -0,0 +1,115 @@
'use strict';
const _ = require('lodash');
const is_request_sources_only_whosonfirst = require('../../../../controller/predicates/is_request_sources_only_whosonfirst');
module.exports.tests = {};
module.exports.tests.interface = (test, common) => {
test('valid interface', (t) => {
t.ok(_.isFunction(is_request_sources_only_whosonfirst), 'is_request_sources_only_whosonfirst is a function');
t.end();
});
};
module.exports.tests.true_conditions = (test, common) => {
test('sources only \'whosonfirst\' should return true', (t) => {
const req = {
clean: {
sources: [
'whosonfirst'
]
}
};
t.ok(is_request_sources_only_whosonfirst(req));
t.end();
});
};
module.exports.tests.false_conditions = (test, common) => {
test('undefined req should return false', (t) => {
const req = {
clean: {
sources: [
'not whosonfirst'
]
}
};
t.notOk(is_request_sources_only_whosonfirst(req));
t.end();
});
test('undefined req.clean should return false', (t) => {
const req = {};
t.notOk(is_request_sources_only_whosonfirst(req));
t.end();
});
test('undefined req.clean.sources should return false', (t) => {
const req = {
clean: {}
};
t.notOk(is_request_sources_only_whosonfirst(req));
t.end();
});
test('empty req.clean.sources should return false', (t) => {
const req = {
clean: {
sources: []
}
};
t.notOk(is_request_sources_only_whosonfirst(req));
t.end();
});
test('sources not \'whosonfirst\' should return false', (t) => {
const req = {
clean: {
sources: [
'not whosonfirst'
]
}
};
t.notOk(is_request_sources_only_whosonfirst(req));
t.end();
});
test('sources other than \'whosonfirst\' should return false', (t) => {
const req = {
clean: {
sources: [
'whosonfirst', 'not whosonfirst'
]
}
};
t.notOk(is_request_sources_only_whosonfirst(req));
t.end();
});
};
module.exports.all = (tape, common) => {
function test(name, testFunction) {
return tape(`GET /is_request_sources_only_whosonfirst ${name}`, testFunction);
}
for( const testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};
Loading…
Cancel
Save