Skip to content

Commit

Permalink
Improve user list pagination integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzkocer committed Nov 5, 2024
1 parent 60652b1 commit 4f58cd9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ class UsersEndpointTest {
requestBuilder.users().listWithEditContext(params = UserListParams(perPage = 1u))
}.assertSuccessAndRetrieveData()
assert(firstPageResponse.data.isNotEmpty())
val secondPageResponse = client.request { requestBuilder ->
val nextPageResponse = client.request { requestBuilder ->
requestBuilder.users().listWithEditContext(firstPageResponse.nextPageParams!!)
}.assertSuccessAndRetrieveData()
assert(secondPageResponse.data.isNotEmpty())
assert(nextPageResponse.data.isNotEmpty())
val prevPageResponse = client.request { requestBuilder ->
requestBuilder.users().listWithEditContext(nextPageResponse.prevPageParams!!)
}.assertSuccessAndRetrieveData()
assert(prevPageResponse.data.isNotEmpty())
}
}
73 changes: 29 additions & 44 deletions wp_api_integration_tests/tests/test_users_immut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,6 @@ async fn list_users_with_edit_context(#[case] params: UserListParams) {
.assert_response();
}

#[tokio::test]
#[parallel]
#[ignore]
async fn paginate_list_users_with_edit_context() {
let first_page_response = api_client()
.users()
.list_with_edit_context(&UserListParams {
per_page: Some(1),
..Default::default()
})
.await
.assert_response();
let second_page_params = first_page_response.next_page_params.unwrap();
println!(
"first_page_data: {:#?}",
first_page_response
.data
.into_iter()
.map(|u| u.id)
.collect::<Vec<UserId>>()
);
println!("second_page_params: {:#?}", second_page_params);
let second_page_response = api_client()
.users()
.list_with_edit_context(&second_page_params)
.await
.assert_response();
let first_page_params_from_second_response = second_page_response.prev_page_params.unwrap();
let third_page_params = second_page_response.next_page_params.unwrap();
println!(
"second_page_data: {:#?}",
second_page_response
.data
.into_iter()
.map(|u| u.id)
.collect::<Vec<UserId>>()
);
println!("third_page_params: {:#?}", third_page_params);
println!(
"first_page_params_from_second_response: {:#?}",
first_page_params_from_second_response
);
}

#[apply(list_users_cases)]
#[tokio::test]
#[parallel]
Expand Down Expand Up @@ -226,6 +182,35 @@ async fn retrieve_me_with_view_context() {
assert_eq!(FIRST_USER_ID, user.id);
}

#[tokio::test]
#[rstest]
#[parallel]
#[case(UserListParams { per_page: Some(1), ..Default::default() })]
#[case(UserListParams { per_page: Some(1), order: Some(WpApiParamOrder::Desc), ..Default::default() })]
#[case(UserListParams { per_page: Some(1), orderby: Some(WpApiParamUsersOrderBy::Email), ..Default::default() })]
async fn paginate_list_users_with_edit_context(#[case] params: UserListParams) {
let first_page_response = api_client()
.users()
.list_with_edit_context(&params)
.await
.assert_response();
assert!(!first_page_response.data.is_empty());
let next_page_params = first_page_response.next_page_params.unwrap();
let next_page_response = api_client()
.users()
.list_with_edit_context(&next_page_params)
.await
.assert_response();
assert!(!next_page_response.data.is_empty());
let prev_page_params = next_page_response.prev_page_params.unwrap();
let prev_page_response = api_client()
.users()
.list_with_edit_context(&prev_page_params)
.await
.assert_response();
assert!(!prev_page_response.data.is_empty());
}

#[template]
#[rstest]
#[case(None)]
Expand Down

0 comments on commit 4f58cd9

Please sign in to comment.