diff --git a/src/lib/canonical-title-map.js b/src/lib/canonical-title-map.js index 1720eaf..0749ae0 100644 --- a/src/lib/canonical-title-map.js +++ b/src/lib/canonical-title-map.js @@ -14,6 +14,17 @@ export default function(titleMap: Array, originalEnum?: any) { }); } return canonical; + } else if (originalEnum) { + const canonical = []; + return originalEnum.map((value, index) => { + if (typeof titleMap[index] === 'string') { + return { + name: titleMap[index], + value, + } + } + return titleMap[index]; + }); } return titleMap; } diff --git a/src/lib/canonical-title-map.spec.js b/src/lib/canonical-title-map.spec.js index 11c4430..4fdac0d 100644 --- a/src/lib/canonical-title-map.spec.js +++ b/src/lib/canonical-title-map.spec.js @@ -36,6 +36,15 @@ describe('canonical-title-map.js', () => { result.should.be.deep.equal(titlemap); }); + it('should return a titleMap for a enumNames list with enum values', () => { + let result = canonicalTitleMap([ 'name', 'firstname', 'phone' ], [ 'n', 'f', 'p' ]); + result.should.be.deep.equal([ + { name: 'name', value: 'n' }, + { name: 'firstname', value: 'f' }, + { name: 'phone', value: 'p' }, + ]); + }); + it('should return a titleMap for a titleMap object without enum', () => { let result = canonicalTitleMap(titlemapObj); result.should.be.deep.equal(titlemap);