mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd/notifications): improve notification format consistency (#14967)
This Pull request addresses the more trivial items in https://github.com/coder/coder/issues/14893. These were simple formatting changes that I was able to fix despite limited context. Some more changes are required for which I will have to dig a bit deeper into how the template contexts are populated. I'm happy to add those to this PR or create a subsequent PR.
This commit is contained in:
@@ -684,7 +684,7 @@ func enumerateAllTemplates(t *testing.T) ([]string, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
func TestNotificationTemplates_Golden(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if !dbtestutil.WillUsePostgres() {
|
||||
@@ -764,7 +764,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
payload: types.MessagePayload{
|
||||
UserName: "Bobby",
|
||||
Labels: map[string]string{
|
||||
"created_account_name": "bobby",
|
||||
"created_account_name": "bobby",
|
||||
"created_account_user_name": "William Tables",
|
||||
"account_creator": "rob",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -774,7 +776,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
payload: types.MessagePayload{
|
||||
UserName: "Bobby",
|
||||
Labels: map[string]string{
|
||||
"deleted_account_name": "bobby",
|
||||
"deleted_account_name": "bobby",
|
||||
"deleted_account_user_name": "william tables",
|
||||
"account_deleter_user_name": "rob",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -784,7 +788,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
payload: types.MessagePayload{
|
||||
UserName: "Bobby",
|
||||
Labels: map[string]string{
|
||||
"suspended_account_name": "bobby",
|
||||
"suspended_account_name": "bobby",
|
||||
"suspended_account_user_name": "william tables",
|
||||
"account_suspender_user_name": "rob",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -794,7 +800,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
payload: types.MessagePayload{
|
||||
UserName: "Bobby",
|
||||
Labels: map[string]string{
|
||||
"activated_account_name": "bobby",
|
||||
"activated_account_name": "bobby",
|
||||
"activated_account_user_name": "william tables",
|
||||
"account_activator_user_name": "rob",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -804,7 +812,8 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
payload: types.MessagePayload{
|
||||
UserName: "Bobby",
|
||||
Labels: map[string]string{
|
||||
"suspended_account_name": "bobby",
|
||||
"suspended_account_name": "bobby",
|
||||
"account_suspender_user_name": "rob",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -814,7 +823,8 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
payload: types.MessagePayload{
|
||||
UserName: "Bobby",
|
||||
Labels: map[string]string{
|
||||
"activated_account_name": "bobby",
|
||||
"activated_account_name": "bobby",
|
||||
"account_activator_user_name": "rob",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -824,8 +834,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
payload: types.MessagePayload{
|
||||
UserName: "Bobby",
|
||||
Labels: map[string]string{
|
||||
"name": "bobby-template",
|
||||
"initiator": "rob",
|
||||
"name": "bobby-template",
|
||||
"display_name": "Bobby's Template",
|
||||
"initiator": "rob",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -837,6 +848,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
Labels: map[string]string{
|
||||
"name": "bobby-workspace",
|
||||
"template_name": "bobby-template",
|
||||
"template_display_name": "William's Template",
|
||||
"template_version_name": "bobby-template-version",
|
||||
"initiator": "joe",
|
||||
"workspace_owner_username": "mrbobby",
|
||||
@@ -960,13 +972,15 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
wantBody, err := os.ReadFile(bodyGoldenFile)
|
||||
require.NoError(t, err, "open golden file, run \"DB=ci make update-golden-files\" and commit the changes")
|
||||
wantTitle, err := os.ReadFile(titleGoldenFile)
|
||||
require.NoError(t, err, "open golden file, run \"DB=ci make update-golden-files\" and commit the changes")
|
||||
const hint = "run \"DB=ci make update-golden-files\" and commit the changes"
|
||||
|
||||
require.Equal(t, string(wantBody), body, "body should be equal")
|
||||
require.Equal(t, string(wantTitle), title, "title should be equal")
|
||||
wantBody, err := os.ReadFile(bodyGoldenFile)
|
||||
require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint))
|
||||
wantTitle, err := os.ReadFile(titleGoldenFile)
|
||||
require.NoError(t, err, fmt.Sprintf("missing golden notification title file. %s", hint))
|
||||
|
||||
require.Equal(t, string(wantBody), body, fmt.Sprintf("rendered template body does not match golden file. If this is expected, %s", hint))
|
||||
require.Equal(t, string(wantTitle), title, fmt.Sprintf("rendered template title does not match golden file. If this is expected, %s", hint))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -1,3 +1,5 @@
|
||||
Hi Bobby
|
||||
Hi Bobby,
|
||||
|
||||
The template **bobby-template** was deleted by **rob**.
|
||||
The template **bobby-template** was deleted by **rob**.
|
||||
|
||||
The template's display name was **Bobby's Template**.
|
||||
Vendored
+4
-1
@@ -1,2 +1,5 @@
|
||||
Hi Bobby,
|
||||
User account **bobby** has been activated.
|
||||
|
||||
User account **bobby** has been activated.
|
||||
|
||||
The newly activated account belongs to **william tables** and was activated by **rob**.
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
Hi Bobby,
|
||||
|
||||
New user account **bobby** has been created.
|
||||
New user account **bobby** has been created.
|
||||
|
||||
This new user account was created for **William Tables** by **rob**.
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
Hi Bobby,
|
||||
|
||||
User account **bobby** has been deleted.
|
||||
User account **bobby** has been deleted.
|
||||
|
||||
The deleted account belonged to **william tables** and was deleted by **rob**.
|
||||
Vendored
+4
-1
@@ -1,2 +1,5 @@
|
||||
Hi Bobby,
|
||||
User account **bobby** has been suspended.
|
||||
|
||||
User account **bobby** has been suspended.
|
||||
|
||||
The newly suspended account belongs to **william tables** and was suspended by **rob**.
|
||||
Vendored
+4
-2
@@ -1,3 +1,5 @@
|
||||
Hi Bobby
|
||||
Hi Bobby,
|
||||
|
||||
Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0).
|
||||
Reason for update: **template now includes catnip**
|
||||
|
||||
Reason for update: **template now includes catnip**.
|
||||
Vendored
+3
-1
@@ -1,3 +1,5 @@
|
||||
Hi Bobby
|
||||
Hi Bobby,
|
||||
|
||||
Automatic build of your workspace **bobby-workspace** failed.
|
||||
|
||||
The specified reason was "**autostart**".
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
Hi Bobby
|
||||
Hi Bobby,
|
||||
|
||||
Your workspace **bobby-workspace** was deleted.
|
||||
|
||||
The specified reason was "**autodeleted due to dormancy (autobuild)**".
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
Hi Bobby
|
||||
Hi Bobby,
|
||||
|
||||
Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.
|
||||
Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity.
|
||||
|
||||
Vendored
+2
-1
@@ -1,4 +1,5 @@
|
||||
Hi Bobby,
|
||||
|
||||
A manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).
|
||||
The workspace build was initiated by **joe**.
|
||||
|
||||
The template's display name was **William's Template**. The workspace build was initiated by **joe**.
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
Hi Bobby
|
||||
Hi Bobby,
|
||||
|
||||
Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.
|
||||
To prevent deletion, use your workspace with the link below.
|
||||
Vendored
+2
-1
@@ -1,2 +1,3 @@
|
||||
Hi Bobby,
|
||||
Your account **bobby** has been activated.
|
||||
|
||||
Your account **bobby** has been activated by **rob**.
|
||||
Vendored
+2
-1
@@ -1,2 +1,3 @@
|
||||
Hi Bobby,
|
||||
Your account **bobby** has been suspended.
|
||||
|
||||
Your account **bobby** has been suspended by **rob**.
|
||||
Reference in New Issue
Block a user