@atombender/hydrant-api
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -199,3 +199,9 @@ 'use strict'; | ||
case 'count': | ||
return a + b; | ||
if (isNaN(a)) { | ||
return b; | ||
} else if (isNaN(b)) { | ||
return a; | ||
} else { | ||
return a + b; | ||
} | ||
@@ -202,0 +208,0 @@ default: |
{ | ||
"name": "@atombender/hydrant-api", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -9,3 +9,3 @@ 'use strict'; | ||
import {Table, TableRow} from '../../src/tables'; | ||
import {COUNT_DIMENSION, Value, AggregationInstance} from '../../src/dimensions'; | ||
import {COUNT_DIMENSION, TIME_DIMENSION, Value, AggregationInstance} from '../../src/dimensions'; | ||
@@ -17,2 +17,4 @@ describe('Table#nest()', () => { | ||
let browserDimension = find(schema.dimensions, d => d.id === 'browser'); | ||
let countDimension = COUNT_DIMENSION; | ||
let timeDimension = TIME_DIMENSION; | ||
@@ -50,3 +52,3 @@ describe('Plain tables', () => { | ||
[urlDimension, 'http://example.com/listings/1'], | ||
[COUNT_DIMENSION, 1] | ||
[countDimension, 1] | ||
])), | ||
@@ -56,3 +58,3 @@ new TableRow(Immutable.OrderedMap([ | ||
[urlDimension, 'http://example.com/listings/2'], | ||
[COUNT_DIMENSION, 3] | ||
[countDimension, 3] | ||
])), | ||
@@ -62,3 +64,3 @@ new TableRow(Immutable.OrderedMap([ | ||
[urlDimension, 'http://example.com/listings/1'], | ||
[COUNT_DIMENSION, 8] | ||
[countDimension, 8] | ||
])) | ||
@@ -73,5 +75,5 @@ ]; | ||
expect(table.rows.get(0).childRows.size).to.eql(2); | ||
expect(table.rows.get(0).valueMap.get(COUNT_DIMENSION)).to.eql(4); | ||
expect(table.rows.get(0).valueMap.get(countDimension)).to.eql(4); | ||
expect(table.rows.get(1).childRows.size).to.eql(1); | ||
expect(table.rows.get(1).valueMap.get(COUNT_DIMENSION)).to.eql(8); | ||
expect(table.rows.get(1).valueMap.get(countDimension)).to.eql(8); | ||
}); | ||
@@ -85,3 +87,3 @@ | ||
[browserDimension, 'Internet Explorer'], | ||
[COUNT_DIMENSION, 1] | ||
[countDimension, 1] | ||
])), | ||
@@ -92,3 +94,3 @@ new TableRow(Immutable.OrderedMap([ | ||
[browserDimension, 'Firefox'], | ||
[COUNT_DIMENSION, 3] | ||
[countDimension, 3] | ||
])), | ||
@@ -99,3 +101,3 @@ new TableRow(Immutable.OrderedMap([ | ||
[browserDimension, 'Safari'], | ||
[COUNT_DIMENSION, 8] | ||
[countDimension, 8] | ||
])) | ||
@@ -113,2 +115,40 @@ ]; | ||
}); | ||
it('it nests a single dimension with holes in data', () => { | ||
let rows = [ | ||
new TableRow(Immutable.OrderedMap([ | ||
[platformDimension, 'Mobile'], | ||
[browserDimension, 'Safari'], | ||
[timeDimension, timeDimension.parseRawValue(1422766800000)], | ||
[countDimension, 1] | ||
])), | ||
new TableRow(Immutable.OrderedMap([ | ||
[platformDimension, 'Mobile'], | ||
[browserDimension, 'Chrome'], | ||
[timeDimension, timeDimension.parseRawValue(1422766800000)], | ||
[countDimension, 2] | ||
])), | ||
new TableRow(Immutable.OrderedMap([ | ||
[platformDimension, 'Mobile'], | ||
[browserDimension, 'Safari'], | ||
[timeDimension, timeDimension.parseRawValue(1425186000000)], | ||
[countDimension, 6] | ||
])), | ||
new TableRow(Immutable.OrderedMap([ | ||
[platformDimension, 'Mobile'], | ||
[browserDimension, 'Chrome'], | ||
[timeDimension, timeDimension.parseRawValue(1425186000000)], | ||
[countDimension, 0] | ||
])) | ||
]; | ||
let table = new Table(schema, rows); | ||
expect(table.length).to.eql(4); | ||
table.nest([platformDimension, browserDimension], [timeDimension]); | ||
expect(table.length).to.eql(2); | ||
// TODO: More tests, please | ||
expect(table.rows.get(0).valueMap.get(countDimension)).to.eql(3); | ||
expect(table.rows.get(1).valueMap.get(countDimension)).to.eql(6); | ||
}); | ||
}); | ||
@@ -123,3 +163,3 @@ | ||
[browserDimension, 'Internet Explorer'], | ||
[COUNT_DIMENSION, 1] | ||
[countDimension, 1] | ||
])), | ||
@@ -130,3 +170,3 @@ new TableRow(Immutable.OrderedMap([ | ||
[browserDimension, 'Firefox'], | ||
[COUNT_DIMENSION, 3] | ||
[countDimension, 3] | ||
])), | ||
@@ -137,3 +177,3 @@ new TableRow(Immutable.OrderedMap([ | ||
[browserDimension, 'Safari'], | ||
[COUNT_DIMENSION, 8] | ||
[countDimension, 8] | ||
])) | ||
@@ -146,5 +186,5 @@ ]; | ||
expect(table.length).to.eql(3); | ||
expect(table.rows.get(0).valueMap.get(COUNT_DIMENSION)).to.eql(new Value(COUNT_DIMENSION, 1)); | ||
expect(table.rows.get(1).valueMap.get(COUNT_DIMENSION)).to.eql(new Value(COUNT_DIMENSION, 3)); | ||
expect(table.rows.get(2).valueMap.get(COUNT_DIMENSION)).to.eql(new Value(COUNT_DIMENSION, 8)); | ||
expect(table.rows.get(0).valueMap.get(countDimension)).to.eql(new Value(countDimension, 1)); | ||
expect(table.rows.get(1).valueMap.get(countDimension)).to.eql(new Value(countDimension, 3)); | ||
expect(table.rows.get(2).valueMap.get(countDimension)).to.eql(new Value(countDimension, 8)); | ||
@@ -163,3 +203,3 @@ table.nest([platformDimension, urlDimension]); | ||
expect(table.rows.get(0).valueMap.size).to.eql(3); | ||
expect(table.rows.get(0).valueMap.get(COUNT_DIMENSION)).to.eql(4); | ||
expect(table.rows.get(0).valueMap.get(countDimension)).to.eql(4); | ||
expect(table.rows.get(0).valueMap.get(platformDimension)).to.eql('Desktop'); | ||
@@ -197,5 +237,5 @@ expect(table.rows.get(0).valueMap.get(browserDimension)).to.be.a(TableRow); | ||
expect(table.rows.get(1).valueMap.size).to.eql(3); | ||
expect(table.rows.get(1).valueMap.get(COUNT_DIMENSION)).to.be.a(Value); | ||
expect(table.rows.get(1).valueMap.get(COUNT_DIMENSION).dimension).to.eql(COUNT_DIMENSION); | ||
expect(table.rows.get(1).valueMap.get(COUNT_DIMENSION).value).to.eql(8); | ||
expect(table.rows.get(1).valueMap.get(countDimension)).to.be.a(Value); | ||
expect(table.rows.get(1).valueMap.get(countDimension).dimension).to.eql(countDimension); | ||
expect(table.rows.get(1).valueMap.get(countDimension).value).to.eql(8); | ||
expect(table.rows.get(1).valueMap.get(platformDimension)).to.eql('Mobile'); | ||
@@ -202,0 +242,0 @@ expect(table.rows.get(1).valueMap.get(browserDimension)).to.be.a(TableRow); |
@@ -126,3 +126,3 @@ 'use strict'; | ||
it('it pivots a single time dimension', () => { | ||
it('it pivots a single dimension with complex value', () => { | ||
let rows = [ | ||
@@ -129,0 +129,0 @@ new TableRow(Immutable.OrderedMap([ |
112451
2852