Improved histogram assertion with moment.js

This commit is contained in:
Daniel García Aubert
2017-06-05 14:18:24 +02:00
parent 6ff3b33cde
commit 71e9e62db0
3 changed files with 32 additions and 16 deletions
+17 -2
View File
@@ -2,6 +2,7 @@ require('../../support/test_helper');
var assert = require('../../support/assert');
var TestClient = require('../../support/test-client');
var moment = require('moment');
function createMapConfig(layers, dataviews, analysis) {
return {
@@ -206,8 +207,10 @@ describe('histogram-dataview for date column type', function() {
});
it('should aggregate respecting timezone', function (done) {
var TIMEZONE_CEST_IN_SECONDS = 2 * 3600; // Central European Summer Time (Daylight Saving Time)
var TIMEZONE_CEST_IN_MINUTES = 2 * 60; // Central European Summer Time (Daylight Saving Time)
var params = {
timezone: 7200 // GMT +2h
timezone: TIMEZONE_CEST_IN_SECONDS
};
this.testClient = new TestClient(mapConfig, 1234);
@@ -216,7 +219,19 @@ describe('histogram-dataview for date column type', function() {
assert.equal(dataview.type, 'histogram');
assert.ok(dataview.bin_width > 0, 'Unexpected bin width: ' + dataview.bin_width);
assert.equal(dataview.bins.length, 15);
dataview.bins.forEach(function(bin) {
var initialTimestamp = '2007-02-01T00:00:00+02:00';
var binsStartInMilliseconds = dataview.bins_start * 1000;
var binsStartFormatted = moment.utc(binsStartInMilliseconds).utcOffset(TIMEZONE_CEST_IN_MINUTES).format();
assert.equal(binsStartFormatted, initialTimestamp);
dataview.bins.forEach(function(bin, index) {
var binTimestampExpected = moment.utc(initialTimestamp).utcOffset(TIMEZONE_CEST_IN_MINUTES).add(index, 'month').format();
console.log(binTimestampExpected);
var binsTimestampInMilliseconds = bin.timestamp * 1000;
var binTimestampFormatted = moment.utc(binsTimestampInMilliseconds).utcOffset(TIMEZONE_CEST_IN_MINUTES).format();
assert.equal(binTimestampFormatted, binTimestampExpected);
assert.ok(bin.min <= bin.max, 'bin min < bin max: ' + JSON.stringify(bin));
});