(t *testing.T)
| 648 | } |
| 649 | |
| 650 | func TestNotifyDeletedUser(t *testing.T) { |
| 651 | t.Parallel() |
| 652 | |
| 653 | t.Run("OwnerNotified", func(t *testing.T) { |
| 654 | t.Parallel() |
| 655 | |
| 656 | // given |
| 657 | notifyEnq := ¬ificationstest.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 := ¬ificationstest.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{ |
nothing calls this directly
no test coverage detected