(t *testing.T)
| 323 | } |
| 324 | |
| 325 | func 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 := ¬ificationstest.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 := ¬ificationstest.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 | |
| 380 | func TestCustomNotification(t *testing.T) { |
| 381 | t.Parallel() |
nothing calls this directly
no test coverage detected