Skip to content

Commit

Permalink
update fromViewDefinition argument order in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmroz-allegro committed Nov 24, 2022
1 parent 549416e commit ee957db
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/common/utils/url-hash-converter/url-hash-converter.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("urlHashConverter", () => {
const { visualization } = essence;

it(`decodes ${visualization.name} version ${version} correctly`, () => {
const decodedEssence = urlHashConverter.essenceFromHash(hash, wikiClientDataCube, clientAppSettings);
const decodedEssence = urlHashConverter.essenceFromHash(hash, clientAppSettings, wikiClientDataCube);

expect(decodedEssence.toJS()).to.deep.equal(essence.toJS());
});
Expand All @@ -59,7 +59,7 @@ describe("urlHashConverter", () => {
const { visualization } = essence;

it(`decodes ${visualization.name} version ${version} correctly`, () => {
const decodedEssence = urlHashConverter.essenceFromHash(hash, wikiClientDataCube, clientAppSettings);
const decodedEssence = urlHashConverter.essenceFromHash(hash, clientAppSettings, wikiClientDataCube);

expect(decodedEssence.toJS()).to.deep.equal(essence.toJS());
});
Expand All @@ -76,14 +76,14 @@ describe("urlHashConverter", () => {
const { visualization } = essence;

it(`decodes ${visualization.name} version ${version} correctly`, () => {
const decodedEssence = urlHashConverter.essenceFromHash(hash, wikiClientDataCube, clientAppSettings);
const decodedEssence = urlHashConverter.essenceFromHash(hash, clientAppSettings, wikiClientDataCube);

expect(decodedEssence.toJS()).to.deep.equal(essence.toJS());
});

it(`is symmetric in decode/encode for ${visualization.name} in version ${version}`, () => {
const encodedHash = urlHashConverter.toHash(essence, version);
const decodedEssence = urlHashConverter.essenceFromHash(encodedHash, wikiClientDataCube, clientAppSettings);
const decodedEssence = urlHashConverter.essenceFromHash(encodedHash, clientAppSettings, wikiClientDataCube);

expect(essence.toJS()).to.deep.equal(decodedEssence.toJS());
});
Expand All @@ -94,7 +94,7 @@ describe("urlHashConverter", () => {
}

it(`is symmetric in encode/decode for ${visualization.name} in version ${version}`, () => {
const decodedEssence = urlHashConverter.essenceFromHash(hash, wikiClientDataCube, clientAppSettings);
const decodedEssence = urlHashConverter.essenceFromHash(hash, clientAppSettings, wikiClientDataCube);
const encodedHash = urlHashConverter.toHash(decodedEssence, version);

try {
Expand All @@ -116,7 +116,7 @@ describe("urlHashConverter", () => {

minimalNumberOfSegmentsTests.forEach(({ version, hash }) => {
it(`decodes version ${version} with minimal number of segments`, () => {
const decodedEssence = urlHashConverter.essenceFromHash(hash, wikiClientDataCube, clientAppSettings);
const decodedEssence = urlHashConverter.essenceFromHash(hash, clientAppSettings, wikiClientDataCube);

expect(decodedEssence).to.be.an.instanceOf(Essence);
});
Expand All @@ -131,7 +131,7 @@ describe("urlHashConverter", () => {

wrongHashStructureTests.forEach(({ hash, errorMessage }) => {
it(`throws error for hash: "${hash}" with wrong structure`, () => {
const essenceFromHashCall = () => urlHashConverter.essenceFromHash(hash, wikiClientDataCube, clientAppSettings);
const essenceFromHashCall = () => urlHashConverter.essenceFromHash(hash, clientAppSettings, wikiClientDataCube);
expect(essenceFromHashCall).to.throw(errorMessage);
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/common/view-definitions/test/essence.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { day, Duration, Timezone } from "chronoshift";
import { OrderedSet } from "immutable";
import { clientAppSettings } from "../../models/app-settings/app-settings.fixtures";
import { Essence, EssenceValue } from "../../models/essence/essence";
import { RelativeTimeFilterClause, TimeFilterPeriod } from "../../models/filter-clause/filter-clause";
import { Filter } from "../../models/filter/filter";
Expand Down Expand Up @@ -61,6 +62,7 @@ const defaults: EssenceOptions = {

export function mockEssence(opts: Partial<EssenceOptions> = {}) {
return new Essence({
appSettings: clientAppSettings,
dataCube,
...defaults,
...opts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { expect } from "chai";
import { clientAppSettings } from "../../models/app-settings/app-settings.fixtures";
import { wikiClientDataCube } from "../../models/data-cube/data-cube.fixtures";
import { TimeFilterPeriod } from "../../models/filter-clause/filter-clause";
import { stringIn, timePeriod } from "../../models/filter-clause/filter-clause.fixtures";
Expand Down Expand Up @@ -64,7 +65,7 @@ describe("ViewDefinitionConverter2", () => {
].forEach(({ label, expression, period }) => {
it(`converts ${label} bucket expression to time period`, () => {
const viewDefinition = ViewDefinitionConverter2Fixtures.withFilterExpression(expression);
const essence = new ViewDefinitionConverter2().fromViewDefinition(viewDefinition, wikiClientDataCube);
const essence = new ViewDefinitionConverter2().fromViewDefinition(viewDefinition, clientAppSettings, wikiClientDataCube);
const convertedClause = essence.filter.clauses.first();

const expectedClause = timePeriod("time", "P1D", period);
Expand Down Expand Up @@ -125,7 +126,7 @@ describe("ViewDefinitionConverter2", () => {
}
}
]);
const convertedFilter = new ViewDefinitionConverter2().fromViewDefinition(viewDefinition, wikiClientDataCube).filter;
const convertedFilter = new ViewDefinitionConverter2().fromViewDefinition(viewDefinition, clientAppSettings, wikiClientDataCube).filter;
const convertedClause = convertedFilter.clauses.get(1);

const expectedClause = stringIn("page_last_author", ["TypeScript"]);
Expand Down Expand Up @@ -160,7 +161,7 @@ describe("ViewDefinitionConverter2", () => {
limit: 10
}
}]);
const convertedSplits = new ViewDefinitionConverter2().fromViewDefinition(viewDefinition, wikiClientDataCube).splits;
const convertedSplits = new ViewDefinitionConverter2().fromViewDefinition(viewDefinition, clientAppSettings, wikiClientDataCube).splits;

expect(convertedSplits.getSplit(0).reference).to.equal("page_last_author");
});
Expand Down
3 changes: 2 additions & 1 deletion src/common/view-definitions/version-4/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

import { clientAppSettings } from "../../../models/app-settings/app-settings.fixtures";
import { Essence } from "../../../models/essence/essence";
import { assertEqlEssence } from "../../test/assertions";
import { dataCube } from "../../test/data-cube.fixture";
import { ViewDefinition4 } from "../view-definition-4";
import { ViewDefinitionConverter4 } from "../view-definition-converter-4";

const converter = new ViewDefinitionConverter4();
export const toEssence = (viewDef: ViewDefinition4) => converter.fromViewDefinition(viewDef, dataCube);
export const toEssence = (viewDef: ViewDefinition4) => converter.fromViewDefinition(viewDef, clientAppSettings, dataCube);

export function assertConversionToEssence(viewDef: ViewDefinition4, essence: Essence) {
assertEqlEssence(toEssence(viewDef), essence);
Expand Down

0 comments on commit ee957db

Please sign in to comment.