File tree Expand file tree Collapse file tree 4 files changed +59
-24
lines changed
Expand file tree Collapse file tree 4 files changed +59
-24
lines changed Original file line number Diff line number Diff line change @@ -138,8 +138,8 @@ describe('createStep mutation integration tests', async () => {
138138 updatedAt : testFlowTimestampString ,
139139 } ,
140140 previousStep : { id : existingSteps [ 0 ] . id } ,
141- key : 'newStep ' ,
142- appKey : 'test-app ' ,
141+ key : 'sendMessage ' ,
142+ appKey : 'telegram-bot ' ,
143143 parameters : { newParam : 'value' } ,
144144 } ,
145145 }
@@ -149,8 +149,8 @@ describe('createStep mutation integration tests', async () => {
149149 // Ensure the new step is returned as expected.
150150 expect ( newStep ) . toBeDefined ( )
151151 expect ( newStep . type ) . toBe ( 'action' )
152- expect ( newStep . key ) . toBe ( 'newStep ' )
153- expect ( newStep . appKey ) . toBe ( 'test-app ' )
152+ expect ( newStep . key ) . toBe ( 'sendMessage ' )
153+ expect ( newStep . appKey ) . toBe ( 'telegram-bot ' )
154154 // New step's position should be previousStep.position + 1.
155155 expect ( newStep . position ) . toBe ( existingSteps [ 0 ] . position + 1 )
156156
Original file line number Diff line number Diff line change @@ -206,22 +206,45 @@ describe('updateStep mutation', () => {
206206 it ( 'should set status to incomplete when key or appKey changes' , async ( ) => {
207207 const input = {
208208 ...genericInputParams ,
209- key : 'newKey' ,
209+ key : 'sendMessage' ,
210+ appKey : 'telegram-bot' ,
211+ // remove connection from input for testing purposes
212+ connection : { id : null } as any ,
210213 }
211214
212215 await updateStep ( null , { input } , context )
213216
214217 expect ( patchAndFetchByIdSpy ) . toHaveBeenCalledWith ( mockStepId , {
215- key : 'newKey ' ,
216- appKey : 'postman ' ,
217- connectionId : mockConnectionId ,
218+ key : 'sendMessage ' ,
219+ appKey : 'telegram-bot ' ,
220+ connectionId : null ,
218221 parameters : { testParam : 'value' } ,
219222 status : 'incomplete' ,
220223 config : { } ,
221224 updatedBy : context . currentUser . id ,
222225 } )
223226 } )
224227
228+ it ( 'should throw an error if the key or appKey is not found' , async ( ) => {
229+ const input = {
230+ ...genericInputParams ,
231+ key : 'invalidKey' ,
232+ }
233+
234+ await expect ( updateStep ( null , { input } , context ) ) . rejects . toThrow (
235+ BadUserInputError ,
236+ )
237+
238+ const input2 = {
239+ ...genericInputParams ,
240+ appKey : 'invalidAppKey' ,
241+ }
242+
243+ await expect ( updateStep ( null , { input : input2 } , context ) ) . rejects . toThrow (
244+ BadUserInputError ,
245+ )
246+ } )
247+
225248 it ( 'should set status to incomplete when explicitly requested' , async ( ) => {
226249 const input = {
227250 ...genericInputParams ,
Original file line number Diff line number Diff line change @@ -15,18 +15,19 @@ const createStep: MutationResolvers['createStep'] = async (
1515) => {
1616 const { input } = params
1717
18- const triggerOrAction = await App . findTriggerOrActionByKey (
19- input . appKey ,
20- input . key ,
21- )
22-
23- if ( ! triggerOrAction ) {
24- throw new BadUserInputError ( 'No such trigger or action' )
25- }
26- if ( 'hiddenFromUser' in triggerOrAction && triggerOrAction . hiddenFromUser ) {
27- throw new BadUserInputError ( 'Action can only be created by system' )
18+ /**
19+ * appKey and key are optional, we allow creating of empty step for if-then branches
20+ */
21+ if ( input . appKey && input . key ) {
22+ const triggerOrAction = await App . findTriggerOrActionByKey (
23+ input . appKey ,
24+ input . key ,
25+ )
26+
27+ if ( 'hiddenFromUser' in triggerOrAction && triggerOrAction . hiddenFromUser ) {
28+ throw new BadUserInputError ( 'Action can only be created by system' )
29+ }
2830 }
29-
3031 return await Step . transaction ( async ( trx ) => {
3132 await trx . raw ( 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;' )
3233
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { memoize } from 'lodash'
55import apps from '@/apps'
66import appInfoConverter from '@/helpers/app-info-converter'
77import getApp from '@/helpers/get-app'
8+ import logger from '@/helpers/logger'
89
910class App {
1011 static list = Object . keys ( apps )
@@ -41,11 +42,21 @@ class App {
4142 appKey : string ,
4243 key : string ,
4344 ) : Promise < ITrigger | IAction > {
44- const app = await this . findOneByKey ( appKey )
45- return (
46- app . triggers ?. find ( ( trigger ) => trigger . key === key ) ||
47- app . actions ?. find ( ( action ) => action . key === key )
48- )
45+ try {
46+ const app = await this . findOneByKey ( appKey )
47+ return (
48+ app . triggers ?. find ( ( trigger ) => trigger . key === key ) ||
49+ app . actions ?. find ( ( action ) => action . key === key )
50+ )
51+ } catch {
52+ logger . error ( {
53+ event : 'findTriggerOrActionByKey' ,
54+ message : 'No such trigger or action' ,
55+ appKey,
56+ key,
57+ } )
58+ return null
59+ }
4960 }
5061
5162 static getAllAppsWithFunctions = memoize ( async ( ) => {
You can’t perform that action at this time.
0 commit comments