Skip to content
This repository was archived by the owner on Mar 4, 2022. It is now read-only.

Commit bec91df

Browse files
committed
create tests for empty averages
1 parent 925194c commit bec91df

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/lib/providers/metrics-provider.spec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ var createMockMetric = function () {
2424
};
2525
};
2626

27+
var mapToAverage = function (metric) {
28+
return {
29+
metricA: {
30+
valueA: +metric.metricA.valueA.toFixed(1)
31+
},
32+
metricB: {
33+
valueA: +metric.metricB.valueA.toFixed(1),
34+
valueB: +metric.metricB.valueB.toFixed(1)
35+
}
36+
};
37+
};
38+
2739
describe("MetricsProvider", function () {
2840
var sandbox;
2941
var testContainer;
@@ -163,6 +175,61 @@ describe("MetricsProvider", function () {
163175
});
164176
});
165177

178+
it("creates missing average even if first", function () {
179+
var timeKey = AGGREGATE_TIME_LEVELS[0];
180+
var timeLength = +timeKey;
181+
182+
// Fill 2 time slots skiping the first
183+
// 2 slots are needed to cause average calculation
184+
var mockMetrics = fill(2, timeLength);
185+
186+
expect(metricsProvider._aggregation[timeKey].data)
187+
.to.be.an("array")
188+
.that.eql([
189+
{
190+
metricA: {
191+
valueA: 0
192+
},
193+
metricB: {
194+
valueA: 0,
195+
valueB: 0
196+
}
197+
},
198+
mapToAverage(mockMetrics[0])
199+
]);
200+
});
201+
202+
it("creates missing average in the middle", function () {
203+
var timeKey = AGGREGATE_TIME_LEVELS[0];
204+
var timeLength = +timeKey;
205+
206+
// Fill data until first average created
207+
var mockMetrics = fill(2, timeLength - 1);
208+
209+
// Then add 1 more metric to split lastTimeIndex from lastAggregateIndex
210+
mockMetrics = mockMetrics.concat(fill(1, timeLength * 2));
211+
212+
// Then skip a time slot and add 1 more metric
213+
mockMetrics = mockMetrics.concat(fill(1, timeLength * 3));
214+
215+
expect(metricsProvider._aggregation[timeKey].data)
216+
.to.be.an("array")
217+
.that.eql([
218+
mapToAverage(mockMetrics[0]),
219+
mapToAverage(mockMetrics[1]),
220+
{
221+
metricA: {
222+
valueA: 0
223+
},
224+
metricB: {
225+
valueA: 0,
226+
valueB: 0
227+
}
228+
},
229+
mapToAverage(mockMetrics[2])
230+
]);
231+
});
232+
166233
it("aggregates metrics into time buckets", function () {
167234
// Fill in a single event so all future events result in a average calculation
168235
var mockMetrics = fill(1, 1);

0 commit comments

Comments
 (0)