From 2bdb834f3e1b66d5773229e4e965809acfca3d8d Mon Sep 17 00:00:00 2001 From: Paulo Bernardo Date: Fri, 1 Nov 2024 14:17:19 -0300 Subject: [PATCH] tests: add webhook router tests --- .../webhook/WebhookRouterForm.test.tsx | 95 +- .../WebhookRouterForm.test.tsx.snap | 1471 ++++++++++++++++- .../routers/webhook/header/HeaderElement.tsx | 1 + .../__snapshots__/HeaderElement.test.ts.snap | 1 + src/testUtils/assetCreators.ts | 6 +- 5 files changed, 1488 insertions(+), 86 deletions(-) diff --git a/src/components/flow/routers/webhook/WebhookRouterForm.test.tsx b/src/components/flow/routers/webhook/WebhookRouterForm.test.tsx index 34ac9d2b2..45db1f9e8 100644 --- a/src/components/flow/routers/webhook/WebhookRouterForm.test.tsx +++ b/src/components/flow/routers/webhook/WebhookRouterForm.test.tsx @@ -71,11 +71,79 @@ describe(WebhookRouterForm.name, () => { // add http header fireEvent.click(getByText('HTTP Headers')); - const headerName = getAllByTestId('Ex: Accept')[0]; - const headerValue = getAllByTestId('Ex: application/json')[0]; + let headerName = getAllByTestId('Ex: Accept')[0]; + let headerValue = getAllByTestId('Ex: application/json')[0]; - fireEvent.change(headerName, 'Content-type'); - fireEvent.change(headerValue, 'application/json'); + await act(async () => { + fireUnnnicInputChangeText(headerName, 'Content-type'); + fireUnnnicInputChangeText(headerValue, 'application/json'); + }); + + fireEvent.click(okButton); + expect(webhookForm.updateRouter).toBeCalled(); + expect(webhookForm.updateRouter).toMatchSnapshot(); + + fireEvent.click(getByText('General')); + + // change to the same method and save + await act(async () => { + userEvent.click(getByText('POST')); + }); + + fireEvent.click(okButton); + expect(webhookForm.updateRouter).toBeCalled(); + expect(webhookForm.updateRouter).toMatchSnapshot(); + + // test the GET method + await act(async () => { + userEvent.click(getByText('GET')); + }); + + // set a get body + fireEvent.click(getByText('GET Body')); + const getBody = getByTestId('GET Body'); + + await act(async () => { + fireUnnnicTextAreaChangeText(getBody, 'Updated get body'); + }); + + fireEvent.click(okButton); + expect(webhookForm.updateRouter).toBeCalled(); + expect(webhookForm.updateRouter).toMatchSnapshot(); + + // Manually add content-type header and change back to POST + fireEvent.click(getByText('HTTP Headers')); + headerName = getAllByTestId('Ex: Accept')[0]; + headerValue = getAllByTestId('Ex: application/json')[0]; + + fireUnnnicInputChangeText(headerName, 'Content-type'); + fireUnnnicInputChangeText(headerValue, 'application/json'); + + fireEvent.click(getByText('General')); + + // change to the same method and save + await act(async () => { + userEvent.click(getByText('POST')); + }); + + // remonve an http header + await act(async () => { + fireEvent.click(getByText('HTTP Headers')); + }); + + const deleteButton = getAllByTestId('remove-icon')[0]; + fireEvent.click(deleteButton); + + fireEvent.click(okButton); + expect(webhookForm.updateRouter).toBeCalled(); + expect(webhookForm.updateRouter).toMatchSnapshot(); + + fireEvent.click(getByText('General')); + + // go back to GET and save + await act(async () => { + userEvent.click(getByText('GET')); + }); fireEvent.click(okButton); expect(webhookForm.updateRouter).toBeCalled(); @@ -131,4 +199,23 @@ describe(WebhookRouterForm.name, () => { expect(webhookForm.updateRouter).toBeCalled(); }); }); + + it("should render a split_by_webhook's original action", () => { + const webhookForm = getRouterFormProps({ + node: { + ...createWebhookRouterNode({ + 'Content-Type': 'application/json', + }), + }, + ui: { type: Types.split_by_webhook }, + } as RenderNode); + + const { setup } = composeComponentTestUtils( + WebhookRouterForm, + webhookForm, + ); + const { wrapper } = setup(true); + + expect(shallowToJson(wrapper)).toMatchSnapshot(); + }); }); diff --git a/src/components/flow/routers/webhook/__snapshots__/WebhookRouterForm.test.tsx.snap b/src/components/flow/routers/webhook/__snapshots__/WebhookRouterForm.test.tsx.snap index 0a7ecbdb8..cf6c1d633 100644 --- a/src/components/flow/routers/webhook/__snapshots__/WebhookRouterForm.test.tsx.snap +++ b/src/components/flow/routers/webhook/__snapshots__/WebhookRouterForm.test.tsx.snap @@ -311,6 +311,319 @@ exports[`WebhookRouterForm > should render 1`] = ` `; +exports[`WebhookRouterForm > should render a split_by_webhook's original action 1`] = ` + +
+ + Add any additional headers below that you would like to send along with your request. + +
+
+
+ +
+
+ +
+
+ , + "checked": true, + "hasErrors": false, + "name": "HTTP Headers", + }, + { + "body":
+
+ + Modify the body of the [[method]] request that will be sent to your webhook + +
+
+ +
+
, + "checked": true, + "name": "GET Body", + }, + ] + } + title="Call webhook" +> + +
+
+ +
+
+ +
+
+
+
+ + If your server responds with JSON, each property will be added to the Flow. + +
+
+      { "product": "Solar Charging Kit", "stock level": 32 }
+    
+
+ + This response would add + + @webhook.product + + and + + + @webhook["stock level"] + + for use in the flow. + +
+
+ +
+`; + exports[`WebhookRouterForm > updates > should repopulate post body 1`] = ` { "body": { @@ -318,40 +631,1014 @@ exports[`WebhookRouterForm > updates > should repopulate post body 1`] = ` }, "headers": [ { - "value": { - "name": "Accept", - "uuid": "0c8c9239-9b59-473a-a229-d8a9693be270", - "value": "application/json", + "value": { + "name": "Accept", + "uuid": "c5722340-f7e1-4d99-ac5e-3a6e59845111", + "value": "application/json", + }, + }, + { + "value": { + "name": "", + "uuid": "f05fa107-03db-4315-a211-53da63603e6f", + "value": "", + }, + }, + ], + "method": { + "value": { + "value": "GET", + }, + }, + "resultName": { + "value": "Result", + }, + "url": { + "validationFailures": [], + "value": "http://domain.com/", + }, + "valid": true, +} +`; + +exports[`WebhookRouterForm > updates > should repopulate post body 2`] = ` +{ + "body": { + "value": "@(json(object( + "contact", object( + "uuid", contact.uuid, + "name", contact.name, + "urn", contact.urn + ), + "flow", object( + "uuid", run.flow.uuid, + "name", run.flow.name + ), + "results", foreach_value(results, extract_object, "value", "category") +)))", + }, + "headers": [ + { + "value": { + "name": "Accept", + "uuid": "c5722340-f7e1-4d99-ac5e-3a6e59845111", + "value": "application/json", + }, + }, + { + "validationFailures": undefined, + "value": { + "name": "Content-Type", + "uuid": "f05fa107-03db-4315-a211-53da63603e6f", + "value": "application/json", + }, + }, + { + "validationFailures": undefined, + "value": { + "name": "", + "uuid": "e81b3f1a-0863-4418-8a72-9c9f8aa72b7c", + "value": "", + }, + }, + ], + "method": { + "value": "POST", + }, + "resultName": { + "value": "Result", + }, + "url": { + "validationFailures": [], + "value": "http://domain.com/", + }, + "valid": true, +} +`; + +exports[`WebhookRouterForm > updates > should save changes 1`] = ` +[MockFunction spy] { + "calls": [ + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + ], + "results": [ + { + "type": "return", + "value": undefined, + }, + ], +} +`; + +exports[`WebhookRouterForm > updates > should save changes 2`] = ` +[MockFunction spy] { + "calls": [ + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + ], + "results": [ + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, + ], +} +`; + +exports[`WebhookRouterForm > updates > should save changes 3`] = ` +[MockFunction spy] { + "calls": [ + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated get body", + "headers": { + "Content-Type": "application/json", + }, + "method": "GET", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + ], + "results": [ + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, + ], +} +`; + +exports[`WebhookRouterForm > updates > should save changes 4`] = ` +[MockFunction spy] { + "calls": [ + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated get body", + "headers": { + "Content-Type": "application/json", + }, + "method": "GET", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "@(json(object( + "contact", object( + "uuid", contact.uuid, + "name", contact.name, + "urn", contact.urn + ), + "flow", object( + "uuid", run.flow.uuid, + "name", run.flow.name + ), + "results", foreach_value(results, extract_object, "value", "category") +)))", + "headers": {}, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + ], + "results": [ + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, + ], +} +`; + +exports[`WebhookRouterForm > updates > should save changes 5`] = ` +[MockFunction spy] { + "calls": [ + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, + }, + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated post body", + "headers": { + "Content-Type": "application/json", + "Content-type": "application/json", + }, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, }, - }, - { - "value": { - "name": "", - "uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5", - "value": "", + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "Updated get body", + "headers": { + "Content-Type": "application/json", + }, + "method": "GET", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, }, - }, - ], - "method": { - "value": { - "value": "GET", - }, - }, - "resultName": { - "value": "Result", - }, - "url": { - "validationFailures": [], - "value": "http://domain.com/", - }, - "valid": true, -} -`; - -exports[`WebhookRouterForm > updates > should repopulate post body 2`] = ` -{ - "body": { - "value": "@(json(object( + ], + [ + { + "inboundConnections": {}, + "node": { + "actions": [ + { + "body": "@(json(object( "contact", object( "uuid", contact.uuid, "name", contact.name, @@ -363,61 +1650,69 @@ exports[`WebhookRouterForm > updates > should repopulate post body 2`] = ` ), "results", foreach_value(results, extract_object, "value", "category") )))", - }, - "headers": [ - { - "value": { - "name": "Accept", - "uuid": "0c8c9239-9b59-473a-a229-d8a9693be270", - "value": "application/json", - }, - }, - { - "validationFailures": undefined, - "value": { - "name": "Content-Type", - "uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5", - "value": "application/json", - }, - }, - { - "validationFailures": undefined, - "value": { - "name": "", - "uuid": "00dd2423-0a34-4ee2-b97d-839fb2d593ef", - "value": "", + "headers": {}, + "method": "POST", + "result_name": "My Webhook Result", + "type": "call_webhook", + "url": "http://app.rapidpro.io", + "uuid": "b1f332f3-bdd3-4891-aec5-1843a712dbf1", + }, + ], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "Success", + ], + "category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + "type": "has_only_text", + "uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb", + }, + ], + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Success", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Failure", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + "operand": "@results.my_webhook_result.category", + "type": "switch", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "config": {}, + "position": null, + "type": "split_by_webhook", + }, }, - }, - ], - "method": { - "value": "POST", - }, - "resultName": { - "value": "Result", - }, - "url": { - "validationFailures": [], - "value": "http://domain.com/", - }, - "valid": true, -} -`; - -exports[`WebhookRouterForm > updates > should save changes 1`] = ` -[MockFunction spy] { - "calls": [ + ], [ { "inboundConnections": {}, "node": { "actions": [ { - "body": "Updated post body", - "headers": { - "Accept": "application/json", - "Content-Type": "application/json", - }, - "method": "POST", + "body": "", + "headers": {}, + "method": "GET", "result_name": "My Webhook Result", "type": "call_webhook", "url": "http://app.rapidpro.io", @@ -476,6 +1771,22 @@ exports[`WebhookRouterForm > updates > should save changes 1`] = ` "type": "return", "value": undefined, }, + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, + { + "type": "return", + "value": undefined, + }, ], } `; diff --git a/src/components/flow/routers/webhook/header/HeaderElement.tsx b/src/components/flow/routers/webhook/header/HeaderElement.tsx index 4219ab4a7..ac84b7e6c 100644 --- a/src/components/flow/routers/webhook/header/HeaderElement.tsx +++ b/src/components/flow/routers/webhook/header/HeaderElement.tsx @@ -128,6 +128,7 @@ export default class HeaderElement extends React.Component< clickable onClick={this.handleRemove} data-spec={removeIcoSpecId} + data-testid={removeIcoSpecId} /> ) : null} diff --git a/src/components/flow/routers/webhook/header/__snapshots__/HeaderElement.test.ts.snap b/src/components/flow/routers/webhook/header/__snapshots__/HeaderElement.test.ts.snap index c1c3e0ff3..9eaba2b3a 100644 --- a/src/components/flow/routers/webhook/header/__snapshots__/HeaderElement.test.ts.snap +++ b/src/components/flow/routers/webhook/header/__snapshots__/HeaderElement.test.ts.snap @@ -206,6 +206,7 @@ exports[`HeaderElement > render > should render remove icon 1`] = ` { +export const createWebhookRouterNode = ( + headers: { [key: string]: string } = {}, +): FlowNode => { const action: CallWebhook = { uuid: utils.createUUID(), - headers: {}, + headers, type: Types.call_webhook, url: 'http://www.google.com', method: Methods.GET,