From 8709fb2f0b0e6d38d2826888a15d9391d926dd94 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Tue, 5 Oct 2021 12:20:09 +0200 Subject: [PATCH 1/9] add a slash before the path and a questionmark before the querystring --- .../src/components/integration/index.svelte | 6 +++--- packages/server/src/integrations/rest.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/components/integration/index.svelte b/packages/builder/src/components/integration/index.svelte index 5c821d3a53..a0e1b8c1c4 100644 --- a/packages/builder/src/components/integration/index.svelte +++ b/packages/builder/src/components/integration/index.svelte @@ -17,9 +17,9 @@ $: urlDisplay = schema.urlDisplay && - `${datasource.config.url}${query.fields.path ?? ""}${ - query.fields.queryString ?? "" - }` + `${datasource.config.url}${ + query.fields.path ? "/" + query.fields.path : "" + }${query.fields.queryString ? "?" + query.fields.queryString : ""}` function updateQuery({ detail }) { query.fields[schema.type] = detail.value diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index d6cf71e324..9c6ece52d6 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -152,13 +152,17 @@ module RestModule { } } + getUrl(path: string, queryString: string): string { + return `${this.config.url}/${path}?${queryString}` + } + async create({ path = "", queryString = "", headers = {}, json = {} }) { this.headers = { ...this.config.defaultHeaders, ...headers, } - const response = await fetch(this.config.url + path + queryString, { + const response = await fetch(this.getUrl(path, queryString), { method: "POST", headers: this.headers, body: JSON.stringify(json), @@ -173,7 +177,7 @@ module RestModule { ...headers, } - const response = await fetch(this.config.url + path + queryString, { + const response = await fetch(this.getUrl(path, queryString), { headers: this.headers, }) @@ -186,7 +190,7 @@ module RestModule { ...headers, } - const response = await fetch(this.config.url + path + queryString, { + const response = await fetch(this.getUrl(path, queryString), { method: "POST", headers: this.headers, body: JSON.stringify(json), @@ -201,7 +205,7 @@ module RestModule { ...headers, } - const response = await fetch(this.config.url + path + queryString, { + const response = await fetch(this.getUrl(path, queryString), { method: "PATCH", headers: this.headers, body: JSON.stringify(json), @@ -216,7 +220,7 @@ module RestModule { ...headers, } - const response = await fetch(this.config.url + path + queryString, { + const response = await fetch(this.getUrl(path, queryString), { method: "DELETE", headers: this.headers, }) From dbf747f749da975dc56ccee6960cda9e67d04c43 Mon Sep 17 00:00:00 2001 From: Maurits Lourens Date: Tue, 5 Oct 2021 13:38:03 +0200 Subject: [PATCH 2/9] fix tests --- .../src/integrations/tests/rest.spec.js | 70 ++++++++++--------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/packages/server/src/integrations/tests/rest.spec.js b/packages/server/src/integrations/tests/rest.spec.js index a0b12f6c17..cb69d3c38d 100644 --- a/packages/server/src/integrations/tests/rest.spec.js +++ b/packages/server/src/integrations/tests/rest.spec.js @@ -1,98 +1,100 @@ -jest.mock("node-fetch", () => jest.fn(() => ({ json: jest.fn(), text: jest.fn() }))) +jest.mock("node-fetch", () => + jest.fn(() => ({ json: jest.fn(), text: jest.fn() })) +) const fetch = require("node-fetch") const RestIntegration = require("../rest") class TestConfiguration { constructor(config = {}) { - this.integration = new RestIntegration.integration(config) + this.integration = new RestIntegration.integration(config) } } describe("REST Integration", () => { const BASE_URL = "https://myapi.com" - let config + let config beforeEach(() => { config = new TestConfiguration({ - url: BASE_URL + url: BASE_URL, }) }) it("calls the create method with the correct params", async () => { const query = { - path: "/api", - queryString: "?test=1", + path: "api", + queryString: "test=1", headers: { - Accept: "application/json" + Accept: "application/json", }, json: { - name: "test" - } + name: "test", + }, } const response = await config.integration.create(query) expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { method: "POST", - body: "{\"name\":\"test\"}", + body: '{"name":"test"}', headers: { - Accept: "application/json" - } + Accept: "application/json", + }, }) }) it("calls the read method with the correct params", async () => { const query = { - path: "/api", - queryString: "?test=1", + path: "api", + queryString: "test=1", headers: { - Accept: "text/html" - } + Accept: "text/html", + }, } const response = await config.integration.read(query) expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { headers: { - Accept: "text/html" - } + Accept: "text/html", + }, }) }) it("calls the update method with the correct params", async () => { const query = { - path: "/api", - queryString: "?test=1", + path: "api", + queryString: "test=1", headers: { - Accept: "application/json" + Accept: "application/json", }, json: { - name: "test" - } + name: "test", + }, } const response = await config.integration.update(query) expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { method: "POST", - body: "{\"name\":\"test\"}", + body: '{"name":"test"}', headers: { - Accept: "application/json" - } + Accept: "application/json", + }, }) }) it("calls the delete method with the correct params", async () => { const query = { - path: "/api", - queryString: "?test=1", + path: "api", + queryString: "test=1", headers: { - Accept: "application/json" + Accept: "application/json", }, json: { - name: "test" - } + name: "test", + }, } const response = await config.integration.delete(query) expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { method: "DELETE", headers: { - Accept: "application/json" - } + Accept: "application/json", + }, }) }) -}) \ No newline at end of file +}) From 5702eb464b845d0bae71988ae23bf3a4f2591cac Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 11 Oct 2021 11:10:26 +0100 Subject: [PATCH 3/9] fix issue where automation block was not being added in the correct order --- .../AutomationBuilder/FlowChart/ActionModal.svelte | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte index acb945a96a..b076a8da86 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte @@ -4,10 +4,11 @@ import { externalActions } from "./ExternalActions" export let blockIdx + export let blockComplete + let selectedAction let actionVal let actions = Object.entries($automationStore.blockDefinitions.ACTION) - export let blockComplete const external = actions.reduce((acc, elm) => { const [k, v] = elm @@ -36,10 +37,9 @@ actionVal.stepId, actionVal ) - automationStore.actions.addBlockToAutomation(newBlock) + automationStore.actions.addBlockToAutomation(newBlock, blockIdx + 1) await automationStore.actions.save( - $automationStore.selectedAutomation?.automation, - blockIdx + $automationStore.selectedAutomation?.automation ) } From 8744e50ded708ea0aeb2385f4f7edacc4cd01e76 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 11 Oct 2021 11:33:54 +0100 Subject: [PATCH 4/9] fix lint --- packages/builder/cypress/support/commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index c8e01435aa..f179a24729 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -5,7 +5,7 @@ // *********************************************** // -Cypress.on('uncaught:exception', (err, runnable) => { +Cypress.on("uncaught:exception", () => { return false }) From eba9bd79f66a0b144620dc8513f62f3b138dfbb0 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 11 Oct 2021 11:35:07 +0100 Subject: [PATCH 5/9] enable 'add action' button when inputs completed --- .../automation/AutomationBuilder/FlowChart/FlowItem.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte index 0c0b79c3de..e69f5ec204 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/FlowItem.svelte @@ -151,7 +151,7 @@ > {/if}