This commit is contained in:
Mateus Badan de Pieri 2023-02-02 15:14:54 +00:00
parent b2d18d13f5
commit 126b475c32
1 changed files with 43 additions and 1 deletions

View File

@ -92,6 +92,48 @@ describe("/api/env/variables", () => {
it("should run a query preview and check the mocked results", async () => { it("should run a query preview and check the mocked results", async () => {
// TODO: use the preview API // TODO: use the preview API
expect(postgres.integration).toHaveBeenCalledWith() const datasourceBase = structures.basicDatasource()
await request
.post(`/api/env/variables`)
.send(structures.basicEnvironmentVariable("test", "test"))
.set(config.defaultHeaders())
datasourceBase.datasource.config = {
password: "{{ env.test }}",
}
const response = await request
.post(`/api/datasources`)
.send(datasourceBase)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
expect(response.body.datasource._id).toBeDefined()
const query = {
datasourceId: response.body.datasource._id,
parameters: {},
fields: {},
queryVerb: "read",
name: response.body.datasource.name,
}
const res = await request
.post(`/api/queries/preview`)
.send(query)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
// these responses come from the mock
expect(res.body.schemaFields).toEqual({
a: "string",
b: "number",
})
expect(res.body.rows.length).toEqual(1)
expect(events.query.previewed).toBeCalledTimes(1)
expect(events.query.previewed).toBeCalledWith(
response.body.datasource,
query
)
//expect(postgres.integration).toHaveBeenCalledWith()
}) })
}) })