From 611ca62c439fdae9c0bba0339faec3f2d09087c6 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Thu, 10 Feb 2022 09:25:13 +0100 Subject: [PATCH 1/3] Fix validation for query preview endpoint --- packages/server/src/api/controllers/query/validation.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/server/src/api/controllers/query/validation.js b/packages/server/src/api/controllers/query/validation.js index 4958433849..4486ff2307 100644 --- a/packages/server/src/api/controllers/query/validation.js +++ b/packages/server/src/api/controllers/query/validation.js @@ -33,6 +33,9 @@ exports.generateQueryPreviewValidation = () => { return joiValidator.body(Joi.object({ fields: Joi.object().required(), queryVerb: Joi.string().allow().required(), + name: Joi.string().required(), + flags: Joi.object().optional(), + schema: Joi.object().optional(), extra: Joi.object().optional(), datasourceId: Joi.string().required(), transformer: Joi.string().optional(), From 59197bcaec378eaf52441c759253a887d1470079 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Thu, 10 Feb 2022 10:22:57 +0100 Subject: [PATCH 2/3] add properties which are present when previewing an existing query --- packages/server/src/api/controllers/query/validation.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/server/src/api/controllers/query/validation.js b/packages/server/src/api/controllers/query/validation.js index 4486ff2307..515c7b591e 100644 --- a/packages/server/src/api/controllers/query/validation.js +++ b/packages/server/src/api/controllers/query/validation.js @@ -31,6 +31,9 @@ exports.generateQueryValidation = () => { exports.generateQueryPreviewValidation = () => { // prettier-ignore return joiValidator.body(Joi.object({ + _id: Joi.string().optional(), + _rev: Joi.string().optional(), + readable: Joi.boolean().optional(), fields: Joi.object().required(), queryVerb: Joi.string().allow().required(), name: Joi.string().required(), From a3626986a191dc704a7ec560d547cce9a396f554 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Fri, 11 Feb 2022 17:28:19 +0100 Subject: [PATCH 3/3] fix tests --- .../server/src/api/routes/tests/query.spec.js | 17 +++++++++++++---- .../src/tests/utilities/TestConfiguration.js | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/routes/tests/query.spec.js b/packages/server/src/api/routes/tests/query.spec.js index dac576836e..48e3181d10 100644 --- a/packages/server/src/api/routes/tests/query.spec.js +++ b/packages/server/src/api/routes/tests/query.spec.js @@ -169,6 +169,7 @@ describe("/queries", () => { parameters: {}, fields: {}, queryVerb: "read", + name: datasource.name, }) .set(config.defaultHeaders()) .expect("Content-Type", /json/) @@ -261,9 +262,13 @@ describe("/queries", () => { }) it("check that it automatically retries on fail with cached dynamics", async () => { - const { datasource, query: base } = await config.dynamicVariableDatasource() + const { datasource, query: base } = + await config.dynamicVariableDatasource() // preview once to cache - await preview(datasource, { path: "www.google.com", queryString: "test={{ variable3 }}" }) + await preview(datasource, { + path: "www.google.com", + queryString: "test={{ variable3 }}", + }) // check its in cache const contents = await checkCacheForDynamicVariable(base._id, "variable3") expect(contents.rows.length).toEqual(1) @@ -276,9 +281,13 @@ describe("/queries", () => { }) it("deletes variables when linked query is deleted", async () => { - const { datasource, query: base } = await config.dynamicVariableDatasource() + const { datasource, query: base } = + await config.dynamicVariableDatasource() // preview once to cache - await preview(datasource, { path: "www.google.com", queryString: "test={{ variable3 }}" }) + await preview(datasource, { + path: "www.google.com", + queryString: "test={{ variable3 }}", + }) // check its in cache let contents = await checkCacheForDynamicVariable(base._id, "variable3") expect(contents.rows.length).toEqual(1) diff --git a/packages/server/src/tests/utilities/TestConfiguration.js b/packages/server/src/tests/utilities/TestConfiguration.js index 6c2b7d4f98..1b3a91ceab 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.js +++ b/packages/server/src/tests/utilities/TestConfiguration.js @@ -393,6 +393,7 @@ class TestConfiguration { parameters: {}, fields, queryVerb: "read", + name: datasource.name, }) .set(config.defaultHeaders()) .expect("Content-Type", /json/)