MCPcopy Index your code
hub / github.com/coder/coder / TestNotificationTest

Function TestNotificationTest

coderd/notifications_test.go:325–378  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

323}
324
325func TestNotificationTest(t *testing.T) {
326 t.Parallel()
327
328 t.Run("OwnerCanSendTestNotification", func(t *testing.T) {
329 t.Parallel()
330
331 ctx := testutil.Context(t, testutil.WaitShort)
332
333 notifyEnq := &notificationstest.FakeEnqueuer{}
334 ownerClient := coderdtest.New(t, &coderdtest.Options{
335 DeploymentValues: coderdtest.DeploymentValues(t),
336 NotificationsEnqueuer: notifyEnq,
337 })
338
339 // Given: A user with owner permissions.
340 _ = coderdtest.CreateFirstUser(t, ownerClient)
341
342 // When: They attempt to send a test notification.
343 err := ownerClient.PostTestNotification(ctx)
344 require.NoError(t, err)
345
346 // Then: We expect a notification to have been sent.
347 sent := notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateTestNotification))
348 require.Len(t, sent, 1)
349 })
350
351 t.Run("MemberCannotSendTestNotification", func(t *testing.T) {
352 t.Parallel()
353
354 ctx := testutil.Context(t, testutil.WaitShort)
355
356 notifyEnq := &notificationstest.FakeEnqueuer{}
357 ownerClient := coderdtest.New(t, &coderdtest.Options{
358 DeploymentValues: coderdtest.DeploymentValues(t),
359 NotificationsEnqueuer: notifyEnq,
360 })
361
362 // Given: A user without owner permissions.
363 ownerUser := coderdtest.CreateFirstUser(t, ownerClient)
364 memberClient, _ := coderdtest.CreateAnotherUser(t, ownerClient, ownerUser.OrganizationID)
365
366 // When: They attempt to send a test notification.
367 err := memberClient.PostTestNotification(ctx)
368
369 // Then: We expect a forbidden error with no notifications sent
370 var sdkError *codersdk.Error
371 require.Error(t, err)
372 require.ErrorAsf(t, err, &sdkError, "error should be of type *codersdk.Error")
373 require.Equal(t, http.StatusForbidden, sdkError.StatusCode())
374
375 sent := notifyEnq.Sent(notificationstest.WithTemplateID(notifications.TemplateTestNotification))
376 require.Len(t, sent, 0)
377 })
378}
379
380func TestCustomNotification(t *testing.T) {
381 t.Parallel()

Callers

nothing calls this directly

Calls 13

SentMethod · 0.95
StatusCodeMethod · 0.95
ContextFunction · 0.92
NewFunction · 0.92
DeploymentValuesFunction · 0.92
CreateFirstUserFunction · 0.92
WithTemplateIDFunction · 0.92
CreateAnotherUserFunction · 0.92
PostTestNotificationMethod · 0.80
RunMethod · 0.65
LenMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected