budibase/packages/server/src/api/routes/tests/application.spec.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-05-14 16:12:30 +02:00
const {
createClientDatabase,
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
});
beforeEach(async () => {
2020-05-18 11:28:38 +02:00
await createClientDatabase()
})
afterEach(async () => {
2020-05-18 11:28:38 +02:00
await destroyClientDatabase()
})
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", () => {
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" })
.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)
expect(res.body.length).toBe(2)
})
})
})