budibase/packages/server/middleware/routes/neo/tests/instance.spec.js

78 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-04-09 17:53:48 +02:00
const supertest = require("supertest");
const app = require("../../../../app");
const {
createInstanceDatabase,
destroyDatabase,
createClientDatabase,
destroyClientDatabase
} = require("./couchTestUtils");
2020-04-09 17:53:48 +02:00
const TEST_INSTANCE_ID = "testing-123";
const TEST_APP_ID = "test-app";
2020-04-09 17:53:48 +02:00
describe("/instances", () => {
2020-04-09 17:53:48 +02:00
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", () => {
beforeEach(async () => {
await createClientDatabase();
});
2020-04-10 12:18:15 +02:00
afterEach(async () => {
await destroyClientDatabase();
2020-04-10 12:18:15 +02:00
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/testing/${TEST_APP_ID}/instances`)
2020-04-09 17:53:48 +02:00
.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 createClientDatabase();
2020-04-10 12:18:15 +02:00
await createInstanceDatabase(TEST_INSTANCE_ID);
});
afterEach(async () => {
await destroyClientDatabase();
});
2020-04-09 17:53:48 +02:00
it("returns a success message when the instance database is successfully deleted", done => {
request
.delete(`/api/instances/${TEST_INSTANCE_ID}`)
2020-04-09 17:53:48 +02:00
.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();
});
})
});
});