Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function SendTestEmailModal(props: MessageTemplateLogicProps & { isOpen:
sendDisabledReason,
testSendResult,
testSendResultLoading,
testSendSkipMessage,
} = useValues(logic)
const { setModalOpen, setRecipientEmail, setSenderIntegrationId, sendTestEmail } = useActions(logic)

Expand Down Expand Up @@ -86,11 +87,8 @@ export function SendTestEmailModal(props: MessageTemplateLogicProps & { isOpen:
</div>
)}
</div>
{testSendResult && testSendResult.status === 'skipped' ? (
<LemonBanner type="warning">
{testSendResult.logs?.map((log) => log.message).join(' ') ||
'The send was skipped for this recipient.'}
</LemonBanner>
{testSendSkipMessage ? (
<LemonBanner type="warning">{testSendSkipMessage}</LemonBanner>
) : testSendResult && testSendResult.status === 'error' ? (
<LemonBanner type="error">
{testSendResult.errors?.join(', ') || 'Failed to send test email'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,21 @@ describe('messageTemplateTestSendLogic', () => {
post: {
'/api/environments/:team_id/hog_flows/:id/invocations/': () => [
200,
{ status: 'skipped', logs: [{ message: 'Recipient has opted out.' }] },
{
status: 'skipped',
nextActionId: 'exit',
emailSendResult: {
status: 'skipped',
reason: 'Skipping send: recipient(s) on the suppression list — recipient@example.com',
},
logs: [
{ message: '[Action:send_test_email] Executing action' },
{
message:
'[Action:send_test_email] Skipping send: recipient(s) on the suppression list — recipient@example.com',
},
],
},
],
},
})
Expand All @@ -144,7 +158,9 @@ describe('messageTemplateTestSendLogic', () => {
expect(mockToast.warning).toHaveBeenCalledWith('Test email skipped, see details below')
expect(mockToast.error).not.toHaveBeenCalled()
expect(logic.values.isModalOpen).toBe(true)
expect(logic.values.testSendResult?.status).toBe('skipped')
expect(logic.values.testSendSkipMessage).toBe(
'Skipping send: recipient(s) on the suppression list — recipient@example.com'
)
})

it('keeps the modal open and surfaces the error when the send fails', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
senderFrom,
senderIntegrationFor,
} from '../../../../frontend/src/scenes/hog-functions/email-templater/emailSenderFields'
import { emailSkipReason } from '../Workflows/hogflows/panel/testing/getHogFlowTestResultMessage'
import { HogflowTestResult } from '../Workflows/hogflows/steps/types'
import { createExampleEvent } from '../Workflows/hogflows/testEventFactory'
import type { HogFlow, HogFlowAction, HogFlowEdge } from '../Workflows/hogflows/types'
Expand All @@ -40,6 +41,7 @@ export interface messageTemplateTestSendLogicValues {
senderIntegrationIdOverride: number | null
testSendResult: HogflowTestResult | null
testSendResultLoading: boolean
testSendSkipMessage: string | undefined
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
Expand Down Expand Up @@ -106,6 +108,7 @@ export interface messageTemplateTestSendLogicMeta {
recipientEmail: string,
senderIntegrationId: number | null
) => string | undefined
testSendSkipMessage: (testSendResult: HogflowTestResult | null) => string | undefined
}
}

Expand Down Expand Up @@ -248,6 +251,13 @@ export const messageTemplateTestSendLogic = kea<messageTemplateTestSendLogicType
return undefined
},
],
testSendSkipMessage: [
(s) => [s.testSendResult],
(testSendResult: HogflowTestResult | null): string | undefined =>
testSendResult?.status === 'skipped'
? (emailSkipReason(testSendResult) ?? 'The send was skipped for this recipient.')
: undefined,
],
}),
listeners(({ actions, values }) => ({
setModalOpen: ({ open }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
import { renderWorkflowLogMessage } from '../../../logs/log-utils'
import { TRIGGER_NODE_ID, workflowLogic } from '../../../workflowLogic'
import { hogFlowEditorLogic } from '../../hogFlowEditorLogic'
import { getHogFlowTestResultMessage } from './getHogFlowTestResultMessage'
import { hogFlowEditorNotificationTestLogic } from './hogFlowEditorNotificationTestLogic'
import { reorderGlobalsForEmailAction } from './hogFlowEditorNotificationTestLogic'

export function EmailActionTestContent(): JSX.Element | null {

Check warning on line 36 in products/workflows/frontend/Workflows/hogflows/panel/testing/HogFlowEditorNotificationPanelTest.tsx

View workflow job for this annotation

GitHub Actions / Frontend formatting

lint:complexity

`EmailActionTestContent` has cyclomatic complexity 26 (warn >10)
const { workflow, selectedNode } = useValues(hogFlowEditorLogic)
const { setSelectedNodeId } = useActions(hogFlowEditorLogic)
const { logicProps } = useValues(workflowLogic)
Expand Down Expand Up @@ -368,11 +369,7 @@
: 'error'
}
>
{testResult.status === 'success'
? 'Success'
: testResult.status === 'skipped'
? 'Workflow was skipped because the event did not match the filter criteria'
: 'Error: ' + testResult.errors?.join(', ')}
{getHogFlowTestResultMessage(testResult)}
</LemonBanner>

<div className="flex flex-col gap-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { LogsViewerTable } from 'scenes/hog-functions/logs/LogsViewer'
import { renderWorkflowLogMessage } from '../../../logs/log-utils'
import { TRIGGER_NODE_ID, workflowLogic } from '../../../workflowLogic'
import { hogFlowEditorLogic } from '../../hogFlowEditorLogic'
import { getHogFlowTestResultMessage } from './getHogFlowTestResultMessage'
import { HogFlowEditorTestEvent } from './HogFlowEditorTestEvent'
import { hogFlowEditorTestLogic } from './hogFlowEditorTestLogic'

Expand Down Expand Up @@ -157,11 +158,7 @@ export function HogFlowEditorPanelTest(): JSX.Element | null {
: 'error'
}
>
{testResult.status === 'success'
? 'Success'
: testResult.status === 'skipped'
? 'Workflow was skipped because the event did not match the filter criteria'
: 'Error: ' + testResult.errors?.join(', ')}
{getHogFlowTestResultMessage(testResult)}
</LemonBanner>

<div className="flex flex-col gap-2">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { HogflowTestResult } from '../../steps/types'
import { getHogFlowTestResultMessage } from './getHogFlowTestResultMessage'

describe('getHogFlowTestResultMessage', () => {
it.each<[string, HogflowTestResult, string]>([
['a success', { status: 'success', nextActionId: 'exit' }, 'Success'],
['an error', { status: 'error', nextActionId: null, errors: ['Invalid input'] }, 'Error: Invalid input'],
[
'an email the worker declined to send',
{
status: 'skipped',
nextActionId: 'exit',
emailSendResult: {
status: 'skipped',
reason: 'Skipping send: recipient(s) on the suppression list — person@example.com',
},
},
'Skipping send: recipient(s) on the suppression list — person@example.com',
],
[
'a skipped step without a reason',
{ status: 'skipped', nextActionId: 'exit' },
'This step was skipped. See the logs for details.',
],
[
'an event that did not match the trigger',
{ status: 'skipped', nextActionId: null },
'Workflow was skipped because the event did not match the filter criteria',
],
])('describes %s', (_label, result, expected) => {
expect(getHogFlowTestResultMessage(result)).toBe(expected)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { HogflowTestResult } from '../../steps/types'

export function emailSkipReason(result: HogflowTestResult | null): string | undefined {
return result?.emailSendResult?.status === 'skipped' ? result.emailSendResult.reason : undefined
}

export function getHogFlowTestResultMessage(result: HogflowTestResult): string {
if (result.status === 'success') {
return 'Success'
}
if (result.status === 'error') {
return 'Error: ' + result.errors?.join(', ')
}
return (
emailSkipReason(result) ??
(result.nextActionId
? 'This step was skipped. See the logs for details.'
: 'Workflow was skipped because the event did not match the filter criteria')
)
}
Loading