@@ -15,7 +15,6 @@ public function setUp() {
1515
1616 // Create users.
1717 $ this ->shop_manager = $ this ->factory ->user ->create ( array ( 'role ' => 'shop_manager ' ) );
18- $ this ->simple_customer = $ this ->factory ->user ->create ( array ( 'role ' => 'customer ' ) );
1918
2019 // Setup helpers.
2120 $ this ->coupons = $ this ->getModule ('\Helper\Wpunit ' )->coupon ();
@@ -127,7 +126,6 @@ function( $key_a, $key_b ) {
127126 $ this ->assertEquals ( $ expected , $ actual );
128127 }
129128
130- // tests
131129 public function testProductsPagination () {
132130 $ products = array (
133131 $ this ->products ->create_simple (),
@@ -220,7 +218,6 @@ function( $key_a, $key_b ) {
220218 $ this ->assertEquals ( $ expected , $ actual );
221219 }
222220
223- // tests
224221 public function testOrdersPagination () {
225222 $ orders = array (
226223 $ this ->orders ->create (),
@@ -315,7 +312,6 @@ function( $key_a, $key_b ) {
315312 $ this ->assertEquals ( $ expected , $ actual );
316313 }
317314
318- // tests
319315 public function testRefundsPagination () {
320316 $ order = $ this ->orders ->create ();
321317 $ refunds = array (
@@ -410,4 +406,98 @@ function( $key_a, $key_b ) {
410406
411407 $ this ->assertEquals ( $ expected , $ actual );
412408 }
409+
410+ public function testCustomersPagination () {
411+ $ customers = array (
412+ $ this ->customers ->create (),
413+ $ this ->customers ->create (),
414+ $ this ->customers ->create (),
415+ $ this ->customers ->create (),
416+ $ this ->customers ->create (),
417+ );
418+
419+ usort (
420+ $ customers ,
421+ function ( $ key_a , $ key_b ) {
422+ return $ key_a < $ key_b ;
423+ }
424+ );
425+
426+ $ query = '
427+ query ($first: Int, $last: Int, $after: String, $before: String) {
428+ customers(first: $first, last: $last, after: $after, before: $before) {
429+ nodes {
430+ id
431+ }
432+ pageInfo {
433+ hasPreviousPage
434+ hasNextPage
435+ startCursor
436+ endCursor
437+ }
438+ }
439+ }
440+ ' ;
441+
442+ wp_set_current_user ( $ this ->shop_manager );
443+
444+ /**
445+ * Assertion One
446+ *
447+ * Test "first" parameter.
448+ */
449+ $ variables = array ( 'first ' => 2 );
450+ $ results = graphql (
451+ array (
452+ 'query ' => $ query ,
453+ 'variables ' => $ variables ,
454+ )
455+ );
456+
457+ // use --debug flag to view.
458+ codecept_debug ( $ results );
459+
460+ // Check pageInfo.
461+ $ this ->assertNotEmpty ( $ results ['data ' ] );
462+ $ this ->assertNotEmpty ( $ results ['data ' ]['customers ' ] );
463+ $ this ->assertNotEmpty ( $ results ['data ' ]['customers ' ]['pageInfo ' ] );
464+ $ this ->assertTrue ( $ results ['data ' ]['customers ' ]['pageInfo ' ]['hasNextPage ' ] );
465+ $ this ->assertNotEmpty ( $ results ['data ' ]['customers ' ]['pageInfo ' ]['endCursor ' ] );
466+ $ end_cursor = $ results ['data ' ]['customers ' ]['pageInfo ' ]['endCursor ' ];
467+
468+ // Check customers.
469+ $ actual = $ results ['data ' ]['customers ' ]['nodes ' ];
470+ $ expected = $ this ->customers ->print_nodes ( array_slice ( $ customers , 0 , 2 ) );
471+
472+ $ this ->assertEquals ( $ expected , $ actual );
473+
474+ /**
475+ * Assertion Two
476+ *
477+ * Test "after" parameter.
478+ */
479+ $ variables = array ( 'first ' => 3 , 'after ' => $ end_cursor );
480+ $ results = graphql (
481+ array (
482+ 'query ' => $ query ,
483+ 'variables ' => $ variables ,
484+ )
485+ );
486+
487+ // use --debug flag to view.
488+ codecept_debug ( $ results );
489+
490+ // Check pageInfo.
491+ $ this ->assertNotEmpty ( $ results ['data ' ] );
492+ $ this ->assertNotEmpty ( $ results ['data ' ]['customers ' ] );
493+ $ this ->assertNotEmpty ( $ results ['data ' ]['customers ' ]['pageInfo ' ] );
494+ $ this ->assertFalse ( $ results ['data ' ]['customers ' ]['pageInfo ' ]['hasNextPage ' ] );
495+ $ this ->assertNotEmpty ( $ results ['data ' ]['customers ' ]['pageInfo ' ]['endCursor ' ] );
496+
497+ // Check customers.
498+ $ actual = $ results ['data ' ]['customers ' ]['nodes ' ];
499+ $ expected = $ this ->customers ->print_nodes ( array_slice ( $ customers , 2 , 3 ) );
500+
501+ $ this ->assertEquals ( $ expected , $ actual );
502+ }
413503}
0 commit comments