2020-04-09 17:53:48 +02:00
|
|
|
const supertest = require("supertest");
|
|
|
|
const app = require("../../../../app");
|
2020-04-10 12:18:15 +02:00
|
|
|
const { createInstanceDatabase, destroyDatabase } = require("./couchTestUtils");
|
2020-04-09 17:53:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
const TEST_INSTANCE_ID = "testing-123";
|
|
|
|
|
|
|
|
describe("/databases", () => {
|
|
|
|
let request;
|
2020-04-10 12:18:15 +02:00
|
|
|
let server;
|
2020-04-09 17:53:48 +02:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
2020-04-10 12:18:15 +02:00
|
|
|
server = await app({
|
2020-04-09 17:53:48 +02:00
|
|
|
config: {
|
|
|
|
port: 3000
|
|
|
|
}
|
|
|
|
});
|
|
|
|
request = supertest(server);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
2020-04-10 12:18:15 +02:00
|
|
|
server.close();
|
2020-04-09 17:53:48 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("create", () => {
|
2020-04-10 12:18:15 +02:00
|
|
|
afterEach(async () => {
|
|
|
|
await destroyDatabase(TEST_INSTANCE_ID);
|
|
|
|
});
|
|
|
|
|
2020-04-09 17:53:48 +02:00
|
|
|
it("returns a success message when the instance database is successfully created", done => {
|
|
|
|
request
|
|
|
|
.post(`/api/databases`)
|
|
|
|
.send({ name: TEST_INSTANCE_ID })
|
|
|
|
.set("Accept", "application/json")
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.end(async (err, res) => {
|
|
|
|
expect(res.body.message).toEqual("Instance Database testing-123 successfully provisioned.");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("destroy", () => {
|
2020-04-10 12:18:15 +02:00
|
|
|
beforeEach(async () => {
|
|
|
|
await createInstanceDatabase(TEST_INSTANCE_ID);
|
|
|
|
});
|
|
|
|
|
2020-04-09 17:53:48 +02:00
|
|
|
it("returns a success message when the instance database is successfully deleted", done => {
|
|
|
|
request
|
|
|
|
.delete(`/api/databases/${TEST_INSTANCE_ID}`)
|
|
|
|
.set("Accept", "application/json")
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.end(async (err, res) => {
|
|
|
|
expect(res.body.message).toEqual("Instance Database testing-123 successfully destroyed.");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|