Skip to content

Commit

Permalink
feat: add support for custom email templates in email notifications
Browse files Browse the repository at this point in the history
Signed-off-by: peterxcli <[email protected]>
  • Loading branch information
peterxcli committed Nov 27, 2024
1 parent aad14c9 commit f48160e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions flyteadmin/pkg/async/notifications/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,41 @@ func TestToEmailMessageFromWorkflowExecutionEvent(t *testing.T) {
assert.True(t, emailMessage.GetSenderEmail() == expected.GetSenderEmail())
assert.True(t, len(emailMessage.GetRecipientsEmail()) == len(expected.GetRecipientsEmail()))
}

func TestToEmailMessageFromWorkflowExecutionEventWithTemplate(t *testing.T) {
notificationsConfig := runtimeInterfaces.NotificationsConfig{
NotificationsEmailerConfig: runtimeInterfaces.NotificationsEmailerConfig{
Body: "Execution \"{{ name }}\" has succeeded in \"{{ domain }}\". View details at " +
"<a href=\"https://example.com/executions/{{ project }}/{{ domain }}/{{ name }}\">" +
"https://example.com/executions/{{ project }}/{{ domain }}/{{ name }}</a>.",
Sender: "[email protected]",
Subject: "Notice: Execution \"{{ name }}\" has succeeded in \"{{ domain }}\".",
},
}
emailNotification := &admin.EmailNotification{
RecipientsEmail: []string{
"[email protected]", "[email protected]",
},
Template: "LP custom template: Execution \"{{ name }}\" has succeeded in \"{{ domain }}\". View details at " +
"<a href=\"https://example.com/executions/{{ project }}/{{ domain }}/{{ name }}\">" +
"https://example.com/executions/{{ project }}/{{ domain }}/{{ name }}</a>.",
}
request := &admin.WorkflowExecutionEventRequest{
Event: &event.WorkflowExecutionEvent{
Phase: core.WorkflowExecution_ABORTED,
},
}
emailMessage := ToEmailMessageFromWorkflowExecutionEvent(notificationsConfig, emailNotification, request, workflowExecution)
expected := &admin.EmailMessage{
RecipientsEmail: []string{
"[email protected]", "[email protected]",
},
SenderEmail: "[email protected]",
SubjectLine: `Notice: Execution "e124" has succeeded in "prod".`,
Body: `LP custom template: Execution "e124" has succeeded in "prod". View details at <a href="https://example.com/executions/proj/prod/e124">https://example.com/executions/proj/prod/e124</a>.`,
}
assert.True(t, emailMessage.GetBody() == expected.GetBody())
assert.True(t, emailMessage.GetSubjectLine() == expected.GetSubjectLine())
assert.True(t, emailMessage.GetSenderEmail() == expected.GetSenderEmail())
assert.True(t, len(emailMessage.GetRecipientsEmail()) == len(expected.GetRecipientsEmail()))
}

0 comments on commit f48160e

Please sign in to comment.