Skip to content

Commit 0a97677

Browse files
committed
Rework webhook nodes to route on @webhook.status
1 parent 7d6db62 commit 0a97677

File tree

11 files changed

+72
-66
lines changed

11 files changed

+72
-66
lines changed

src/components/flow/routers/airtime/__snapshots__/AirtimeRouterForm.test.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Array [
156156
],
157157
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
158158
"type": "has_category",
159-
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
159+
"uuid": "e67ce051-f3e4-4c42-807b-e393df5fa382",
160160
},
161161
],
162162
"categories": Array [
@@ -245,7 +245,7 @@ Array [
245245
],
246246
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
247247
"type": "has_category",
248-
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
248+
"uuid": "42ebf1d0-a43e-4ba6-9577-c863b20c88c4",
249249
},
250250
],
251251
"categories": Array [

src/components/flow/routers/airtime/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
AirtimeRouterFormState,
33
AirtimeTransferEntry
44
} from 'components/flow/routers/airtime/AirtimeRouterForm';
5-
import { createWebhookBasedNode } from 'components/flow/routers/helpers';
5+
import { createServiceCallSplitNode } from 'components/flow/routers/helpers';
66
import { Types } from 'config/interfaces';
77
import { TransferAirtime } from 'flowTypes';
88
import { RenderNode } from 'store/flowContext';
@@ -56,7 +56,7 @@ export const stateToNode = (
5656
result_name: state.resultName.value
5757
};
5858

59-
return createWebhookBasedNode(newAction, settings.originalNode, true);
59+
return createServiceCallSplitNode(newAction, settings.originalNode, false);
6060
};
6161

6262
export const getOriginalAction = (settings: NodeEditorSettings): TransferAirtime => {

src/components/flow/routers/helpers.ts

+22-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
SwitchRouter,
1515
TransferAirtime,
1616
UIConfig,
17-
WebhookExitNames,
17+
ServiceCallExitNames,
1818
CallClassifier,
1919
OpenTicket
2020
} from 'flowTypes';
@@ -330,24 +330,23 @@ export const resolveRoutes = (
330330
return results;
331331
};
332332

