// (C) 2007-2019 GoodData Corporation import * as request from "supertest"; import { createEndpoint } from "../../../utils/tests"; import { ISchema } from "../../../schema/model/Schema"; import { query } from "../query"; it("should return queried objects", () => { const schema: ISchema = { groups: [ { attributes: [ { title: "Customer", elements: ["John Doe", "Jane Doe"], }, ], facts: [], metrics: [ { expression: "Foo", title: "Amount", }, ], }, ], project: { identifier: "mockproject", title: "My title", }, }; const app = createEndpoint(query, schema); return request(app) .get("/gdc/md/mockproject/query/attributes") .expect(200) .then(res => { expect(res.body).toEqual({ query: { entries: [ { category: "attribute", link: "/gdc/md/mockproject/obj/attr.customer", identifier: "attr.customer", title: "Customer", }, ], meta: { category: "query", summary: "Meta Query Resources for project 'mockproject'", title: "List of attributes", }, }, }); }); }); it("should return an error message in case of uknown type queried", () => { const schema: ISchema = { groups: [ { attributes: [], facts: [], metrics: [], }, ], project: { identifier: "mockproject", title: "My title", }, }; const app = createEndpoint(query, schema); return request(app) .get("/gdc/md/mockproject/query/unknown-type") .expect(404) .then(res => { expect(res.body).toEqual({ error: { component: "metadata", errorClass: "foo.bar", message: "Unknown type '%s'", parameters: ["unknown-type"], }, }); }); }); describe("analyticalDashboards", () => { it("should return list of analytical Dashboards", () => { const schema: ISchema = { project: { identifier: "mockproject", title: "My title", }, users: [ { identifier: "123456", email: "john.doe@example.com", }, ], analyticalDashboards: [ { identifier: "22223", title: "meine dashbo", }, ], }; const app = createEndpoint(query, schema); return request(app) .get("/gdc/md/mockproject/query/analyticaldashboard") .expect(200) .then(res => { const response = res.body; expect(response.query.entries.length).toEqual(1); expect(response.query.entries[0].link).toEqual( `/gdc/md/mockproject/obj/${schema.analyticalDashboards[0].identifier}`, ); }); }); it("should create multiple dashboards", () => { const schema: ISchema = { project: { identifier: "mockproject", title: "My title", }, users: [ { identifier: "123456", email: "john.doe@example.com", }, ], analyticalDashboards: [ { identifier: "22223", title: "meine dashbo", }, { identifier: "22224", title: "secondary dashbo", }, ], }; const app = createEndpoint(query, schema); return request(app) .get("/gdc/md/mockproject/query/analyticaldashboard") .expect(200) .then(res => { const response = res.body; expect(response.query.entries.length).toEqual(2); expect(response.query.entries[0].link).toEqual( `/gdc/md/mockproject/obj/${schema.analyticalDashboards[0].identifier}`, ); expect(response.query.entries[1].link).toEqual( `/gdc/md/mockproject/obj/${schema.analyticalDashboards[1].identifier}`, ); }); }); });