// (C) 2007-2019 GoodData Corporation import * as request from "supertest"; import * as HttpStatusCodes from "http-status-codes"; import { log } from "../log"; import { createEndpoint } from "../../../utils/tests"; import * as logErrors from "../../../constants/ProjectLogErrors"; import * as errors from "../../errors/errors"; import { ISchema } from "../../../schema/model/Schema"; const LOG_URI = "/gdc/app/projects/mockproject/log"; const schema: ISchema = { project: { identifier: "mockproject", title: "My title", }, }; const app = createEndpoint(log, schema); it("should return queried objects", () => { return request(app) .post(LOG_URI) .set("Content-Type", "application/json") .send({ logMessages: [ "adi-catalogue-ready total_count=69 metric_count=39 fact_count=10 attribute_count=20", ], }) .expect(HttpStatusCodes.NO_CONTENT) .then(res => { expect(res.text).toBe(""); }); }); it("should validate more than one root element", () => { return request(app) .post(LOG_URI) .set("Content-Type", "application/json") .send({ a: ["b"], c: ["d"], e: ["f"], }) .expect(HttpStatusCodes.BAD_REQUEST) .then(res => { expect(res.body).toEqual(errors.moreThanOneRootElement()); }); }); it("should validate invalid element key", () => { const validKey = "logMessages"; const invalidKey = "invalidLogMessagesElementKey"; const invalidMessage = {}; invalidMessage[invalidKey] = {}; return request(app) .post(LOG_URI) .set("Content-Type", "application/json") .send(invalidMessage) .expect(HttpStatusCodes.BAD_REQUEST) .then(res => { expect(res.body).toEqual(errors.invalidElementKey(validKey, invalidKey)); }); }); it("should validate invalid element type", () => { return request(app) .post(LOG_URI) .set("Content-Type", "application/json") .send({ logMessages: {}, }) .expect(HttpStatusCodes.BAD_REQUEST) .then(res => { expect(res.body).toEqual(logErrors.INVALID_ELEMENT_TYPE); }); }); it("should validate invalid types in element", () => { return request(app) .post(LOG_URI) .set("Content-Type", "application/json") .send({ logMessages: [0, 1, 2, 3, 4, 5], }) .expect(HttpStatusCodes.BAD_REQUEST) .then(res => { expect(res.body).toEqual(logErrors.INVALID_TYPES_IN_ELEMENT); }); });