333-
export const createWebhookBasedNode = (
333+
export const createServiceCallSplitNode = (
334334
action: CallWebhook | CallResthook | OpenTicket | TransferAirtime,
335335
originalNode: RenderNode,
336-
useCategoryTest: boolean
336+
useWebhookTest: boolean
337337
): RenderNode => {
338338
const exits: Exit[] = [];
339339
let cases: Case[] = [];
340340
let categories: Category[] = [];
341+
let operand = '';
341342

342343
// see if we are editing an existing router so we reuse exits
343344
if (
344345
originalNode &&
345346
originalNode.node.actions.length === 1 &&
346347
originalNode.node.actions[0].type === action.type
347348
) {
348-
const previousRouter = getSwitchRouter(originalNode.node);
349-
originalNode.node.exits.forEach((exit: any) => exits.push(exit));
350-
previousRouter.cases.forEach(kase => cases.push(kase));
349+
originalNode.node.exits.forEach((exit: Exit) => exits.push(exit));
351350
originalNode.node.router.categories.forEach(category => categories.push(category));
352351
} else {
353352
// Otherwise, let's create some new ones
@@ -365,29 +364,37 @@ export const createWebhookBasedNode = (
365364
categories = [
366365
{
367366
uuid: createUUID(),
368-
name: WebhookExitNames.Success,
367+
name: ServiceCallExitNames.Success,
369368
exit_uuid: exits[0].uuid
370369
},
371370
{
372371
uuid: createUUID(),
373-
name: WebhookExitNames.Failure,
372+
name: ServiceCallExitNames.Failure,
374373
exit_uuid: exits[1].uuid
375374
}
376375
];
376+
}
377377

378+
if (useWebhookTest) {
379+
operand = '@webhook.status';
378380
cases = [
379381
{
380382
uuid: createUUID(),
381-
type: useCategoryTest ? Operators.has_category : Operators.has_only_text,
382-
arguments: [WebhookExitNames.Success],
383+
type: Operators.has_number_between,
384+
arguments: ['200', '299'],
385+
category_uuid: categories[0].uuid
386+
}
387+
];
388+
} else {
389+
operand = '@results.' + snakify(action.result_name);
390+
cases = [
391+
{
392+
uuid: createUUID(),
393+
type: Operators.has_category,
394+
arguments: [ServiceCallExitNames.Success],
383395
category_uuid: categories[0].uuid
384396
}
385397
];
386-
}
387-
388-
let operand = '@results.' + snakify(action.result_name);
389-
if (!useCategoryTest) {
390-
operand += '.category';
391398
}
392399

393400
const router: SwitchRouter = {

src/components/flow/routers/resthook/__snapshots__/ResthookRouterForm.test.ts.snap

+24-21
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ Array [
115115
"cases": Array [
116116
Object {
117117
"arguments": Array [
118-
"Success",
118+
"200",
119+
"299",
119120
],
120121
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
121-
"type": "has_only_text",
122-
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
122+
"type": "has_number_between",
123+
"uuid": "e67ce051-f3e4-4c42-807b-e393df5fa382",
123124
},
124125
],
125126
"categories": Array [
@@ -135,7 +136,7 @@ Array [
135136
},
136137
],
137138
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
138-
"operand": "@results.result.category",
139+
"operand": "@webhook.status",
139140
"type": "switch",
140141
},
141142
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",
@@ -159,44 +160,45 @@ Array [
159160
"resthook": "new-resthook",
160161
"result_name": "Result",
161162
"type": "call_resthook",
162-
"uuid": "70ac6ea6-803a-4c33-81c7-dc26803c313f",
163+
"uuid": "e0bc3776-792f-49d2-b4be-48be2cf8159a",
163164
},
164165
],
165166
"exits": Array [
166167
Object {
167168
"destination_uuid": null,
168-
"uuid": "e67ce051-f3e4-4c42-807b-e393df5fa382",
169+
"uuid": "6c22884b-0e35-4206-982e-18320691eda9",
169170
},
170171
Object {
171172
"destination_uuid": null,
172-
"uuid": "e0bc3776-792f-49d2-b4be-48be2cf8159a",
173+
"uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
173174
},
174175
],
175176
"router": Object {
176177
"cases": Array [
177178
Object {
178179
"arguments": Array [
179-
"Success",
180+
"200",
181+
"299",
180182
],
181-
"category_uuid": "6c22884b-0e35-4206-982e-18320691eda9",
182-
"type": "has_only_text",
183-
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
183+
"category_uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
184+
"type": "has_number_between",
185+
"uuid": "6b59e863-2e14-442b-9987-aaa284871b8e",
184186
},
185187
],
186188
"categories": Array [
187189
Object {
188-
"exit_uuid": "e67ce051-f3e4-4c42-807b-e393df5fa382",
190+
"exit_uuid": "6c22884b-0e35-4206-982e-18320691eda9",
189191
"name": "Success",
190-
"uuid": "6c22884b-0e35-4206-982e-18320691eda9",
192+
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
191193
},
192194
Object {
193-
"exit_uuid": "e0bc3776-792f-49d2-b4be-48be2cf8159a",
195+
"exit_uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
194196
"name": "Failure",
195-
"uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
197+
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
196198
},
197199
],
198-
"default_category_uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
199-
"operand": "@results.result.category",
200+
"default_category_uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
201+
"operand": "@webhook.status",
200202
"type": "switch",
201203
},
202204
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",
@@ -254,11 +256,12 @@ Array [
254256
"cases": Array [
255257
Object {
256258
"arguments": Array [
257-
"Success",
259+
"200",
260+
"299",
258261
],
259262
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
260-
"type": "has_only_text",
261-
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
263+
"type": "has_number_between",
264+
"uuid": "42ebf1d0-a43e-4ba6-9577-c863b20c88c4",
262265
},
263266
],
264267
"categories": Array [
@@ -274,7 +277,7 @@ Array [
274277
},
275278
],
276279
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
277-
"operand": "@results.result.category",
280+
"operand": "@webhook.status",
278281
"type": "switch",
279282
},
280283
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",

src/components/flow/routers/resthook/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createWebhookBasedNode } from 'components/flow/routers/helpers';
1+
import { createServiceCallSplitNode } from 'components/flow/routers/helpers';
22
import { Types } from 'config/interfaces';
33
import { CallResthook } from 'flowTypes';
44
import { RenderNode } from 'store/flowContext';
@@ -46,7 +46,7 @@ export const stateToNode = (
4646
result_name: state.resultName.value
4747
};
4848

49-
return createWebhookBasedNode(newAction, settings.originalNode, false);
49+
return createServiceCallSplitNode(newAction, settings.originalNode, true);
5050
};
5151

5252
export const getOriginalAction = (settings: NodeEditorSettings): CallResthook => {

src/components/flow/routers/ticket/__snapshots__/TicketRouterForm.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ Array [
406406
],
407407
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
408408
"type": "has_category",
409-
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
409+
"uuid": "42ebf1d0-a43e-4ba6-9577-c863b20c88c4",
410410
},
411411
],
412412
"categories": Array [

src/components/flow/routers/ticket/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createWebhookBasedNode } from 'components/flow/routers/helpers';
1+
import { createServiceCallSplitNode } from 'components/flow/routers/helpers';
22
import { Types } from 'config/interfaces';
33
import { getType } from 'config/typeConfigs';
44
import { OpenTicket } from 'flowTypes';
@@ -64,5 +64,5 @@ export const stateToNode = (
6464
result_name: state.resultName.value
6565
};
6666

