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

74 lines
1.8 KiB
JavaScript
Raw Normal View History

const {
supertest,
2020-05-27 18:23:01 +02:00
defaultHeaders,
} = require("./utilities")
const TestConfig = require("./utilities/TestConfiguration")
const { clearAllApps, checkBuilderEndpoint } = require("./utilities/TestFunctions")
2020-04-09 17:53:48 +02:00
describe("/applications", () => {
2020-05-14 16:12:30 +02:00
let request
let server
let config
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 () => {
await clearAllApps()
config = new TestConfig(request)
await config.init()
})
2020-10-28 23:37:58 +01:00
afterAll(() => {
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" })
2020-06-18 17:59:31 +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()
})
2020-05-27 18:23:01 +02:00
2020-06-18 21:41:37 +02:00
it("should apply authorization to endpoint", async () => {
await checkBuilderEndpoint({
config,
2020-05-27 18:23:01 +02:00
method: "POST",
url: `/api/applications`,
body: { name: "My App" }
})
})
})
describe("fetch", () => {
it("lists all applications", async () => {
await config.createApp(request, "app1")
await config.createApp(request, "app2")
const res = await request
.get("/api/applications")
2020-06-18 17:59:31 +02:00
.set(defaultHeaders())
2020-04-09 17:53:48 +02:00
.expect('Content-Type', /json/)
.expect(200)
// two created apps + the inited app
expect(res.body.length).toBe(3)
})
2020-05-27 18:23:01 +02:00
it("should apply authorization to endpoint", async () => {
await checkBuilderEndpoint({
config,
2020-05-27 18:23:01 +02:00
method: "GET",
url: `/api/applications`,
})
})
})
})