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. 8
      helper/TypeMapping.js
  2. 24
      test/unit/helper/TypeMapping.js

8
helper/TypeMapping.js

@ -65,8 +65,8 @@ TypeMapping.prototype.setLayerAliases = function( aliases ){
this.layer_aliases = aliases;
};
// generate dynamic mappings after setters have been run
TypeMapping.prototype.generateDynamicMappings = function(){
// generate mappings after setters have been run
TypeMapping.prototype.generateMappings = function(){
this.sources = Object.keys( this.layers_by_source );
this.source_mapping = TypeMapping.addStandardTargetsToAliases(this.sources, this.source_aliases);
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.setLayerAliases( targetsBlock.layer_aliases || {} );
// generate the dynamic mappings
this.generateDynamicMappings();
// generate the mappings
this.generateMappings();
};
// load values from either pelias config file or from elasticsearch

24
test/unit/helper/TypeMapping.js

@ -13,7 +13,7 @@ module.exports.tests.interface = function(test) {
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.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.load, 'function', 'load() is a function');
@ -105,47 +105,47 @@ module.exports.tests.setLayerAliases = function(test) {
});
};
module.exports.tests.generateDynamicMappings = function(test) {
test('generateDynamicMappings - no-op', function(t) {
module.exports.tests.generateMappings = function(test) {
test('generateMappings - no-op', function(t) {
var tm = new TypeMapping();
t.deepEqual(tm.sources, []);
t.deepEqual(tm.source_mapping, {});
t.deepEqual(tm.layers, []);
t.deepEqual(tm.layer_mapping, {});
tm.generateDynamicMappings();
tm.generateMappings();
t.deepEqual(tm.sources, []);
t.deepEqual(tm.source_mapping, {});
t.deepEqual(tm.layers, []);
t.deepEqual(tm.layer_mapping, {});
t.end();
});
test('generateDynamicMappings - sources', function(t) {
test('generateMappings - sources', function(t) {
var tm = new TypeMapping();
tm.layers_by_source = { foo: ['foo'], faz: ['faz'] };
tm.generateDynamicMappings();
tm.generateMappings();
t.deepEqual(tm.sources, ['foo', 'faz']);
t.end();
});
test('generateDynamicMappings - source_mapping', function(t) {
test('generateMappings - source_mapping', function(t) {
var tm = new TypeMapping();
tm.layers_by_source = { foo: ['foo'], faz: ['faz'] };
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.end();
});
test('generateDynamicMappings - layers', function(t) {
test('generateMappings - layers', function(t) {
var tm = new TypeMapping();
tm.layers_by_source = { foo: ['foo'], faz: ['faz'] };
tm.generateDynamicMappings();
tm.generateMappings();
t.deepEqual(tm.layers, ['foo','faz']);
t.end();
});
test('generateDynamicMappings - layer_mapping', function(t) {
test('generateMappings - layer_mapping', function(t) {
var tm = new TypeMapping();
tm.layers_by_source = { foo: ['foo'], faz: ['faz'] };
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.end();
});

Loading…
Cancel
Save