Add test to ensure query schema is correctly cleared for prod app IDs
This commit is contained in:
parent
3abaded20a
commit
0b239a5bec
|
@ -1,6 +1,13 @@
|
|||
// mock out postgres for this
|
||||
// Mock out postgres for this
|
||||
jest.mock("pg")
|
||||
|
||||
// Mock isProdAppID to we can later mock the implementation and pretend we are
|
||||
// using prod app IDs
|
||||
const authDb = require("@budibase/auth/db")
|
||||
const { isProdAppID } = authDb
|
||||
const mockIsProdAppID = jest.fn(isProdAppID)
|
||||
authDb.isProdAppID = mockIsProdAppID
|
||||
|
||||
const setup = require("./utilities")
|
||||
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
||||
const { basicQuery, basicDatasource } = setup.structures
|
||||
|
@ -98,10 +105,32 @@ describe("/queries", () => {
|
|||
.set(await config.defaultHeaders())
|
||||
.expect(200)
|
||||
.expect("Content-Type", /json/)
|
||||
expect(res.body.fields).toBeUndefined()
|
||||
expect(res.body.parameters).toBeUndefined()
|
||||
expect(res.body.fields).toBeDefined()
|
||||
expect(res.body.parameters).toBeDefined()
|
||||
expect(res.body.schema).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
it("should remove sensitive info for prod apps", async () => {
|
||||
// Mock isProdAppID to pretend we are using a prod app
|
||||
mockIsProdAppID.mockClear()
|
||||
mockIsProdAppID.mockImplementation(() => true)
|
||||
|
||||
const query = await config.createQuery()
|
||||
const res = await request
|
||||
.get(`/api/queries/${query._id}`)
|
||||
.set(await config.defaultHeaders())
|
||||
.expect("Content-Type", /json/)
|
||||
.expect(200)
|
||||
expect(res.body._id).toEqual(query._id)
|
||||
expect(res.body.fields).toBeUndefined()
|
||||
expect(res.body.parameters).toBeUndefined()
|
||||
expect(res.body.schema).toBeDefined()
|
||||
|
||||
// Reset isProdAppID mock
|
||||
expect(mockIsProdAppID).toHaveBeenCalledTimes(1)
|
||||
mockIsProdAppID.mockImplementation(isProdAppID)
|
||||
})
|
||||
})
|
||||
|
||||
describe("destroy", () => {
|
||||
|
|
Loading…
Reference in New Issue