(t *testing.T)
| 115 | } |
| 116 | |
| 117 | func 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 | |
| 156 | func TestServer_Purge(t *testing.T) { |
| 157 | t.Parallel() |
nothing calls this directly
no test coverage detected