Add extra verification to import cancel endpoint test.

This commit is contained in:
Jeff Stieler 2019-04-30 10:38:07 -06:00
parent 61492c5f10
commit f9c1b130c3
2 changed files with 21 additions and 12 deletions

View File

@ -202,6 +202,10 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
$order->set_date_created( time() - ( 3 * DAY_IN_SECONDS ) );
$order->save();
// Verify there are actions to cancel.
$pending_actions = WC_Helper_Queue::get_all_pending();
$this->assertCount( 1, $pending_actions );
// Cancel outstanding actions.
$request = new WP_REST_Request( 'POST', $this->endpoint . '/cancel' );
$response = $this->server->dispatch( $request );
@ -209,15 +213,9 @@ class WC_Tests_API_Reports_Import extends WC_REST_Unit_Test_Case {
$this->assertEquals( 200, $response->get_status() );
$this->assertEquals( 'success', $report['status'] );
WC_Helper_Queue::run_all_pending();
// @todo It may be better to compare against outstanding actions
// pulled from the import API once #1850 is complete.
$request = new WP_REST_Request( 'GET', '/wc/v4/reports/orders' );
$response = $this->server->dispatch( $request );
$reports = $response->get_data();
$this->assertEquals( 200, $response->get_status() );
$this->assertCount( 0, $reports );
// Verify there are no pending actions.
$pending_actions = WC_Helper_Queue::get_all_pending();
$this->assertCount( 0, $pending_actions );
}
}

View File

@ -12,11 +12,11 @@
*/
class WC_Helper_Queue {
/**
* Run all pending queued actions.
* Get all pending queued actions.
*
* @return void
* @return array Pending jobs.
*/
public static function run_all_pending() {
public static function get_all_pending() {
$jobs = WC()->queue()->search(
array(
'per_page' => -1,
@ -25,6 +25,17 @@ class WC_Helper_Queue {
)
);
return $jobs;
}
/**
* Run all pending queued actions.
*
* @return void
*/
public static function run_all_pending() {
$jobs = self::get_all_pending();
foreach ( $jobs as $job ) {
$job->execute();
}