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

Function TestNotifyUserStatusChanged

coderd/users_test.go:539–648  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

537}
538
539func TestNotifyUserStatusChanged(t *testing.T) {
540 t.Parallel()
541
542 type expectedNotification struct {
543 TemplateID uuid.UUID
544 UserID uuid.UUID
545 }
546
547 verifyNotificationDispatched := func(notifyEnq *notificationstest.FakeEnqueuer, expectedNotifications []expectedNotification, member codersdk.User, label string) {
548 require.Equal(t, len(expectedNotifications), len(notifyEnq.Sent()))
549
550 // Validate that each expected notification is present in notifyEnq.Sent()
551 for _, expected := range expectedNotifications {
552 found := false
553 for _, sent := range notifyEnq.Sent(notificationstest.WithTemplateID(expected.TemplateID)) {
554 if sent.TemplateID == expected.TemplateID &&
555 sent.UserID == expected.UserID &&
556 slices.Contains(sent.Targets, member.ID) &&
557 sent.Labels[label] == member.Username {
558 found = true
559
560 require.IsType(t, map[string]any{}, sent.Data["user"])
561 userData := sent.Data["user"].(map[string]any)
562 require.Equal(t, member.ID, userData["id"])
563 require.Equal(t, member.Name, userData["name"])
564 require.Equal(t, member.Email, userData["email"])
565
566 break
567 }
568 }
569 require.True(t, found, "Expected notification not found: %+v", expected)
570 }
571 }
572
573 t.Run("Account suspended", func(t *testing.T) {
574 t.Parallel()
575
576 notifyEnq := &notificationstest.FakeEnqueuer{}
577 adminClient := coderdtest.New(t, &coderdtest.Options{
578 NotificationsEnqueuer: notifyEnq,
579 })
580 firstUser := coderdtest.CreateFirstUser(t, adminClient)
581
582 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
583 defer cancel()
584
585 _, userAdmin := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID, rbac.RoleUserAdmin())
586
587 member, err := adminClient.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
588 OrganizationIDs: []uuid.UUID{firstUser.OrganizationID},
589 Email: "another@user.org",
590 Username: "someone-else",
591 Password: "SomeSecurePassword!",
592 })
593 require.NoError(t, err)
594
595 notifyEnq.Clear()
596

Callers

nothing calls this directly

Calls 12

SentMethod · 0.95
ClearMethod · 0.95
WithTemplateIDFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleUserAdminFunction · 0.92
CreateUserWithOrgsMethod · 0.80
RunMethod · 0.65
UpdateUserStatusMethod · 0.65
EqualMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected