Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/backend/src/apps/formsg/actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import mrfSubmission from './mrf-submission'

export default [mrfSubmission]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IGlobalVariable, IRawAction } from '@plumber/types'

import getDataOutMetadata from '../../triggers/new-submission/get-data-out-metadata'

const action: IRawAction = {
name: 'New form response',
key: 'mrfSubmission',
hiddenFromUser: true,
description:
'This is a hidden action that signifies a subsequent MRF submission',
getDataOutMetadata,

async testRun(_$: IGlobalVariable) {
// TODO: this should run testRun for the trigger execution step
},
}

export default action
3 changes: 2 additions & 1 deletion packages/backend/src/apps/formsg/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IApp } from '@plumber/types'

import beforeRequest from './common/before-request'
import actions from './actions'
import auth from './auth'
import triggers from './triggers'

Expand All @@ -16,7 +17,7 @@ const app: IApp = {
beforeRequest,
auth,
triggers,
actions: [],
actions,
demoVideoDetails: {
url: 'https://demo.arcade.software/6cWULLTHkTH4XsSB1rs1?embed&show_copy_link=true',
title: 'Setting up FormSG',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
},
}
Expand All @@ -138,8 +138,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendMessage',
appKey: 'telegram-bot',
parameters: { newParam: 'value' },
},
}
Expand All @@ -149,8 +149,8 @@ describe('createStep mutation integration tests', async () => {
// Ensure the new step is returned as expected.
expect(newStep).toBeDefined()
expect(newStep.type).toBe('action')
expect(newStep.key).toBe('newStep')
expect(newStep.appKey).toBe('test-app')
expect(newStep.key).toBe('sendMessage')
expect(newStep.appKey).toBe('telegram-bot')
// New step's position should be previousStep.position + 1.
expect(newStep.position).toBe(existingSteps[0].position + 1)

Expand Down Expand Up @@ -246,8 +246,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: 'invalid-id' }, // Non-existent step id
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
},
}
Expand All @@ -260,8 +260,8 @@ describe('createStep mutation integration tests', async () => {

expect(newStep).toBeDefined()
expect(newStep.type).toBe('action')
expect(newStep.key).toBe('newStep')
expect(newStep.appKey).toBe('test-app')
expect(newStep.key).toBe('sendTransactionalEmail')
expect(newStep.appKey).toBe('postman')
// New step's position should be previousStep.position + 1.
expect(newStep.position).toBe(existingSteps[0].position + 1)
})
Expand All @@ -272,8 +272,8 @@ describe('createStep mutation integration tests', async () => {

expect(newStep).toBeDefined()
expect(newStep.type).toBe('action')
expect(newStep.key).toBe('newStep')
expect(newStep.appKey).toBe('test-app')
expect(newStep.key).toBe('sendTransactionalEmail')
expect(newStep.appKey).toBe('postman')
// New step's position should be previousStep.position + 1.
expect(newStep.position).toBe(existingSteps[0].position + 1)
})
Expand All @@ -285,8 +285,8 @@ describe('createStep mutation integration tests', async () => {
input: {
flow: { id: testFlow.id, updatedAt: testFlowTimestampString },
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
connection: { id: testConnection.id },
connectionRole: 'owner',
Expand All @@ -296,8 +296,8 @@ describe('createStep mutation integration tests', async () => {
const newStep = await createStep(null, params, context)
expect(newStep).toBeDefined()
expect(newStep.type).toBe('action')
expect(newStep.key).toBe('newStep')
expect(newStep.appKey).toBe('test-app')
expect(newStep.key).toBe('sendTransactionalEmail')
expect(newStep.appKey).toBe('postman')
expect(newStep.position).toBe(existingSteps[0].position + 1)
})

Expand All @@ -324,8 +324,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
connection: { id: testConnection.id },
},
Expand Down Expand Up @@ -353,8 +353,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
connection: { id: randomUUID() },
},
Expand Down Expand Up @@ -385,8 +385,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
connection: { id: editorConnection.id },
},
Expand Down Expand Up @@ -417,8 +417,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
connection: { id: otherUserConnection.id },
},
Expand All @@ -437,8 +437,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
},
}
Expand All @@ -458,16 +458,16 @@ describe('createStep mutation integration tests', async () => {
updatedAt: testFlowTimestampString,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
},
}

const newStep = await createStep(null, params, context)

expect(newStep).toBeDefined()
expect(newStep.key).toBe('newStep')
expect(newStep.key).toBe('sendTransactionalEmail')
})

it('should succeed when input.flow.updatedAt is different from flow.updatedAt for same user', async () => {
Expand All @@ -481,16 +481,16 @@ describe('createStep mutation integration tests', async () => {
updatedAt: futureTimestamp,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
},
}

const newStep = await createStep(null, params, context)

expect(newStep).toBeDefined()
expect(newStep.key).toBe('newStep')
expect(newStep.key).toBe('sendTransactionalEmail')
})

