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

Function TestNotifyDeletedUser

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

Source from the content-addressed store, hash-verified

648}
649
650func TestNotifyDeletedUser(t *testing.T) {
651 t.Parallel()
652
653 t.Run("OwnerNotified", func(t *testing.T) {
654 t.Parallel()
655
656 // given
657 notifyEnq := &notificationstest.FakeEnqueuer{}
658 adminClient := coderdtest.New(t, &coderdtest.Options{
659 NotificationsEnqueuer: notifyEnq,
660 })
661 firstUserResponse := coderdtest.CreateFirstUser(t, adminClient)
662
663 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
664 defer cancel()
665
666 firstUser, err := adminClient.User(ctx, firstUserResponse.UserID.String())
667 require.NoError(t, err)
668
669 user, err := adminClient.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
670 OrganizationIDs: []uuid.UUID{firstUserResponse.OrganizationID},
671 Email: "another@user.org",
672 Username: "someone-else",
673 Password: "SomeSecurePassword!",
674 })
675 require.NoError(t, err)
676
677 // when
678 err = adminClient.DeleteUser(context.Background(), user.ID)
679 require.NoError(t, err)
680
681 // then
682 require.Len(t, notifyEnq.Sent(), 2)
683 // notifyEnq.Sent()[0] is create account event
684 require.Equal(t, notifications.TemplateUserAccountDeleted, notifyEnq.Sent()[1].TemplateID)
685 require.Equal(t, firstUser.ID, notifyEnq.Sent()[1].UserID)
686 require.Contains(t, notifyEnq.Sent()[1].Targets, user.ID)
687 require.Equal(t, user.Username, notifyEnq.Sent()[1].Labels["deleted_account_name"])
688 require.Equal(t, user.Name, notifyEnq.Sent()[1].Labels["deleted_account_user_name"])
689 require.Equal(t, firstUser.Name, notifyEnq.Sent()[1].Labels["initiator"])
690 })
691
692 t.Run("UserAdminNotified", func(t *testing.T) {
693 t.Parallel()
694
695 // given
696 notifyEnq := &notificationstest.FakeEnqueuer{}
697 adminClient := coderdtest.New(t, &coderdtest.Options{
698 NotificationsEnqueuer: notifyEnq,
699 })
700 firstUser := coderdtest.CreateFirstUser(t, adminClient)
701
702 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
703 defer cancel()
704
705 _, userAdmin := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID, rbac.RoleUserAdmin())
706
707 member, err := adminClient.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{

Callers

nothing calls this directly

Calls 13

SentMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
RoleUserAdminFunction · 0.92
CreateUserWithOrgsMethod · 0.80
DeleteUserMethod · 0.80
RunMethod · 0.65
UserMethod · 0.65
StringMethod · 0.45
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected