Skip to content

Commit 0c131a5

Browse files
committed
feat(notifications): working on tests for logo and app_name
1 parent 9c6c105 commit 0c131a5

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

coderd/notifications/dispatch/smtp/html.gotmpl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
<body style="margin: 0; padding: 0; font-family: -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; color: #020617; background: #f8fafc;">
99
<div style="max-width: 600px; margin: 20px auto; padding: 60px; border: 1px solid #e2e8f0; border-radius: 8px; background-color: #fff; text-align: left; font-size: 14px; line-height: 1.5;">
1010
<div style="text-align: center;">
11-
<img src="{{ logo_url }}" alt="Logo" style="height: 40px;" />
12-
<h1 style="text-align: center; font-size: 36px; font-weight: 400; margin: 8px 0 32px; line-height: 1.5;">
13-
{{ app_name }}
14-
</h1>
11+
<img src="{{ logo_url }}" alt="{{ app_name }} Logo" style="height: 40px;" />
1512
</div>
1613
<h1 style="text-align: center; font-size: 24px; font-weight: 400; margin: 8px 0 32px; line-height: 1.5;">
1714
{{ .Labels._subject }}

coderd/notifications/fetcher.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package notifications
2+
3+
import (
4+
"context"
5+
"database/sql"
6+
"errors"
7+
8+
"golang.org/x/xerrors"
9+
)
10+
11+
func (n *notifier) FetchAppName(ctx context.Context) (string, error) {
12+
appName, err := n.store.GetApplicationName(ctx)
13+
if err != nil {
14+
if errors.Is(err, sql.ErrNoRows) {
15+
return notificationsDefaultAppName, nil
16+
}
17+
return "", xerrors.Errorf("get organization: %w", err)
18+
}
19+
return appName, nil
20+
}
21+
22+
func (n *notifier) FetchLogoURL(ctx context.Context) (string, error) {
23+
logoURL, err := n.store.GetLogoURL(ctx)
24+
if err != nil {
25+
if errors.Is(err, sql.ErrNoRows) {
26+
return notificationsDefaultLogoURL, nil
27+
}
28+
return "", xerrors.Errorf("get logo URL: %w", err)
29+
}
30+
return logoURL, nil
31+
}

coderd/notifications/notifier.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package notifications
22

33
import (
44
"context"
5-
"database/sql"
65
"encoding/json"
7-
"errors"
86
"sync"
97
"text/template"
108

@@ -230,25 +228,18 @@ func (n *notifier) prepare(ctx context.Context, msg database.AcquireNotification
230228
return nil, xerrors.Errorf("failed to resolve handler %q", msg.Method)
231229
}
232230

233-
appName, err := n.store.GetApplicationName(ctx)
234-
if err != nil {
235-
if !errors.Is(err, sql.ErrNoRows) {
236-
return nil, xerrors.Errorf("get application name: %w", err)
237-
}
238-
appName = notificationsDefaultAppName
231+
helpers := make(template.FuncMap)
232+
for k, v := range n.helpers {
233+
helpers[k] = v
239234
}
240235

241-
logoURL, err := n.store.GetLogoURL(ctx)
236+
appName, err := n.FetchAppName(ctx)
242237
if err != nil {
243-
if !errors.Is(err, sql.ErrNoRows) {
244-
return nil, xerrors.Errorf("get logo URL: %w", err)
245-
}
246-
logoURL = notificationsDefaultLogoURL
238+
return nil, xerrors.Errorf("fetch app name: %w", err)
247239
}
248-
249-
helpers := make(template.FuncMap)
250-
for k, v := range n.helpers {
251-
helpers[k] = v
240+
logoURL, err := n.FetchLogoURL(ctx)
241+
if err != nil {
242+
return nil, xerrors.Errorf("fetch logo URL: %w", err)
252243
}
253244

254245
helpers["app_name"] = func() string { return appName }

coderd/notifications/utils_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ func defaultHelpers() map[string]any {
3939
return map[string]any{
4040
"base_url": func() string { return "http://test.com" },
4141
"current_year": func() string { return "2024" },
42-
"logo_url": func() string { return "https://coder.com/coder-logo-horizontal.png" },
43-
"app_name": func() string { return "Coder" },
4442
}
4543
}
4644

0 commit comments

Comments
 (0)