MCPcopy Create free account
hub / github.com/coder/coder / TestServer_NotificationTemplateID

Function TestServer_NotificationTemplateID

scaletest/smtpmock/server_test.go:117–154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

115}
116
117func TestServer_NotificationTemplateID(t *testing.T) {
118 t.Parallel()
119
120 ctx := context.Background()
121 srv := new(smtpmock.Server)
122 err := srv.Start(ctx, smtpmock.Config{
123 HostAddress: "127.0.0.1",
124 SMTPPort: 0,
125 APIPort: 0,
126 Logger: slogtest.Make(t, nil),
127 })
128 require.NoError(t, err)
129 defer srv.Stop()
130
131 notificationID := uuid.New()
132 body := fmt.Sprintf(`<p><a href=3D"http://127.0.0.1:3000/settings/notifications?disabled=3D%s">Unsubscribe</a></p>`, notificationID.String())
133
134 err = sendTestEmail(srv.SMTPAddress(), "test-user@coder.com", "Notification", body)
135 require.NoError(t, err)
136
137 require.Eventually(t, func() bool {
138 return srv.MessageCount() == 1
139 }, testutil.WaitShort, testutil.IntervalMedium)
140
141 url := fmt.Sprintf("%s/messages", srv.APIAddress())
142 req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
143 require.NoError(t, err)
144
145 resp, err := http.DefaultClient.Do(req)
146 require.NoError(t, err)
147 defer resp.Body.Close()
148
149 var summaries []smtpmock.EmailSummary
150 err = json.NewDecoder(resp.Body).Decode(&summaries)
151 require.NoError(t, err)
152 require.Len(t, summaries, 1)
153 require.Equal(t, notificationID, summaries[0].NotificationTemplateID)
154}
155
156func TestServer_Purge(t *testing.T) {
157 t.Parallel()

Callers

nothing calls this directly

Calls 12

sendTestEmailFunction · 0.85
SMTPAddressMethod · 0.80
MessageCountMethod · 0.80
StartMethod · 0.65
StopMethod · 0.65
NewMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
APIAddressMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected