Repository: ViacomInc/data-point
Pull request #93 (2018-01-01 14:22:25)

Add id to ReducerEntity objects
#92

<!-- Have you done all of these things?  -->
**Checklist**:
<!-- add "N/A" to the end of each line that's irrelevant to your changes -->
<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->
- [ ] Documentation n/a
- [x] Tests
- [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->

I'm working on another feature that uses this ID.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/14858161/badge)](https://coveralls.io/builds/14858161)

Coverage remained the same at 100.0% when pulling **1d2e13397b5f5eb64722f14331d8eafd36ee35b6 on raingerber:add-reducer-entity-id** into **ce851a75793d16daa4a25fe904295218e6b7245c on ViacomInc:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/14858926/badge)](https://coveralls.io/builds/14858926)

Coverage remained the same at 100.0% when pulling **5dabea41808bbbb292d4837da3d25fb20a7a8012 on raingerber:add-reducer-entity-id** into **ce851a75793d16daa4a25fe904295218e6b7245c on ViacomInc:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/14859882/badge)](https://coveralls.io/builds/14859882)

Changes Unknown when pulling **56041eae619eabc6a84c1467952b8de2d8788a9b on raingerber:add-reducer-entity-id** into ** on ViacomInc:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/14860305/badge)](https://coveralls.io/builds/14860305)

Changes Unknown when pulling **56041eae619eabc6a84c1467952b8de2d8788a9b on raingerber:add-reducer-entity-id** into ** on ViacomInc:master**.


Patch:
diff --git a/packages/data-point/lib/entity-types/base-entity/resolve.js b/packages/data-point/lib/entity-types/base-entity/resolve.js
index f62361a..7f63498 100644
--- a/packages/data-point/lib/entity-types/base-entity/resolve.js
+++ b/packages/data-point/lib/entity-types/base-entity/resolve.js
@@ -27,7 +27,7 @@ module.exports.resolveErrorReducers = resolveErrorReducers
 
 function createCurrentAccumulator (manager, accumulator, reducer) {
   // get defined source
-  const entity = manager.entities.get(`${reducer.entityType}:${reducer.name}`)
+  const entity = manager.entities.get(reducer.id)
 
   // set reducer's spec
   const currentReducer = utils.assign(reducer, {
diff --git a/packages/data-point/lib/entity-types/entity-hash/factory.js b/packages/data-point/lib/entity-types/entity-hash/factory.js
index 2c1eeb3..9f137e0 100644
--- a/packages/data-point/lib/entity-types/entity-hash/factory.js
+++ b/packages/data-point/lib/entity-types/entity-hash/factory.js
@@ -74,7 +74,7 @@ function validateCompose (entityId, compose, validKeys) {
       throw new Error(
         `Modifier '${modifier.type}' in ${
           entityId
-        } doest not match any of the registered Modifiers: ${validKeys}`
+        } doesn't match any of the registered Modifiers: ${validKeys}`
       )
     }
   })
diff --git a/packages/data-point/lib/reducer-entity/factory.js b/packages/data-point/lib/reducer-entity/factory.js
index 87ae800..d86f5d4 100644
--- a/packages/data-point/lib/reducer-entity/factory.js
+++ b/packages/data-point/lib/reducer-entity/factory.js
@@ -42,10 +42,9 @@ function create (source) {
   const tokens = source.split(':')
 
   reducer.entityType = tokens[0]
+  reducer.name = tokens[1].replace(/\[]$/, '')
   reducer.asCollection = source.slice(-2) === '[]'
-  reducer.name = reducer.asCollection
-    ? tokens[1].slice(0, -2) // if collection remove []
-    : tokens[1]
+  reducer.id = `${reducer.entityType}:${reducer.name}`
 
   return Object.freeze(reducer)
 }


Test patch:
diff --git a/packages/data-point/lib/reducer-entity/factory.test.js b/packages/data-point/lib/reducer-entity/factory.test.js
index 6c76514..b341cad 100644
--- a/packages/data-point/lib/reducer-entity/factory.test.js
+++ b/packages/data-point/lib/reducer-entity/factory.test.js
@@ -28,6 +28,7 @@ test('reducer/reducer-entity#create', () => {
   expect(reducer.type).toBe('ReducerEntity')
   expect(reducer.name).toBe('abc')
   expect(reducer.entityType).toBe('foo')
+  expect(reducer.id).toBe('foo:abc')
 })
 
 test('reducer/reducer-entity#create as collection of', () => {
@@ -36,4 +37,5 @@ test('reducer/reducer-entity#create as collection of', () => {
   expect(reducer.type).toBe('ReducerEntity')
   expect(reducer.name).toBe('abc')
   expect(reducer.entityType).toBe('foo')
+  expect(reducer.id).toBe('foo:abc')
 })
diff --git a/packages/data-point/lib/reducer-object/__snapshots__/factory.test.js.snap b/packages/data-point/lib/reducer-object/__snapshots__/factory.test.js.snap
index ef2a774..276696a 100644
--- a/packages/data-point/lib/reducer-object/__snapshots__/factory.test.js.snap
+++ b/packages/data-point/lib/reducer-object/__snapshots__/factory.test.js.snap
@@ -57,6 +57,7 @@ Array [
                   ReducerEntity {
                     "asCollection": false,
                     "entityType": "transform",
+                    "id": "transform:entity-name",
                     "name": "entity-name",
                     "type": "ReducerEntity",
                   },