2021-03-04 11:05:50 +01:00
|
|
|
let TestConfig = require("./utilities/TestConfiguration")
|
|
|
|
let { basicDatasource } = require("./utilities/structures")
|
|
|
|
let { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
2021-01-14 21:51:03 +01:00
|
|
|
|
|
|
|
describe("/datasources", () => {
|
|
|
|
let request
|
2021-03-04 11:05:50 +01:00
|
|
|
let config
|
2021-01-14 21:51:03 +01:00
|
|
|
|
|
|
|
beforeAll(async () => {
|
2021-03-04 13:32:31 +01:00
|
|
|
config = new TestConfig()
|
|
|
|
request = config.request
|
|
|
|
})
|
2021-01-14 21:51:03 +01:00
|
|
|
|
|
|
|
afterAll(() => {
|
2021-03-04 13:32:31 +01:00
|
|
|
config.end()
|
2021-01-14 21:51:03 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2021-03-04 11:40:27 +01:00
|
|
|
await config.init()
|
2021-01-14 21:51:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("create", () => {
|
|
|
|
it("should create a new datasource", async () => {
|
|
|
|
const res = await request
|
|
|
|
.post(`/api/datasources`)
|
2021-03-04 11:05:50 +01:00
|
|
|
.send(basicDatasource())
|
2021-03-04 11:40:27 +01:00
|
|
|
.set(config.defaultHeaders())
|
2021-01-14 21:51:03 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
|
|
|
|
expect(res.res.statusMessage).toEqual("Datasource saved successfully.");
|
|
|
|
expect(res.body.name).toEqual("Test");
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("fetch", () => {
|
|
|
|
let datasource
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2021-03-04 11:05:50 +01:00
|
|
|
datasource = await config.createDatasource()
|
2021-01-14 21:51:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
delete datasource._rev
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns all the datasources from the server", async () => {
|
|
|
|
const res = await request
|
|
|
|
.get(`/api/datasources`)
|
2021-03-04 11:40:27 +01:00
|
|
|
.set(config.defaultHeaders())
|
2021-01-14 21:51:03 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
|
2021-03-04 11:05:50 +01:00
|
|
|
const datasources = res.body
|
2021-01-14 21:51:03 +01:00
|
|
|
expect(datasources).toEqual([
|
|
|
|
{
|
2021-03-04 11:05:50 +01:00
|
|
|
"_id": datasources[0]._id,
|
2021-01-14 21:51:03 +01:00
|
|
|
"_rev": datasources[0]._rev,
|
2021-03-04 11:05:50 +01:00
|
|
|
...basicDatasource()
|
2021-01-14 21:51:03 +01:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should apply authorization to endpoint", async () => {
|
2021-03-04 11:05:50 +01:00
|
|
|
await checkBuilderEndpoint({
|
|
|
|
config,
|
2021-01-14 21:51:03 +01:00
|
|
|
method: "GET",
|
|
|
|
url: `/api/datasources`,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("destroy", () => {
|
2021-03-04 11:05:50 +01:00
|
|
|
let datasource
|
2021-01-14 21:51:03 +01:00
|
|
|
|
|
|
|
beforeEach(async () => {
|
2021-03-04 11:05:50 +01:00
|
|
|
datasource = await config.createDatasource()
|
2021-01-14 21:51:03 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
delete datasource._rev
|
|
|
|
});
|
|
|
|
|
|
|
|
it("deletes queries for the datasource after deletion and returns a success message", async () => {
|
2021-03-04 11:05:50 +01:00
|
|
|
await config.createQuery()
|
2021-01-14 21:51:03 +01:00
|
|
|
|
|
|
|
await request
|
2021-03-04 11:05:50 +01:00
|
|
|
.delete(`/api/datasources/${datasource._id}/${datasource._rev}`)
|
2021-03-04 11:40:27 +01:00
|
|
|
.set(config.defaultHeaders())
|
2021-01-14 21:51:03 +01:00
|
|
|
.expect(200)
|
|
|
|
|
|
|
|
const res = await request
|
|
|
|
.get(`/api/datasources`)
|
2021-03-04 11:40:27 +01:00
|
|
|
.set(config.defaultHeaders())
|
2021-01-14 21:51:03 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
|
|
|
|
expect(res.body).toEqual([])
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should apply authorization to endpoint", async () => {
|
2021-03-04 11:05:50 +01:00
|
|
|
await checkBuilderEndpoint({
|
|
|
|
config,
|
2021-01-14 21:51:03 +01:00
|
|
|
method: "DELETE",
|
|
|
|
url: `/api/datasources/${datasource._id}/${datasource._rev}`,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|