@budibase/server 1.0.27-alpha.10 → 1.0.27-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/assets/{index.39751e34.js → index.b98dd7ca.js} +1 -1
- package/builder/index.html +1 -1
- package/coverage/clover.xml +440 -424
- package/coverage/coverage-final.json +20 -20
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +57 -57
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +138 -36
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +19 -19
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +21 -21
- package/coverage/lcov-report/api/controllers/query/index.js.html +45 -45
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +5 -5
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/automations/utils.js.html +5 -5
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/client.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +18 -18
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +28 -28
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +9 -9
- package/coverage/lcov-report/middleware/builder.js.html +8 -8
- package/coverage/lcov-report/middleware/currentapp.js.html +28 -28
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +9 -9
- package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +1 -1
- package/coverage/lcov-report/threads/index.js.html +12 -12
- package/coverage/lcov-report/threads/query.js.html +75 -75
- package/coverage/lcov-report/threads/utils.js.html +29 -29
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +12 -12
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +10 -10
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +19 -19
- package/coverage/lcov.info +724 -693
- package/dist/api/controllers/datasource.js +29 -0
- package/dist/package.json +4 -4
- package/dist/tests/utilities/TestConfiguration.js +40 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/api/controllers/datasource.js +34 -0
- package/src/api/routes/tests/datasource.spec.js +45 -0
- package/src/api/routes/tests/query.spec.js +24 -43
- package/src/tests/utilities/TestConfiguration.js +47 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "1.0.27-alpha.
|
|
4
|
+
"version": "1.0.27-alpha.11",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"license": "GPL-3.0",
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@apidevtools/swagger-parser": "^10.0.3",
|
|
73
|
-
"@budibase/auth": "^1.0.27-alpha.
|
|
74
|
-
"@budibase/client": "^1.0.27-alpha.
|
|
75
|
-
"@budibase/string-templates": "^1.0.27-alpha.
|
|
73
|
+
"@budibase/auth": "^1.0.27-alpha.11",
|
|
74
|
+
"@budibase/client": "^1.0.27-alpha.11",
|
|
75
|
+
"@budibase/string-templates": "^1.0.27-alpha.11",
|
|
76
76
|
"@bull-board/api": "^3.7.0",
|
|
77
77
|
"@bull-board/koa": "^3.7.0",
|
|
78
78
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -165,5 +165,5 @@
|
|
|
165
165
|
"optionalDependencies": {
|
|
166
166
|
"oracledb": "^5.3.0"
|
|
167
167
|
},
|
|
168
|
-
"gitHead": "
|
|
168
|
+
"gitHead": "45631b235ddba52942183e312b9154fbdb4ea862"
|
|
169
169
|
}
|
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
const { BuildSchemaErrors, InvalidColumns } = require("../../constants")
|
|
11
11
|
const { integrations } = require("../../integrations")
|
|
12
12
|
const { getDatasourceAndQuery } = require("./row/utils")
|
|
13
|
+
const { invalidateDynamicVariables } = require("../../threads/utils")
|
|
13
14
|
|
|
14
15
|
exports.fetch = async function (ctx) {
|
|
15
16
|
const database = new CouchDB(ctx.appId)
|
|
@@ -57,10 +58,43 @@ exports.buildSchemaFromDb = async function (ctx) {
|
|
|
57
58
|
ctx.body = response
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Check for variables that have been updated or removed and invalidate them.
|
|
63
|
+
*/
|
|
64
|
+
const invalidateVariables = async (existingDatasource, updatedDatasource) => {
|
|
65
|
+
const existingVariables = existingDatasource.config.dynamicVariables
|
|
66
|
+
const updatedVariables = updatedDatasource.config.dynamicVariables
|
|
67
|
+
const toInvalidate = []
|
|
68
|
+
|
|
69
|
+
if (!existingVariables) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!updatedVariables) {
|
|
74
|
+
// invalidate all
|
|
75
|
+
toInvalidate.push(...existingVariables)
|
|
76
|
+
} else {
|
|
77
|
+
// invaldate changed / removed
|
|
78
|
+
existingVariables.forEach(existing => {
|
|
79
|
+
const unchanged = updatedVariables.find(
|
|
80
|
+
updated =>
|
|
81
|
+
existing.name === updated.name &&
|
|
82
|
+
existing.queryId === updated.queryId &&
|
|
83
|
+
existing.value === updated.value
|
|
84
|
+
)
|
|
85
|
+
if (!unchanged) {
|
|
86
|
+
toInvalidate.push(existing)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
await invalidateDynamicVariables(toInvalidate)
|
|
91
|
+
}
|
|
92
|
+
|
|
60
93
|
exports.update = async function (ctx) {
|
|
61
94
|
const db = new CouchDB(ctx.appId)
|
|
62
95
|
const datasourceId = ctx.params.datasourceId
|
|
63
96
|
let datasource = await db.get(datasourceId)
|
|
97
|
+
await invalidateVariables(datasource, ctx.request.body)
|
|
64
98
|
datasource = { ...datasource, ...ctx.request.body }
|
|
65
99
|
|
|
66
100
|
const response = await db.put(datasource)
|
|
@@ -4,6 +4,7 @@ let setup = require("./utilities")
|
|
|
4
4
|
let { basicDatasource } = setup.structures
|
|
5
5
|
let { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
|
6
6
|
const pg = require("pg")
|
|
7
|
+
const { checkCacheForDynamicVariable } = require("../../../threads/utils")
|
|
7
8
|
|
|
8
9
|
describe("/datasources", () => {
|
|
9
10
|
let request = setup.getRequest()
|
|
@@ -31,6 +32,50 @@ describe("/datasources", () => {
|
|
|
31
32
|
})
|
|
32
33
|
})
|
|
33
34
|
|
|
35
|
+
describe("update", () => {
|
|
36
|
+
it("should update an existing datasource", async () => {
|
|
37
|
+
datasource.name = "Updated Test"
|
|
38
|
+
const res = await request
|
|
39
|
+
.put(`/api/datasources/${datasource._id}`)
|
|
40
|
+
.send(datasource)
|
|
41
|
+
.set(config.defaultHeaders())
|
|
42
|
+
.expect('Content-Type', /json/)
|
|
43
|
+
.expect(200)
|
|
44
|
+
|
|
45
|
+
expect(res.body.datasource.name).toEqual("Updated Test")
|
|
46
|
+
expect(res.body.errors).toBeUndefined()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
describe("dynamic variables", () => {
|
|
50
|
+
async function preview(datasource, fields) {
|
|
51
|
+
return config.previewQuery(request, config, datasource, fields)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
it("should invalidate changed or removed variables", async () => {
|
|
55
|
+
const { datasource, query } = await config.dynamicVariableDatasource()
|
|
56
|
+
// preview once to cache variables
|
|
57
|
+
await preview(datasource, { path: "www.test.com", queryString: "test={{ variable3 }}" })
|
|
58
|
+
// check variables in cache
|
|
59
|
+
let contents = await checkCacheForDynamicVariable(query._id, "variable3")
|
|
60
|
+
expect(contents.rows.length).toEqual(1)
|
|
61
|
+
|
|
62
|
+
// update the datasource to remove the variables
|
|
63
|
+
datasource.config.dynamicVariables = []
|
|
64
|
+
const res = await request
|
|
65
|
+
.put(`/api/datasources/${datasource._id}`)
|
|
66
|
+
.send(datasource)
|
|
67
|
+
.set(config.defaultHeaders())
|
|
68
|
+
.expect('Content-Type', /json/)
|
|
69
|
+
.expect(200)
|
|
70
|
+
expect(res.body.errors).toBeUndefined()
|
|
71
|
+
|
|
72
|
+
// check variables no longer in cache
|
|
73
|
+
contents = await checkCacheForDynamicVariable(query._id, "variable3")
|
|
74
|
+
expect(contents).toBe(null)
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
34
79
|
describe("fetch", () => {
|
|
35
80
|
it("returns all the datasources from the server", async () => {
|
|
36
81
|
const res = await request
|
|
@@ -229,52 +229,14 @@ describe("/queries", () => {
|
|
|
229
229
|
})
|
|
230
230
|
})
|
|
231
231
|
|
|
232
|
-
describe("
|
|
233
|
-
async function restDatasource(cfg) {
|
|
234
|
-
return await config.createDatasource({
|
|
235
|
-
datasource: {
|
|
236
|
-
...basicDatasource().datasource,
|
|
237
|
-
source: "REST",
|
|
238
|
-
config: cfg || {},
|
|
239
|
-
},
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
async function dynamicVariableDatasource() {
|
|
244
|
-
const datasource = await restDatasource()
|
|
245
|
-
const basedOnQuery = await config.createQuery({
|
|
246
|
-
...basicQuery(datasource._id),
|
|
247
|
-
fields: {
|
|
248
|
-
path: "www.google.com",
|
|
249
|
-
},
|
|
250
|
-
})
|
|
251
|
-
await config.updateDatasource({
|
|
252
|
-
...datasource,
|
|
253
|
-
config: {
|
|
254
|
-
dynamicVariables: [
|
|
255
|
-
{ queryId: basedOnQuery._id, name: "variable3", value: "{{ data.0.[value] }}" }
|
|
256
|
-
]
|
|
257
|
-
}
|
|
258
|
-
})
|
|
259
|
-
return { datasource, query: basedOnQuery }
|
|
260
|
-
}
|
|
232
|
+
describe("variables", () => {
|
|
261
233
|
|
|
262
234
|
async function preview(datasource, fields) {
|
|
263
|
-
return
|
|
264
|
-
.post(`/api/queries/preview`)
|
|
265
|
-
.send({
|
|
266
|
-
datasourceId: datasource._id,
|
|
267
|
-
parameters: {},
|
|
268
|
-
fields,
|
|
269
|
-
queryVerb: "read",
|
|
270
|
-
})
|
|
271
|
-
.set(config.defaultHeaders())
|
|
272
|
-
.expect("Content-Type", /json/)
|
|
273
|
-
.expect(200)
|
|
235
|
+
return config.previewQuery(request, config, datasource, fields)
|
|
274
236
|
}
|
|
275
237
|
|
|
276
238
|
it("should work with static variables", async () => {
|
|
277
|
-
const datasource = await restDatasource({
|
|
239
|
+
const datasource = await config.restDatasource({
|
|
278
240
|
staticVariables: {
|
|
279
241
|
variable: "google",
|
|
280
242
|
variable2: "1",
|
|
@@ -290,7 +252,7 @@ describe("/queries", () => {
|
|
|
290
252
|
})
|
|
291
253
|
|
|
292
254
|
it("should work with dynamic variables", async () => {
|
|
293
|
-
const { datasource } = await dynamicVariableDatasource()
|
|
255
|
+
const { datasource } = await config.dynamicVariableDatasource()
|
|
294
256
|
const res = await preview(datasource, {
|
|
295
257
|
path: "www.google.com",
|
|
296
258
|
queryString: "test={{ variable3 }}",
|
|
@@ -300,7 +262,7 @@ describe("/queries", () => {
|
|
|
300
262
|
})
|
|
301
263
|
|
|
302
264
|
it("check that it automatically retries on fail with cached dynamics", async () => {
|
|
303
|
-
const { datasource, query: base } = await dynamicVariableDatasource()
|
|
265
|
+
const { datasource, query: base } = await config.dynamicVariableDatasource()
|
|
304
266
|
// preview once to cache
|
|
305
267
|
await preview(datasource, { path: "www.google.com", queryString: "test={{ variable3 }}" })
|
|
306
268
|
// check its in cache
|
|
@@ -313,5 +275,24 @@ describe("/queries", () => {
|
|
|
313
275
|
expect(res.body.schemaFields).toEqual(["fails", "url", "opts"])
|
|
314
276
|
expect(res.body.rows[0].fails).toEqual(1)
|
|
315
277
|
})
|
|
278
|
+
|
|
279
|
+
it("deletes variables when linked query is deleted", async () => {
|
|
280
|
+
const { datasource, query: base } = await config.dynamicVariableDatasource()
|
|
281
|
+
// preview once to cache
|
|
282
|
+
await preview(datasource, { path: "www.google.com", queryString: "test={{ variable3 }}" })
|
|
283
|
+
// check its in cache
|
|
284
|
+
let contents = await checkCacheForDynamicVariable(base._id, "variable3")
|
|
285
|
+
expect(contents.rows.length).toEqual(1)
|
|
286
|
+
|
|
287
|
+
// delete the query
|
|
288
|
+
await request
|
|
289
|
+
.delete(`/api/queries/${base._id}/${base._rev}`)
|
|
290
|
+
.set(config.defaultHeaders())
|
|
291
|
+
.expect(200)
|
|
292
|
+
|
|
293
|
+
// check variables no longer in cache
|
|
294
|
+
contents = await checkCacheForDynamicVariable(base._id, "variable3")
|
|
295
|
+
expect(contents).toBe(null)
|
|
296
|
+
})
|
|
316
297
|
})
|
|
317
298
|
})
|
|
@@ -326,6 +326,53 @@ class TestConfiguration {
|
|
|
326
326
|
return this.datasource
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
async restDatasource(cfg) {
|
|
330
|
+
return this.createDatasource({
|
|
331
|
+
datasource: {
|
|
332
|
+
...basicDatasource().datasource,
|
|
333
|
+
source: "REST",
|
|
334
|
+
config: cfg || {},
|
|
335
|
+
},
|
|
336
|
+
})
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async dynamicVariableDatasource() {
|
|
340
|
+
let datasource = await this.restDatasource()
|
|
341
|
+
const basedOnQuery = await this.createQuery({
|
|
342
|
+
...basicQuery(datasource._id),
|
|
343
|
+
fields: {
|
|
344
|
+
path: "www.google.com",
|
|
345
|
+
},
|
|
346
|
+
})
|
|
347
|
+
datasource = await this.updateDatasource({
|
|
348
|
+
...datasource,
|
|
349
|
+
config: {
|
|
350
|
+
dynamicVariables: [
|
|
351
|
+
{
|
|
352
|
+
queryId: basedOnQuery._id,
|
|
353
|
+
name: "variable3",
|
|
354
|
+
value: "{{ data.0.[value] }}",
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
})
|
|
359
|
+
return { datasource, query: basedOnQuery }
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async previewQuery(request, config, datasource, fields) {
|
|
363
|
+
return request
|
|
364
|
+
.post(`/api/queries/preview`)
|
|
365
|
+
.send({
|
|
366
|
+
datasourceId: datasource._id,
|
|
367
|
+
parameters: {},
|
|
368
|
+
fields,
|
|
369
|
+
queryVerb: "read",
|
|
370
|
+
})
|
|
371
|
+
.set(config.defaultHeaders())
|
|
372
|
+
.expect("Content-Type", /json/)
|
|
373
|
+
.expect(200)
|
|
374
|
+
}
|
|
375
|
+
|
|
329
376
|
async createQuery(config = null) {
|
|
330
377
|
if (!this.datasource && !config) {
|
|
331
378
|
throw "No data source created for query."
|