2020-05-14 16:12:30 +02:00
|
|
|
const {
|
|
|
|
createClientDatabase,
|
2020-05-18 07:40:29 +02:00
|
|
|
createApplication,
|
|
|
|
destroyClientDatabase,
|
|
|
|
supertest,
|
|
|
|
defaultHeaders
|
2020-05-14 16:12:30 +02:00
|
|
|
} = require("./couchTestUtils")
|
2020-04-09 17:53:48 +02:00
|
|
|
|
|
|
|
describe("/applications", () => {
|
2020-05-14 16:12:30 +02:00
|
|
|
let request
|
|
|
|
let server
|
2020-04-09 17:53:48 +02:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
2020-05-14 16:12:30 +02:00
|
|
|
({ request, server } = await supertest())
|
2020-04-09 17:53:48 +02:00
|
|
|
});
|
|
|
|
|
2020-05-18 07:40:29 +02:00
|
|
|
beforeEach(async () => {
|
2020-05-18 11:28:38 +02:00
|
|
|
await createClientDatabase()
|
2020-05-18 07:40:29 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(async () => {
|
2020-05-18 11:28:38 +02:00
|
|
|
await destroyClientDatabase()
|
2020-05-18 07:40:29 +02:00
|
|
|
})
|
|
|
|
|
2020-04-09 17:53:48 +02:00
|
|
|
afterAll(async () => {
|
2020-05-14 16:12:30 +02:00
|
|
|
server.close()
|
2020-04-09 17:53:48 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
describe("create", () => {
|
2020-05-18 07:40:29 +02:00
|
|
|
it("returns a success message when the application is successfully created", async () => {
|
|
|
|
const res = await request
|
2020-05-14 16:12:30 +02:00
|
|
|
.post("/api/applications")
|
2020-04-09 17:53:48 +02:00
|
|
|
.send({ name: "My App" })
|
2020-05-18 07:40:29 +02:00
|
|
|
.set(defaultHeaders)
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
expect(res.res.statusMessage).toEqual("Application My App created successfully")
|
|
|
|
expect(res.body._id).toBeDefined()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("fetch", () => {
|
|
|
|
it("lists all applications", async () => {
|
|
|
|
|
|
|
|
await createApplication(request, "app1")
|
|
|
|
await createApplication(request, "app2")
|
|
|
|
|
|
|
|
const res = await request
|
|
|
|
.get("/api/applications")
|
|
|
|
.set(defaultHeaders)
|
2020-04-09 17:53:48 +02:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
2020-05-18 07:40:29 +02:00
|
|
|
|
|
|
|
expect(res.body.length).toBe(2)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|