// (C) 2007-2019 GoodData Corporation import { createEndpoint } from "../../../utils/tests"; import { metadataObject } from "../metadataObject"; import * as request from "supertest"; import { ISchema } from "../../../schema/model/Schema"; const schema: ISchema = { project: { title: "My title", }, users: [ { identifier: "123456", email: "john.doe@example.com", }, ], groups: [ { attributes: [ { elements: ["a"], identifier: "firstAttribute", title: "First attribute", }, { elements: ["b"], identifier: "secondAttribute", title: "Second attribute", }, { elements: ["c"], identifier: "thirdAttribute", title: "Third attribute", }, ], metrics: [ { identifier: "firstMetric", title: "First metric", expression: "SELECT 1", }, { identifier: "secondMetric", title: "Second metric", expression: "SELECT 2", }, { identifier: "thirdMetric", title: "Third metric", expression: "SELECT 3", }, ], facts: [ { identifier: "firstFact", title: "First Fact", values: [1, 2, 3], }, { identifier: "secondFact", title: "Second Fact", values: [1, 2, 3], }, { identifier: "thirdFact", title: "Third Fact", values: [1, 2, 3], }, ], dateDataSets: [ { title: "First dateDataSet" }, { title: "Second dateDataSet" }, { title: "Third dateDataSet" }, ], }, ], analyticalDashboards: [ { identifier: "firstDashboard", title: "First Dashboard", }, { identifier: "secondDashboard", title: "Second Dashboard", widgets: [ { identifier: "widget_a", title: "Widget A", dateDataSetUri: "/gdc/md/mockproject/second_datedataset.dataset", visualizationUri: "/gdc/md/mockproject/vis_1", }, ], filterContext: { title: "FD FC", filters: [ { attributeFilter: { attributeElements: [], displayForm: "/gdc/md/mockproject/obj/attr.account.df", negativeSelection: true, }, }, ], }, }, { identifier: "thirdDashboard", title: "Third Dashboard", }, ], visualizationClasses: [ { title: "table_visclass", url: "local:table", }, ], visualizationObjects: [ { type: "local:table", title: "My visualization", identifier: "vis_1", }, ], dateFilterConfig: { allTime: { localIdentifier: "allTime", name: "All time", visible: true, }, selectedOption: "allTime", title: "Date filter", identifier: "defaultDateFilterConfig", }, }; const app = createEndpoint(metadataObject, schema); it("should return attribute", () => { return request(app) .get("/gdc/md/mockproject/obj/secondAttribute") .expect(200) .then(res => { expect(res.body.attribute.meta.identifier).toEqual("secondAttribute"); }); }); it("should return date attribute", () => { return request(app) .get("/gdc/md/mockproject/obj/attr.second_datedataset.year") .expect(200) .then(res => { expect(res.body.attribute.meta.identifier).toEqual("attr.second_datedataset.year"); }); }); it("should return date attribute display form", () => { const dfIdentifier = "attr.second_datedataset.year.df"; return request(app) .get(`/gdc/md/mockproject/obj/${dfIdentifier}`) .expect(200) .then(res => { expect(res.body.attributeDisplayForm.meta.identifier).toEqual(dfIdentifier); }); }); it("should return display form", () => { return request(app) .get("/gdc/md/mockproject/obj/secondAttribute.df") .expect(200) .then(res => { expect(res.body.attributeDisplayForm.meta.identifier).toEqual("secondAttribute.df"); }); }); it("should return metric", () => { return request(app) .get("/gdc/md/mockproject/obj/secondMetric") .expect(200) .then(res => { expect(res.body.metric.meta.identifier).toEqual("secondMetric"); }); }); it("should return fact", () => { return request(app) .get("/gdc/md/mockproject/obj/secondFact") .expect(200) .then(res => { expect(res.body.fact.meta.identifier).toEqual("secondFact"); }); }); it("should return dateDataSet", () => { return request(app) .get("/gdc/md/mockproject/obj/second_datedataset.dataset") .expect(200) .then(res => { expect(res.body.meta.identifier).toEqual("second_datedataset.dataset"); }); }); it("should return analyticalDashboard", () => { return request(app) .get("/gdc/md/mockproject/obj/secondDashboard") .expect(200) .then(res => { expect(res.body.analyticalDashboard.meta.identifier).toEqual("secondDashboard"); expect(res.body.analyticalDashboard.content.widgets).toEqual([ "/gdc/md/mockproject/obj/widget_a", ]); }); }); it("should return filterContext", () => { return request(app) .get("/gdc/md/mockproject/obj/fd_fc") .expect(200) .then(res => { expect(res.body.filterContext.meta.identifier).toEqual("fd_fc"); expect(res.body.filterContext.content.filters.length).toEqual(1); }); }); it("should return visualizationObject", () => { return request(app) .get("/gdc/md/mockproject/obj/vis_1") .expect(200) .then(res => { expect(res.body.visualizationObject.meta.identifier).toEqual("vis_1"); }); }); it("should return visualizationClass", () => { return request(app) .get("/gdc/md/mockproject/obj/table_visclass") .expect(200) .then(res => { expect(res.body.visualizationClass.meta.identifier).toEqual("table_visclass"); }); }); it("should return dateFilterConfig", () => { return request(app) .get("/gdc/md/mockproject/obj/defaultDateFilterConfig") .expect(200) .then(res => { expect(res.body.dateFilterConfig.meta.identifier).toEqual("defaultDateFilterConfig"); }); }); it("should allow object deleting", () => { return request(app) .delete("/gdc/md/mockproject/obj/secondAttribute") .expect(204) .then(res => { expect(res.body).toEqual({}); }); });