Fix server query tests
This commit is contained in:
parent
9b21eb78b6
commit
4c53e4bcec
|
@ -4,7 +4,7 @@ const {
|
||||||
defaultHeaders,
|
defaultHeaders,
|
||||||
builderEndpointShouldBlockNormalUsers,
|
builderEndpointShouldBlockNormalUsers,
|
||||||
getDocument,
|
getDocument,
|
||||||
insertDocument
|
insertDocument,
|
||||||
} = require("./couchTestUtils")
|
} = require("./couchTestUtils")
|
||||||
let { generateDatasourceID, generateQueryID } = require("../../../db/utils")
|
let { generateDatasourceID, generateQueryID } = require("../../../db/utils")
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ const TEST_DATASOURCE = {
|
||||||
const TEST_QUERY = {
|
const TEST_QUERY = {
|
||||||
_id: generateQueryID(DATASOURCE_ID),
|
_id: generateQueryID(DATASOURCE_ID),
|
||||||
datasourceId: DATASOURCE_ID,
|
datasourceId: DATASOURCE_ID,
|
||||||
name:"New Query",
|
name: "New Query",
|
||||||
parameters:[],
|
parameters: [],
|
||||||
fields:{},
|
fields: {},
|
||||||
schema:{},
|
schema: {},
|
||||||
queryVerb:"read",
|
queryVerb: "read",
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("/queries", () => {
|
describe("/queries", () => {
|
||||||
|
@ -37,8 +37,8 @@ describe("/queries", () => {
|
||||||
let query
|
let query
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
({ request, server } = await supertest())
|
;({ request, server } = await supertest())
|
||||||
});
|
})
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
server.close()
|
server.close()
|
||||||
|
@ -47,7 +47,7 @@ describe("/queries", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
app = await createApplication(request)
|
app = await createApplication(request)
|
||||||
appId = app.instance._id
|
appId = app.instance._id
|
||||||
});
|
})
|
||||||
|
|
||||||
async function createDatasource() {
|
async function createDatasource() {
|
||||||
return await insertDocument(appId, TEST_DATASOURCE)
|
return await insertDocument(appId, TEST_DATASOURCE)
|
||||||
|
@ -63,65 +63,68 @@ describe("/queries", () => {
|
||||||
.post(`/api/queries`)
|
.post(`/api/queries`)
|
||||||
.send(TEST_QUERY)
|
.send(TEST_QUERY)
|
||||||
.set(defaultHeaders(appId))
|
.set(defaultHeaders(appId))
|
||||||
.expect('Content-Type', /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(res.res.statusMessage).toEqual(`Query ${TEST_QUERY.name} saved successfully.`);
|
expect(res.res.statusMessage).toEqual(
|
||||||
expect(res.body).toEqual({
|
`Query ${TEST_QUERY.name} saved successfully.`
|
||||||
_rev: res.body._rev,
|
)
|
||||||
...TEST_QUERY,
|
expect(res.body).toEqual({
|
||||||
});
|
_rev: res.body._rev,
|
||||||
|
...TEST_QUERY,
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
let datasource
|
let datasource
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
datasource = await createDatasource()
|
datasource = await createDatasource()
|
||||||
});
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
delete datasource._rev
|
delete datasource._rev
|
||||||
});
|
})
|
||||||
|
|
||||||
it("returns all the queries from the server", async () => {
|
it("returns all the queries from the server", async () => {
|
||||||
const query = await createQuery()
|
const query = await createQuery()
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/queries`)
|
.get(`/api/queries`)
|
||||||
.set(defaultHeaders(appId))
|
.set(defaultHeaders(appId))
|
||||||
.expect('Content-Type', /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
const queries = res.body;
|
const queries = res.body
|
||||||
expect(queries).toEqual([
|
expect(queries).toEqual([
|
||||||
{
|
{
|
||||||
"_rev": query.rev,
|
_rev: query.rev,
|
||||||
...TEST_QUERY
|
...TEST_QUERY,
|
||||||
}
|
readable: true,
|
||||||
]);
|
},
|
||||||
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
await builderEndpointShouldBlockNormalUsers({
|
await builderEndpointShouldBlockNormalUsers({
|
||||||
request,
|
request,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: `/api/datasources`,
|
url: `/api/datasources`,
|
||||||
appId: appId,
|
appId: appId,
|
||||||
})
|
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("destroy", () => {
|
describe("destroy", () => {
|
||||||
let datasource;
|
let datasource
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
datasource = await createDatasource()
|
datasource = await createDatasource()
|
||||||
});
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
delete datasource._rev
|
delete datasource._rev
|
||||||
});
|
})
|
||||||
|
|
||||||
it("deletes a query and returns a success message", async () => {
|
it("deletes a query and returns a success message", async () => {
|
||||||
const query = await createQuery()
|
const query = await createQuery()
|
||||||
|
@ -134,10 +137,10 @@ describe("/queries", () => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.get(`/api/queries`)
|
.get(`/api/queries`)
|
||||||
.set(defaultHeaders(appId))
|
.set(defaultHeaders(appId))
|
||||||
.expect('Content-Type', /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
expect(res.body).toEqual([])
|
expect(res.body).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should apply authorization to endpoint", async () => {
|
it("should apply authorization to endpoint", async () => {
|
||||||
|
@ -148,5 +151,5 @@ describe("/queries", () => {
|
||||||
appId: appId,
|
appId: appId,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
Loading…
Reference in New Issue