|
|
|
@ -1,5 +1,6 @@ |
|
|
|
// Mock out postgres for this
|
|
|
|
jest.mock("pg") |
|
|
|
jest.mock("node-fetch") |
|
|
|
|
|
|
|
// Mock isProdAppID to we can later mock the implementation and pretend we are
|
|
|
|
// using prod app IDs
|
|
|
|
@ -226,4 +227,76 @@ describe("/queries", () => { |
|
|
|
.expect(400) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
describe("test variables", () => { |
|
|
|
async function restDatasource(cfg) { |
|
|
|
return await config.createDatasource({ |
|
|
|
datasource: { |
|
|
|
...basicDatasource().datasource, |
|
|
|
source: "REST", |
|
|
|
config: cfg || {}, |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
it("should work with static variables", async () => { |
|
|
|
const datasource = await restDatasource({ |
|
|
|
staticVariables: { |
|
|
|
variable: "google", |
|
|
|
variable2: "1", |
|
|
|
}, |
|
|
|
}) |
|
|
|
const res = await request |
|
|
|
.post(`/api/queries/preview`) |
|
|
|
.send({ |
|
|
|
datasourceId: datasource._id, |
|
|
|
parameters: {}, |
|
|
|
fields: { |
|
|
|
path: "www.{{ variable }}.com", |
|
|
|
queryString: "test={{ variable2 }}", |
|
|
|
}, |
|
|
|
queryVerb: "read", |
|
|
|
}) |
|
|
|
.set(config.defaultHeaders()) |
|
|
|
.expect("Content-Type", /json/) |
|
|
|
.expect(200) |
|
|
|
// these responses come from the mock
|
|
|
|
expect(res.body.schemaFields).toEqual(["url", "opts", "value"]) |
|
|
|
expect(res.body.rows[0].url).toEqual("http://www.google.com?test=1") |
|
|
|
}) |
|
|
|
|
|
|
|
it("should work with dynamic variables", async () => { |
|
|
|
const datasource = await restDatasource() |
|
|
|
const basedOnQuery = await config.createQuery({ |
|
|
|
...basicQuery(datasource._id), |
|
|
|
fields: { |
|
|
|
path: "www.google.com", |
|
|
|
}, |
|
|
|
}) |
|
|
|
await config.updateDatasource({ |
|
|
|
...datasource, |
|
|
|
config: { |
|
|
|
dynamicVariables: [ |
|
|
|
{ queryId: basedOnQuery._id, name: "variable3", value: "{{ data.0.[value] }}" } |
|
|
|
] |
|
|
|
} |
|
|
|
}) |
|
|
|
const res = await request |
|
|
|
.post(`/api/queries/preview`) |
|
|
|
.send({ |
|
|
|
datasourceId: datasource._id, |
|
|
|
parameters: {}, |
|
|
|
fields: { |
|
|
|
path: "www.google.com", |
|
|
|
queryString: "test={{ variable3 }}", |
|
|
|
}, |
|
|
|
queryVerb: "read", |
|
|
|
}) |
|
|
|
.set(config.defaultHeaders()) |
|
|
|
.expect("Content-Type", /json/) |
|
|
|
.expect(200) |
|
|
|
expect(res.body.schemaFields).toEqual(["url", "opts", "value"]) |
|
|
|
expect(res.body.rows[0].url).toContain("doctype html") |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|