Skip to content

Commit 812e6e7

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

File tree

9 files changed

+49
-40
lines changed

9 files changed

+49
-40
lines changed

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

+29-16
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,14 +330,15 @@ 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 (
@@ -365,29 +366,41 @@ export const createWebhookBasedNode = (
365366
categories = [
366367
{
367368
uuid: createUUID(),
368-
name: WebhookExitNames.Success,
369+
name: ServiceCallExitNames.Success,
369370
exit_uuid: exits[0].uuid
370371
},
371372
{
372373
uuid: createUUID(),
373-
name: WebhookExitNames.Failure,
374+
name: ServiceCallExitNames.Failure,
374375
exit_uuid: exits[1].uuid
375376
}
376377
];
377378

378-
cases = [
379-
{
380-
uuid: createUUID(),
381-
type: useCategoryTest ? Operators.has_category : Operators.has_only_text,
382-
arguments: [WebhookExitNames.Success],
383-
category_uuid: categories[0].uuid
384-
}
385-
];
379+
if (useWebhookTest) {
380+
cases = [
381+
{
382+
uuid: createUUID(),
383+
type: Operators.has_number_between,
384+
arguments: ['200', '299'],
385+
category_uuid: categories[0].uuid
386+
}
387+
];
388+
} else {
389+
cases = [
390+
{
391+
uuid: createUUID(),
392+
type: Operators.has_category,
393+
arguments: [ServiceCallExitNames.Success],
394+
category_uuid: categories[0].uuid
395+
}
396+
];
397+
}
386398
}
387399

388-
let operand = '@results.' + snakify(action.result_name);
389-
if (!useCategoryTest) {
390-
operand += '.category';
400+
if (useWebhookTest) {
401+
operand = '@webhook.status';
402+
} else {
403+
operand = '@results.' + snakify(action.result_name);
391404
}
392405

393406
const router: SwitchRouter = {

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Array [
135135
},
136136
],
137137
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
138-
"operand": "@results.result.category",
138+
"operand": "@webhook.status",
139139
"type": "switch",
140140
},
141141
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",
@@ -176,10 +176,11 @@ Array [
176176
"cases": Array [
177177
Object {
178178
"arguments": Array [
179-
"Success",
179+
"200",
180+
"299",
180181
],
181182
"category_uuid": "6c22884b-0e35-4206-982e-18320691eda9",
182-
"type": "has_only_text",
183+
"type": "has_number_between",
183184
"uuid": "0c8c9239-9b59-473a-a229-d8a9693be270",
184185
},
185186
],
@@ -196,7 +197,7 @@ Array [
196197
},
197198
],
198199
"default_category_uuid": "a62e8284-49f8-4292-adbc-d5f6607f85c5",
199-
"operand": "@results.result.category",
200+
"operand": "@webhook.status",
200201
"type": "switch",
201202
},
202203
"uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a",
@@ -274,7 +275,7 @@ Array [
274275
},
275276
],
276277
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
277-
"operand": "@results.result.category",
278+
"operand": "@webhook.status",
278279
"type": "switch",
279280
},
280281
"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/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

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ Array [
628628
},
629629
],
630630
"default_category_uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c",
631-
"operand": "@results.my_webhook_result.category",
631+
"operand": "@webhook.status",
632632
"type": "switch",
633633
},
634634
"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)