From 250f4af690668454dd04fa68c6c3c14b06d27137 Mon Sep 17 00:00:00 2001 From: Adrian Mroz Date: Mon, 31 Jan 2022 16:59:30 +0100 Subject: [PATCH] Add better warnings for missing timeAttribute property --- .../models/data-cube/data-cube.mocha.ts | 23 +++++++++++++++++++ src/common/models/data-cube/data-cube.ts | 5 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/common/models/data-cube/data-cube.mocha.ts b/src/common/models/data-cube/data-cube.mocha.ts index c7c6213c8..84c76598f 100644 --- a/src/common/models/data-cube/data-cube.mocha.ts +++ b/src/common/models/data-cube/data-cube.mocha.ts @@ -17,6 +17,7 @@ import { expect, use } from "chai"; import { $, AttributeInfo } from "plywood"; +import { SinonSpy, spy } from "sinon"; import equivalent from "../../../client/utils/test-utils/equivalent"; import { deduceAttributes } from "../../utils/external/datacube-to-external"; import { Cluster } from "../cluster/cluster"; @@ -724,6 +725,28 @@ describe("DataCube", () => { formula: "$__time" }; + describe("timeAttribute property warnings", () => { + let consoleWarnSpy: SinonSpy; + + beforeEach(() => { + consoleWarnSpy = spy(console, "warn"); + }); + + afterEach(() => { + consoleWarnSpy.restore(); + }); + + it("should warn if timeAttribute is missing", () => { + fromConfig({ ...baseCube }, druidCluster); + expect(consoleWarnSpy.args[0][0]).to.be.equal("DataCube \"wiki\" should have property timeAttribute. Setting timeAttribute to default value \"__time\""); + }); + + it("should warn if timeAttribute has different value than \"__time\"", () => { + fromConfig({ ...baseCube, timeAttribute: "foobar" }, druidCluster); + expect(consoleWarnSpy.args[0][0]).to.be.equal('timeAttribute in DataCube "wiki" should have value "__time" because it is required by Druid. Overriding timeAttribute to "__time"'); + }); + }); + it("should add timeAttribute", () => { const cube = fromConfig({ ...baseCube, dimensions: [timeDimensionJS] }, druidCluster); expect(cube.timeAttribute).to.be.equivalent($("__time")); diff --git a/src/common/models/data-cube/data-cube.ts b/src/common/models/data-cube/data-cube.ts index 3434532fc..5d8074604 100644 --- a/src/common/models/data-cube/data-cube.ts +++ b/src/common/models/data-cube/data-cube.ts @@ -281,7 +281,10 @@ function readAttributes(config: DataCubeJS): Pick