-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
152 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,15 +140,15 @@ public function test_orderby_first_name(): void { | |
// Order by 'first_name' ascending | ||
$request = $this->wp_rest_get_request('/wcpos/v1/customers'); | ||
$request->set_query_params( array( 'orderby' => 'first_name', 'order' => 'asc' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$first_names = wp_list_pluck( $data, 'first_name' ); | ||
|
||
$this->assertEquals( $first_names, array( 'Alice', 'Bob', 'Zara' ) ); | ||
|
||
// reverse order | ||
$request->set_query_params( array( 'orderby' => 'first_name', 'order' => 'desc' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$first_names = wp_list_pluck( $data, 'first_name' ); | ||
|
||
|
@@ -164,15 +164,15 @@ public function test_orderby_last_name(): void { | |
// Order by 'last_name' ascending | ||
$request = $this->wp_rest_get_request('/wcpos/v1/customers'); | ||
$request->set_query_params( array( 'orderby' => 'last_name', 'order' => 'asc' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$last_names = wp_list_pluck( $data, 'last_name' ); | ||
|
||
$this->assertEquals( $last_names, array( 'Anderson', 'Martinez', 'Thompson' ) ); | ||
|
||
// reverse order | ||
$request->set_query_params( array( 'orderby' => 'last_name', 'order' => 'desc' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$last_names = wp_list_pluck( $data, 'last_name' ); | ||
|
||
|
@@ -188,21 +188,26 @@ public function test_orderby_email(): void { | |
// Order by 'email' ascending | ||
$request = $this->wp_rest_get_request('/wcpos/v1/customers'); | ||
$request->set_query_params( array( 'orderby' => 'email', 'order' => 'asc' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$emails = wp_list_pluck( $data, 'email' ); | ||
|
||
$this->assertEquals( $emails, array( '[email protected]', '[email protected]', '[email protected]' ) ); | ||
|
||
// reverse order | ||
$request->set_query_params( array( 'orderby' => 'email', 'order' => 'desc' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$emails = wp_list_pluck( $data, 'email' ); | ||
|
||
$this->assertEquals( $emails, array( '[email protected]', '[email protected]', '[email protected]' ) ); | ||
} | ||
|
||
/** | ||
* TODO - wp_capabilities is an array, so orderby doesn't work. | ||
* | ||
* - either find a way or remove the option to order by role | ||
*/ | ||
public function test_orderby_role(): void { | ||
// Create some customers | ||
$customer1 = CustomerHelper::create_customer(array('role' => 'administrator')); | ||
|
@@ -212,7 +217,7 @@ public function test_orderby_role(): void { | |
// Order by 'role' ascending | ||
$request = $this->wp_rest_get_request('/wcpos/v1/customers'); | ||
$request->set_query_params( array( 'orderby' => 'role', 'order' => 'asc', 'role' => 'all' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$roles = wp_list_pluck( $data, 'role' ); | ||
|
||
|
@@ -224,7 +229,7 @@ public function test_orderby_role(): void { | |
|
||
// reverse order | ||
$request->set_query_params( array( 'orderby' => 'role', 'order' => 'desc', 'role' => 'all' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$roles = wp_list_pluck( $data, 'role' ); | ||
|
||
|
@@ -244,7 +249,7 @@ public function test_orderby_username(): void { | |
// Order by 'username' ascending | ||
$request = $this->wp_rest_get_request('/wcpos/v1/customers'); | ||
$request->set_query_params( array( 'orderby' => 'username', 'order' => 'asc' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$usernames = wp_list_pluck( $data, 'username' ); | ||
|
||
|
@@ -255,7 +260,7 @@ public function test_orderby_username(): void { | |
|
||
// reverse order | ||
$request->set_query_params( array( 'orderby' => 'username', 'order' => 'desc' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$usernames = wp_list_pluck( $data, 'username' ); | ||
|
||
|
@@ -294,78 +299,78 @@ public function test_customer_search(): void { | |
|
||
// empty search | ||
$request->set_query_params( array( 'search' => '' ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 9, \count( $data ) ); | ||
|
||
// search for first_name | ||
$request->set_query_params( array( 'search' => $random_first_name ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
$this->assertEquals( $customer1->get_id(), $data[0]['id'] ); | ||
|
||
// search for last_name | ||
$request->set_query_params( array( 'search' => $random_last_name ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
$this->assertEquals( $customer2->get_id(), $data[0]['id'] ); | ||
|
||
// search for email | ||
$request->set_query_params( array( 'search' => $random_email ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
$this->assertEquals( $customer3->get_id(), $data[0]['id'] ); | ||
|
||
// search for username | ||
$request->set_query_params( array( 'search' => $random_username ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
$this->assertEquals( $customer4->get_id(), $data[0]['id'] ); | ||
|
||
// search for billing_first_name | ||
$request->set_query_params( array( 'search' => $random_billing_first_name ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
$this->assertEquals( $customer5->get_id(), $data[0]['id'] ); | ||
|
||
// search for billing_last_name | ||
$request->set_query_params( array( 'search' => $random_billing_last_name ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
$this->assertEquals( $customer6->get_id(), $data[0]['id'] ); | ||
|
||
// search for billing_last_name | ||
$request->set_query_params( array( 'search' => $random_billing_email ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
$this->assertEquals( $customer7->get_id(), $data[0]['id'] ); | ||
|
||
// search for billing_company | ||
$request->set_query_params( array( 'search' => $random_billing_company ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
$this->assertEquals( $customer8->get_id(), $data[0]['id'] ); | ||
|
||
// search for billing_last_name | ||
$request->set_query_params( array( 'search' => $random_billing_phone ) ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals(200, $response->get_status()); | ||
$this->assertEquals( 1, \count( $data ) ); | ||
|
@@ -385,7 +390,7 @@ public function test_create_customer(): void { | |
'password' => '', | ||
) | ||
); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
// print_r($data); | ||
|
||
|
@@ -404,15 +409,15 @@ public function test_update_customer(): void { | |
); | ||
|
||
$request = $this->wp_rest_get_request('/wcpos/v1/customers/' . $customer->get_id() ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$this->assertEquals( 200, $response->get_status() ); | ||
$this->assertEquals( 'Sarah', $data['first_name'] ); | ||
|
||
$request = $this->wp_rest_post_request('/wcpos/v1/customers/' . $customer->get_id() ); | ||
$data['first_name'] = 'Jane'; | ||
$request->set_body_params($data); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$response = $this->server->dispatch( $request ); | ||
$data = $response->get_data(); | ||
|
||
$this->assertEquals( 200, $response->get_status() ); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.