TestSuspendedPagination is when the after_id is a suspended record. The database query should still return the correct page, as the after_id is in a subquery that finds the record regardless of its status. This is mainly to confirm the db fake has the same behavior.
(t *testing.T)
| 2779 | // is in a subquery that finds the record regardless of its status. |
| 2780 | // This is mainly to confirm the db fake has the same behavior. |
| 2781 | func TestSuspendedPagination(t *testing.T) { |
| 2782 | t.Parallel() |
| 2783 | t.Skip("This fails when two users are created at the exact same time. The reason is unknown... See: https://github.com/coder/coder/actions/runs/3057047622/jobs/4931863163") |
| 2784 | client := coderdtest.New(t, nil) |
| 2785 | coderdtest.CreateFirstUser(t, client) |
| 2786 | |
| 2787 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 2788 | t.Cleanup(cancel) |
| 2789 | |
| 2790 | me, err := client.User(ctx, codersdk.Me) |
| 2791 | require.NoError(t, err) |
| 2792 | orgID := me.OrganizationIDs[0] |
| 2793 | |
| 2794 | total := 10 |
| 2795 | users := make([]codersdk.User, 0, total) |
| 2796 | // Create users |
| 2797 | for i := 0; i < total; i++ { |
| 2798 | email := fmt.Sprintf("%d@coder.com", i) |
| 2799 | username := fmt.Sprintf("user%d", i) |
| 2800 | user, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{ |
| 2801 | Email: email, |
| 2802 | Username: username, |
| 2803 | Password: "MySecurePassword!", |
| 2804 | OrganizationIDs: []uuid.UUID{orgID}, |
| 2805 | }) |
| 2806 | require.NoError(t, err) |
| 2807 | users = append(users, user) |
| 2808 | } |
| 2809 | sortUsers(users) |
| 2810 | deletedUser := users[2] |
| 2811 | expected := users[3:8] |
| 2812 | _, err = client.UpdateUserStatus(ctx, deletedUser.ID.String(), codersdk.UserStatusSuspended) |
| 2813 | require.NoError(t, err, "suspend user") |
| 2814 | |
| 2815 | page, err := client.Users(ctx, codersdk.UsersRequest{ |
| 2816 | Pagination: codersdk.Pagination{ |
| 2817 | Limit: len(expected), |
| 2818 | AfterID: deletedUser.ID, |
| 2819 | }, |
| 2820 | }) |
| 2821 | require.NoError(t, err) |
| 2822 | require.Equal(t, expected, page.Users, "expected page") |
| 2823 | } |
| 2824 | |
| 2825 | func TestUserAutofillParameters(t *testing.T) { |
| 2826 | t.Parallel() |
nothing calls this directly
no test coverage detected