// (C) 2007-2019 GoodData Corporation import { ExecuteAFM as AFM } from "@gooddata/typings"; import { getMetric, getDisplayForm } from "../afm"; import { buildProject } from "../../../../schema/builder"; import { schema } from "../../../../schema/fixtures/dummySchema"; describe("AFM", () => { const project = buildProject(schema); const [metric] = project.groups[0].metrics; const [displayForm] = project.groups[0].attributes[0].content.displayForms; describe("getMetric", () => { it("should return metadata metric by AFM measure with uri", () => { const measure: AFM.IMeasure = { localIdentifier: "1", definition: { measure: { item: { uri: metric.meta.uri, }, }, }, }; expect(getMetric(project, measure)).not.toBeUndefined(); expect(getMetric(project, measure)).toEqual(metric); }); it("should return metadata metric by AFM measure with identifier", () => { const measure: AFM.IMeasure = { localIdentifier: "1", definition: { measure: { item: { identifier: metric.meta.identifier, }, }, }, }; expect(getMetric(project, measure)).not.toBeUndefined(); expect(getMetric(project, measure)).toEqual(metric); }); it("should throw if PoP measure requested", () => { const measure: AFM.IMeasure = { localIdentifier: "1", definition: { popMeasure: { measureIdentifier: "2", popAttribute: { uri: displayForm.meta.uri, }, }, }, }; expect(() => getMetric(project, measure)).toThrowError(); }); it("should throw if previous period measure requested", () => { const measure: AFM.IMeasure = { localIdentifier: "1", definition: { previousPeriodMeasure: { measureIdentifier: "2", dateDataSets: [ { dataSet: { uri: displayForm.meta.uri, }, periodsAgo: 1, }, ], }, }, }; expect(() => getMetric(project, measure)).toThrowError(); }); }); describe("getDisplayForm", () => { it("should return metadata display form by AFM attribute with uri", () => { const attribute: AFM.IAttribute = { localIdentifier: "1", displayForm: { uri: displayForm.meta.uri, }, }; expect(getDisplayForm(project, attribute)).not.toBeNull(); expect(getDisplayForm(project, attribute)).toEqual(displayForm); }); it("should return metadata display form by AFM attribute with identifier", () => { const attribute: AFM.IAttribute = { localIdentifier: "1", displayForm: { identifier: displayForm.meta.identifier, }, }; expect(getDisplayForm(project, attribute)).not.toBeNull(); expect(getDisplayForm(project, attribute)).toEqual(displayForm); }); }); });