-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
b4b908a
commit a9cacf2
Showing
4 changed files
with
87 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Automattic\WooCommerce\Pinterest\Tests\Integration; | ||
|
||
use Automattic\WooCommerce\Pinterest\Feeds; | ||
use Automattic\WooCommerce\Pinterest\PinterestApiException; | ||
use Pinterest_For_Woocommerce; | ||
|
||
class FeedsTest extends \WP_UnitTestCase { | ||
|
||
/** | ||
* Tests emulates Pinterest create feed endpoint response when a feed with the same name already exists. | ||
* | ||
* @return void | ||
*/ | ||
public function test_feed_registration_handles_422_name_already_exists() | ||
{ | ||
$this->expectException( PinterestApiException::class ); | ||
$this->expectExceptionCode( 422 ); | ||
$this->expectExceptionMessage( 'Unprocessable Entity' ); | ||
|
||
Pinterest_For_Woocommerce::save_setting( 'tracking_advertiser', '123' ); | ||
Pinterest_For_Woocommerce::save_data( 'local_feed_ids', '' ); | ||
|
||
$this->create_feed_request_stub(); | ||
|
||
Feeds::create_feed(); | ||
} | ||
|
||
private function create_feed_request_stub() | ||
{ | ||
add_filter( | ||
'pre_http_request', | ||
function ($response, $parsed_args, $url) { | ||
if ('https://api.pinterest.com/v5/catalogs/feeds?ad_account_id=123' === $url) { | ||
$response = array( | ||
'headers' => array( | ||
'content-type' => 'application/json', | ||
), | ||
'body' => json_encode( | ||
array( | ||
'code' => 4170, | ||
'message' => 'Unprocessable Entity', | ||
) | ||
), | ||
'response' => array( | ||
'code' => 422, | ||
'message' => 'OK', | ||
), | ||
'cookies' => array(), | ||
'filename' => '', | ||
); | ||
} | ||
|
||
return $response; | ||
}, | ||
10, | ||
3 | ||
); | ||
} | ||
} |