67-
return createWebhookBasedNode(newAction, settings.originalNode, true);
67+
return createServiceCallSplitNode(newAction, settings.originalNode, false);
6868
};

src/components/flow/routers/webhook/__snapshots__/WebhookRouterForm.test.tsx.snap

+10-9
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,14 @@ Object {
280280
Object {
281281
"value": Object {
282282
"name": "Accept",
283-
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
283+
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
284284
"value": "application/json",
285285
},
286286
},
287287
Object {
288288
"value": Object {
289289
"name": "",
290-
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
290+
"uuid": "6b59e863-2e14-442b-9987-aaa284871b8e",
291291
"value": "",
292292
},
293293
},
@@ -328,23 +328,23 @@ Object {
328328
Object {
329329
"value": Object {
330330
"name": "Accept",
331-
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
331+
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
332332
"value": "application/json",
333333
},
334334
},
335335
Object {
336336
"validationFailures": undefined,
337337
"value": Object {
338338
"name": "Content-Type",
339-
"uuid": "9adce29f-da95-4182-9cb3-0f1e3bf714e5",
339+
"uuid": "6b59e863-2e14-442b-9987-aaa284871b8e",
340340
"value": "application/json",
341341
},
342342
},
343343
Object {
344344
"validationFailures": undefined,
345345
"value": Object {
346346
"name": "",
347-
"uuid": "00dd2423-0a34-4ee2-b97d-839fb2d593ef",
347+
"uuid": "c5722340-f7e1-4d99-ac5e-3a6e59845111",
348348
"value": "",
349349
},
350350
},
@@ -608,11 +608,12 @@ Array [
608608
"cases": Array [
609609
Object {
610610
"arguments": Array [
611-
"Success",
611+
"200",
612+
"299",
612613
],
613614
"category_uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41",
614-
"type": "has_only_text",
615-
"uuid": "1e47a1e1-3c67-4df5-adf1-da542c789adb",
615+
"type": "has_number_between",
616+
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
616617
},
617618
],
618619
"categories": Array [
@@ -628,7 +629,7 @@ Array [
628629
},
629630
],
630631
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
631-
"operand": "@results.my_webhook_result.category",
632+
"operand": "@webhook.status",
632633
"type": "switch",
633634
},
634635
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",

src/components/flow/routers/webhook/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createWebhookBasedNode } from 'components/flow/routers/helpers';
1+
import { createServiceCallSplitNode } from 'components/flow/routers/helpers';
22
import { WebhookRouterFormState } from 'components/flow/routers/webhook/WebhookRouterForm';
33
import { DEFAULT_BODY } from 'components/nodeeditor/constants';
44
import { Types } from 'config/interfaces';
@@ -133,7 +133,7 @@ export const stateToNode = (
133133
result_name: state.resultName.value
134134
};
135135

136-
return createWebhookBasedNode(newAction, settings.originalNode, false);
136+
return createServiceCallSplitNode(newAction, settings.originalNode, true);
137137
};
138138

139139
export const getDefaultBody = (method: string): string => {

src/flowTypes.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,11 @@ export enum StartFlowExitNames {
585585
Expired = 'Expired'
586586
}
587587

588-
export enum WebhookExitNames {
588+
export enum ServiceCallExitNames {
589589
Success = 'Success',
590590
Failure = 'Failure'
591591
}
592592

593-
export enum TransferAirtimeExitNames {
594-
Success = 'Success',
595-
Failure = 'Failed'
596-
}
597-
598593
export enum DialCategoryNames {
599594
Answered = 'Answered',
600595
NoAnswer = 'No Answer',

src/testUtils/assetCreators.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
UINode,
5252
Wait,
5353
WaitTypes,
54-
WebhookExitNames,
54+
ServiceCallExitNames,
5555
HintTypes,
5656
CallClassifier,
5757
ComposeAttachment
@@ -387,15 +387,15 @@ export const createWebhookNode = (
387387
useCategoryTest: boolean
388388
) => {
389389
const { categories, exits } = createCategories([
390-
WebhookExitNames.Success,
391-
WebhookExitNames.Failure
390+
ServiceCallExitNames.Success,
391+
ServiceCallExitNames.Failure
392392
]);
393393

394394
const cases: Case[] = [
395395
{
396396
uuid: utils.createUUID(),
397397
type: useCategoryTest ? Operators.has_category : Operators.has_only_text,
398-
arguments: [WebhookExitNames.Success],
398+
arguments: [ServiceCallExitNames.Success],
399399
category_uuid: categories[0].uuid
400400
}
401401
];

0 commit comments

Comments
 (0)