Adding a query find and planning to tackle mocking out the preview and execute functionality.

This commit is contained in:
mike12345567 2021-03-08 18:03:26 +00:00
parent 039de61de3
commit 8a0a0dabdb
3 changed files with 57 additions and 21 deletions

View File

@ -2,14 +2,17 @@ const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
const { basicQuery } = require("./utilities/structures")
const setup = require("./utilities")
describe("/queries", () => {
let request = setup.getRequest()
let config = setup.getConfig()
let datasource
afterAll(setup.afterAll)
beforeEach(async () => {
await config.init()
datasource = await config.createDatasource()
})
describe("create", () => {
@ -35,16 +38,6 @@ describe("/queries", () => {
})
describe("fetch", () => {
let datasource
beforeEach(async () => {
datasource = await config.createDatasource()
})
afterEach(() => {
delete datasource._rev
})
it("returns all the queries from the server", async () => {
const query = await config.createQuery()
const res = await request
@ -73,17 +66,33 @@ describe("/queries", () => {
})
})
describe("find", () => {
it("should find a query in builder", async () => {
const query = await config.createQuery()
const res = await request
.get(`/api/queries/${query._id}`)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(res.body._id).toEqual(query._id)
})
it("should find a query in cloud", async () => {
await setup.switchToCloudForFunction(async () => {
const query = await config.createQuery()
const res = await request
.get(`/api/queries/${query._id}`)
.set(await config.roleHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(res.body.fields).toBeUndefined()
expect(res.body.parameters).toBeUndefined()
expect(res.body.schema).toBeUndefined()
})
})
})
describe("destroy", () => {
let datasource
beforeEach(async () => {
datasource = await config.createDatasource()
})
afterEach(() => {
delete datasource._rev
})
it("deletes a query and returns a success message", async () => {
const query = await config.createQuery()
@ -109,4 +118,12 @@ describe("/queries", () => {
})
})
})
describe("preview", () => {
// TODO: need to mock out an integration with a test one and try this
})
describe("execute", () => {
// TODO: need to mock out an integration with a test one and try this
})
})

View File

@ -85,7 +85,7 @@ class TestConfiguration {
return headers
}
async roleHeaders(email = EMAIL, roleId) {
async roleHeaders(email = EMAIL, roleId = BUILTIN_ROLE_IDS.ADMIN) {
try {
await this.createUser(email, PASSWORD, roleId)
} catch (err) {

View File

@ -1,4 +1,5 @@
const TestConfig = require("./TestConfiguration")
const env = require("../../../../environment")
exports.delay = ms => new Promise(resolve => setTimeout(resolve, ms))
@ -30,3 +31,21 @@ exports.getConfig = () => {
}
return config
}
exports.switchToCloudForFunction = async func => {
// self hosted stops any attempts to Dynamo
env.CLOUD = true
env.SELF_HOSTED = true
let error
try {
await func()
} catch (err) {
error = err
}
env.CLOUD = false
env.SELF_HOSTED = false
// don't throw error until after reset
if (error) {
throw error
}
}