Skip to content

Commit

Permalink
feat(lib): Move terms function to proper place
Browse files Browse the repository at this point in the history
This 'view' was not really a view, because it did not produce results
based on the variable store. Instead it simply took parameters and
returned an object that was a valid terms query.

This is a good feature to have, but it should be internal to this
library only.
  • Loading branch information
orangejulius committed Aug 6, 2019
1 parent b847841 commit b6748c8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
File renamed without changes.
41 changes: 41 additions & 0 deletions test/lib/leaf/terms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const terms = require('../../../lib/leaf/terms');

module.exports.tests = {};

module.exports.tests.terms = function(test, common) {
test('null returned if property missing', function(t) {
const query = terms();

t.equal(null, query, 'null query returned');
t.end();
});

test('null returned if value missing', function(t) {
const query = terms('theproperty');

t.equal(null, query, 'null query returned');
t.end();
});

test('terms query returned with property and value', function(t) {
const query = terms('theproperty', 'thevalue');

const expected = {
terms: {
theproperty: 'thevalue'
}
};

t.deepEqual(query, expected, 'valid terms query');
t.end();
});
};

module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('lib/leaf/terms ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};
1 change: 1 addition & 0 deletions test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var tests = [
require('./layout/FilteredBooleanQuery.js'),
require('./layout/StructuredFallbackQuery.js'),
require('./layout/VenuesQuery.js'),
require('./lib/leaf/terms.js'),
require('./lib/Variable.js'),
require('./lib/VariableStore.js'),
require('./view/address.js'),
Expand Down
2 changes: 1 addition & 1 deletion view/layers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var terms = require('./terms');
const terms = require('../lib/leaf/terms');

module.exports = function( vs ){
if( !vs.isset('layers')) {
Expand Down
2 changes: 1 addition & 1 deletion view/sources.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var terms = require('./terms');
const terms = require('../lib/leaf/terms');

module.exports = function( vs ){
if( !vs.isset('sources')) {
Expand Down

0 comments on commit b6748c8

Please sign in to comment.