/* * Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre * Departamento de Informatica - Universidade Federal do Parana * * This file is part of blendb. * * blendb is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * blendb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with blendb. If not, see <http://www.gnu.org/licenses/>. */ import * as request from "supertest"; import { expect } from "chai"; import * as server from "../../main"; describe("API collect controller", () => { it("should respond 400 when _id field is in request body", (done) => { request(server) .post("/v1/collect/class") .send({"_id": 1}) .expect(400) .expect((res: any) => { const message = "Property named \"_id\" is protected."; expect(res.body).to.be.an("object"); expect(res.body).to.have.property("message"); expect(res.body.message).to.be.eql(message); }) .end(done); }); it("should respond 500 on error on writing in the database", (done) => { request(server) .post("/v1/collect/class") .send({"field1": 1, "field2": 2}) .expect(500) .expect((res: any) => { const message = "Error while writing to the database."; expect(res.body).to.be.an("object"); expect(res.body).to.have.property("message"); expect(res.body.message).to.be.eql(message); }) .end(done); }); });