diff --git a/.generator/templates/private_key_test.go b/.generator/templates/private_key_test.go index 07efa613..08c6959f 100644 --- a/.generator/templates/private_key_test.go +++ b/.generator/templates/private_key_test.go @@ -1,6 +1,7 @@ package okta import ( + "io/ioutil" "os" "testing" @@ -86,3 +87,39 @@ func Test_Dpop_Get_User(t *testing.T) { err = cleanUpUser(user.GetId()) require.NoError(t, err, "Clean up user should not error") } + +func Test_Dpop_Pagination(t *testing.T) { + configuration, err := NewConfiguration(WithAuthorizationMode("PrivateKey"), WithScopes([]string{"okta.users.manage", "okta.users.read"})) + require.NoError(t, err, "Creating a new config should not error") + client := NewAPIClient(configuration) + uc := testFactory.NewValidTestUserCredentialsWithPassword() + profile := testFactory.NewValidTestUserProfile() + body := CreateUserRequest{Credentials: uc, Profile: profile} + createdUser1, _, err := client.UserAPI.CreateUser(client.cfg.Context).Body(body).Activate(true).Execute() + require.NoError(t, err, "Creating a new user should not error") + uc = testFactory.NewValidTestUserCredentialsWithPassword() + profile = testFactory.NewValidTestUserProfile() + body = CreateUserRequest{Credentials: uc, Profile: profile} + createdUser2, _, err := client.UserAPI.CreateUser(client.cfg.Context).Body(body).Activate(true).Execute() + require.NoError(t, err, "Creating a new user should not error") + user1, resp, err := client.UserAPI.ListUsers(client.cfg.Context).Limit(1).Execute() + require.NoError(t, err) + assert.Equal(t, 1, len(user1), "User1 did not return 1 user") + user1Profile := user1[0].GetProfile() + hasNext := resp.HasNextPage() + assert.True(t, hasNext, "Should return true for HasNextPage") + var user2 []User + res, err := resp.Next(&user2) + require.NoError(t, err) + respBody, err := ioutil.ReadAll(res.Body) + res.Body.Close() + require.NoError(t, err) + assert.NotEmpty(t, string(respBody), "body is empty") + assert.Equal(t, 1, len(user2), "User2 did not return 1 user") + user2Profile := user2[0].GetProfile() + assert.NotEqual(t, user2Profile.GetEmail(), user1Profile.GetEmail(), "Emails should not be the same") + err = cleanUpUser(createdUser1.GetId()) + require.NoError(t, err, "Should not error when deactivating") + err = cleanUpUser(createdUser2.GetId()) + require.NoError(t, err, "Should not error when deactivating") +} diff --git a/.generator/templates/response.mustache b/.generator/templates/response.mustache index a2fc0fb6..e9336148 100644 --- a/.generator/templates/response.mustache +++ b/.generator/templates/response.mustache @@ -108,7 +108,11 @@ func (res *APIResponse) Next(v interface{}) (*APIResponse, error) { if res.cli == nil { return nil, errors.New("no initial response provided from previous request") } - req, err := res.cli.prepareRequest(res.cli.cfg.Context, res.NextPage(), http.MethodGet, nil, map[string]string{"Accept": "application/json"},nil, nil, nil) + URL, err := url.Parse(res.NextPage()) + if err != nil { + return nil, err + } + req, err := res.cli.prepareRequest(res.cli.cfg.Context, URL.Path, http.MethodGet, nil, map[string]string{"Accept": "application/json"}, URL.Query(), nil, nil) if err != nil { return nil, err }