-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for custom email templates in email notifications
Signed-off-by: peterxcli <[email protected]>
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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())) | ||
} |