Browse Source

feat(type_mapping): rename function to avoid confusion with elasticsearch API

pull/1149/head
Peter Johnson 7 years ago committed by Peter Johnson
parent
commit
e15aa52f63
  1. 10
      helper/TypeMapping.js
  2. 26
      test/unit/helper/TypeMapping.js

10
helper/TypeMapping.js

@ -65,8 +65,8 @@ TypeMapping.prototype.setLayerAliases = function( aliases ){
this.layer_aliases = aliases; this.layer_aliases = aliases;
}; };
// generate dynamic mappings after setters have been run // generate mappings after setters have been run
TypeMapping.prototype.generateDynamicMappings = function(){ TypeMapping.prototype.generateMappings = function(){
this.sources = Object.keys( this.layers_by_source ); this.sources = Object.keys( this.layers_by_source );
this.source_mapping = TypeMapping.addStandardTargetsToAliases(this.sources, this.source_aliases); this.source_mapping = TypeMapping.addStandardTargetsToAliases(this.sources, this.source_aliases);
this.layers = _.uniq(Object.keys(this.layers_by_source).reduce(function(acc, key) { this.layers = _.uniq(Object.keys(this.layers_by_source).reduce(function(acc, key) {
@ -85,8 +85,8 @@ TypeMapping.prototype.loadTargets = function( targetsBlock ){
this.setLayersBySource( targetsBlock.layers_by_source || {} ); this.setLayersBySource( targetsBlock.layers_by_source || {} );
this.setLayerAliases( targetsBlock.layer_aliases || {} ); this.setLayerAliases( targetsBlock.layer_aliases || {} );
// generate the dynamic mappings // generate the mappings
this.generateDynamicMappings(); this.generateMappings();
}; };
// load values from either pelias config file or from elasticsearch // load values from either pelias config file or from elasticsearch
@ -143,4 +143,4 @@ TypeMapping.prototype.load = function( done ){
// }); // });
}; };
module.exports = TypeMapping; module.exports = TypeMapping;

26
test/unit/helper/TypeMapping.js

@ -13,8 +13,8 @@ module.exports.tests.interface = function(test) {
t.equal(typeof TypeMapping.prototype.setLayersBySource, 'function', 'setLayersBySource() is a function'); t.equal(typeof TypeMapping.prototype.setLayersBySource, 'function', 'setLayersBySource() is a function');
t.equal(typeof TypeMapping.prototype.setLayerAliases, 'function', 'setLayerAliases() is a function'); t.equal(typeof TypeMapping.prototype.setLayerAliases, 'function', 'setLayerAliases() is a function');
t.equal(typeof TypeMapping.prototype.generateDynamicMappings, 'function', 'generateDynamicMappings() is a function'); t.equal(typeof TypeMapping.prototype.generateMappings, 'function', 'generateMappings() is a function');
t.equal(typeof TypeMapping.prototype.loadTargets, 'function', 'loadTargets() is a function'); t.equal(typeof TypeMapping.prototype.loadTargets, 'function', 'loadTargets() is a function');
t.equal(typeof TypeMapping.prototype.load, 'function', 'load() is a function'); t.equal(typeof TypeMapping.prototype.load, 'function', 'load() is a function');
@ -105,47 +105,47 @@ module.exports.tests.setLayerAliases = function(test) {
}); });
}; };
module.exports.tests.generateDynamicMappings = function(test) { module.exports.tests.generateMappings = function(test) {
test('generateDynamicMappings - no-op', function(t) { test('generateMappings - no-op', function(t) {
var tm = new TypeMapping(); var tm = new TypeMapping();
t.deepEqual(tm.sources, []); t.deepEqual(tm.sources, []);
t.deepEqual(tm.source_mapping, {}); t.deepEqual(tm.source_mapping, {});
t.deepEqual(tm.layers, []); t.deepEqual(tm.layers, []);
t.deepEqual(tm.layer_mapping, {}); t.deepEqual(tm.layer_mapping, {});
tm.generateDynamicMappings(); tm.generateMappings();
t.deepEqual(tm.sources, []); t.deepEqual(tm.sources, []);
t.deepEqual(tm.source_mapping, {}); t.deepEqual(tm.source_mapping, {});
t.deepEqual(tm.layers, []); t.deepEqual(tm.layers, []);
t.deepEqual(tm.layer_mapping, {}); t.deepEqual(tm.layer_mapping, {});
t.end(); t.end();
}); });
test('generateDynamicMappings - sources', function(t) { test('generateMappings - sources', function(t) {
var tm = new TypeMapping(); var tm = new TypeMapping();
tm.layers_by_source = { foo: ['foo'], faz: ['faz'] }; tm.layers_by_source = { foo: ['foo'], faz: ['faz'] };
tm.generateDynamicMappings(); tm.generateMappings();
t.deepEqual(tm.sources, ['foo', 'faz']); t.deepEqual(tm.sources, ['foo', 'faz']);
t.end(); t.end();
}); });
test('generateDynamicMappings - source_mapping', function(t) { test('generateMappings - source_mapping', function(t) {
var tm = new TypeMapping(); var tm = new TypeMapping();
tm.layers_by_source = { foo: ['foo'], faz: ['faz'] }; tm.layers_by_source = { foo: ['foo'], faz: ['faz'] };
tm.source_aliases = { foo: ['foo','f'], bar: ['bar', 'b'], baz: ['baz'] }; tm.source_aliases = { foo: ['foo','f'], bar: ['bar', 'b'], baz: ['baz'] };
tm.generateDynamicMappings(); tm.generateMappings();
t.deepEqual(tm.source_mapping, { foo: ['foo', 'f'], bar: ['bar', 'b'], baz: ['baz'], faz: ['faz'] }); t.deepEqual(tm.source_mapping, { foo: ['foo', 'f'], bar: ['bar', 'b'], baz: ['baz'], faz: ['faz'] });
t.end(); t.end();
}); });
test('generateDynamicMappings - layers', function(t) { test('generateMappings - layers', function(t) {
var tm = new TypeMapping(); var tm = new TypeMapping();
tm.layers_by_source = { foo: ['foo'], faz: ['faz'] }; tm.layers_by_source = { foo: ['foo'], faz: ['faz'] };
tm.generateDynamicMappings(); tm.generateMappings();
t.deepEqual(tm.layers, ['foo','faz']); t.deepEqual(tm.layers, ['foo','faz']);
t.end(); t.end();
}); });
test('generateDynamicMappings - layer_mapping', function(t) { test('generateMappings - layer_mapping', function(t) {
var tm = new TypeMapping(); var tm = new TypeMapping();
tm.layers_by_source = { foo: ['foo'], faz: ['faz'] }; tm.layers_by_source = { foo: ['foo'], faz: ['faz'] };
tm.layer_aliases = { foo: ['foo','f'], bar: ['bar', 'b'], baz: ['baz'] }; tm.layer_aliases = { foo: ['foo','f'], bar: ['bar', 'b'], baz: ['baz'] };
tm.generateDynamicMappings(); tm.generateMappings();
t.deepEqual(tm.layer_mapping, { foo: ['foo', 'f'], bar: ['bar', 'b'], baz: ['baz'], faz: ['faz'] }); t.deepEqual(tm.layer_mapping, { foo: ['foo', 'f'], bar: ['bar', 'b'], baz: ['baz'], faz: ['faz'] });
t.end(); t.end();
}); });

Loading…
Cancel
Save