it('should throw when input.flow.updatedAt is different from flow.updatedAt for different user', async () => {
Expand All @@ -505,8 +505,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: futureTimestamp,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
},
}
Expand All @@ -531,8 +531,8 @@ describe('createStep mutation integration tests', async () => {
updatedAt: oldTimestamp,
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
},
}
Expand All @@ -553,16 +553,16 @@ describe('createStep mutation integration tests', async () => {
updatedAt: 'invalid-timestamp',
},
previousStep: { id: existingSteps[0].id },
key: 'newStep',
appKey: 'test-app',
key: 'sendTransactionalEmail',
appKey: 'postman',
parameters: { newParam: 'value' },
},
}

const newStep = await createStep(null, params, context)

expect(newStep).toBeDefined()
expect(newStep.key).toBe('newStep')
expect(newStep.key).toBe('sendTransactionalEmail')
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,45 @@ describe('updateStep mutation', () => {
it('should set status to incomplete when key or appKey changes', async () => {
const input = {
...genericInputParams,
key: 'newKey',
key: 'sendMessage',
appKey: 'telegram-bot',
// remove connection from input for testing purposes
connection: { id: null } as any,
}

await updateStep(null, { input }, context)

expect(patchAndFetchByIdSpy).toHaveBeenCalledWith(mockStepId, {
key: 'newKey',
appKey: 'postman',
connectionId: mockConnectionId,
key: 'sendMessage',
appKey: 'telegram-bot',
connectionId: null,
parameters: { testParam: 'value' },
status: 'incomplete',
config: {},
updatedBy: context.currentUser.id,
})
})

it('should throw an error if the key or appKey is not found', async () => {
const input = {
...genericInputParams,
key: 'invalidKey',
}

await expect(updateStep(null, { input }, context)).rejects.toThrow(
BadUserInputError,
)

const input2 = {
...genericInputParams,
appKey: 'invalidAppKey',
}

await expect(updateStep(null, { input: input2 }, context)).rejects.toThrow(
BadUserInputError,
)
})

it('should set status to incomplete when explicitly requested', async () => {
const input = {
...genericInputParams,
Expand Down Expand Up @@ -495,8 +518,8 @@ describe('updateStep mutation', () => {
context.currentUser.withAccessibleSteps = createMockWithAccessibleSteps({
owner,
currentUser: context.currentUser,
stepKey: 'sendTransactionalEmail',
stepAppKey: 'postman',
stepKey: 'createTableRow',
stepAppKey: 'm365-excel',
flowId: mockFlowId,
flowUpdatedAt: testFlowISODateString,
})
Expand All @@ -509,6 +532,7 @@ describe('updateStep mutation', () => {
const input = {
...genericInputParams,
appKey: 'm365-excel',
key: 'createTableRow',
parameters: { fileId: '1234567890' },
}

Expand All @@ -529,7 +553,7 @@ describe('updateStep mutation', () => {
const input = {
id: mockStepId,
flow: { id: mockFlowId, updatedAt: testFlowISODateString },
key: 'sendMessage',
key: 'sendMessageToChannel',
appKey: 'slack',
parameters: { channel: 'C1234567890' },
connection: { id: mockConnectionId },
Expand All @@ -551,6 +575,7 @@ describe('updateStep mutation', () => {
const input = {
...genericInputParams,
appKey: 'slack',
key: 'sendMessageToChannel',
parameters: { message: 'Hello world' }, // No channel parameter
connection: { id: mockConnectionId },
}
Expand Down Expand Up @@ -578,7 +603,7 @@ describe('updateStep mutation', () => {
context.currentUser.withAccessibleSteps = createMockWithAccessibleSteps({
owner,
currentUser: owner,
stepKey: 'sendMessage',
stepKey: 'sendMessageToChannel',
stepAppKey: 'slack',
flowId: mockFlowId,
stepRole: 'editor', // Not owner
Expand All @@ -600,6 +625,7 @@ describe('updateStep mutation', () => {
const input = {
...genericInputParams,
appKey: 'slack',
key: 'sendMessageToChannel',
parameters: { channel: 'C1234567890' },
connection: { id: mockConnectionId },
}
Expand Down Expand Up @@ -671,7 +697,7 @@ describe('updateStep mutation', () => {
context.currentUser.withAccessibleSteps = createMockWithAccessibleSteps({
owner,
currentUser: owner,
stepKey: 'readAction',
stepKey: 'createTileRow',
stepAppKey: 'tiles',
stepRole: 'owner',
flowUpdatedAt: testFlowISODateString,
Expand All @@ -680,6 +706,7 @@ describe('updateStep mutation', () => {
const input = {
...genericInputParams,
appKey: 'tiles',
key: 'createTileRow',
connection: {},
parameters: { tableId: mockTableId },
}
Expand Down
Loading