From 009ec0d8fc16d51cd0403e516757083db29ba930 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Thu, 4 Jul 2024 10:15:51 +0200 Subject: [PATCH 1/8] Add track evens when revoking token --- src/API/WP/OAuthService.php | 42 +++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/API/WP/OAuthService.php b/src/API/WP/OAuthService.php index 7773366ce8..c67aa06111 100644 --- a/src/API/WP/OAuthService.php +++ b/src/API/WP/OAuthService.php @@ -159,16 +159,54 @@ public function revoke_wpcom_api_auth(): string { $request = $this->container->get( Jetpack::class )->remote_request( $args ); if ( is_wp_error( $request ) ) { + + /** + * @event revoke_wpcom_api_auth + */ + do_action( + 'woocommerce_gla_track_event', + 'revoke_wpcom_api_auth', + [ + 'status' => 'error', + 'error' => $request->get_error_message(), + ] + ); + throw new Exception( $request->get_error_message(), 400 ); } else { $body = wp_remote_retrieve_body( $request ); $status = wp_remote_retrieve_response_code( $request ); if ( ! $status || $status !== 200 ) { - $data = json_decode( $body, true ); - throw new Exception( $data['message'] ?? 'Error revoking access to WPCOM.', $status ); + $data = json_decode( $body, true ); + $message = $data['message'] ?? 'Error revoking access to WPCOM.'; + + /** + * @event revoke_wpcom_api_auth + */ + do_action( + 'woocommerce_gla_track_event', + 'revoke_wpcom_api_auth', + [ + 'status' => $status, + 'error' => $message, + ] + ); + + throw new Exception( $message, $status ); } + /** + * @event revoke_wpcom_api_auth + */ + do_action( + 'woocommerce_gla_track_event', + 'revoke_wpcom_api_auth', + [ + 'status' => 200, + ] + ); + $this->container->get( AccountService::class )->reset_wpcom_api_authorization_data(); return $body; } From 5388e061c7b05360694fefe6e36440a4d58b8877 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Thu, 4 Jul 2024 10:16:11 +0200 Subject: [PATCH 2/8] Add tests when revoking token --- tests/Unit/API/WP/OAuthServiceTest.php | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/Unit/API/WP/OAuthServiceTest.php b/tests/Unit/API/WP/OAuthServiceTest.php index 40e8fb342e..a5adfce8c4 100644 --- a/tests/Unit/API/WP/OAuthServiceTest.php +++ b/tests/Unit/API/WP/OAuthServiceTest.php @@ -12,6 +12,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Infrastructure\Deactivateable; use Automattic\WooCommerce\GoogleListingsAndAds\Proxies\Jetpack; use Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter\AccountService; +use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\TrackingTrait; use PHPUnit\Framework\MockObject\MockObject; use WP_Error; use Exception; @@ -25,6 +26,7 @@ */ class OAuthServiceTest extends UnitTest { + use TrackingTrait; use UtilitiesTrait; /** @@ -202,4 +204,85 @@ public function test_get_auth_url() { $parsed_state['store_url'] ); } + + public function test_revoke_wpcom_api_auth() { + $this->jp->expects( $this->once() ) + ->method( 'remote_request' ) + ->willReturn( + [ + 'body' => '{"success":true}', + 'response' => [ 'code' => 200 ], + ] + ); + + $this->account_service->expects( $this->once() ) + ->method( 'reset_wpcom_api_authorization_data' ); + + $this->account_service->expects( $this->once() ) + ->method( 'reset_wpcom_api_authorization_data' ); + + $this->expect_track_event( + 'revoke_wpcom_api_auth', + [ + 'status' => 200, + ] + ); + + $response = $this->service->revoke_wpcom_api_auth(); + + $this->assertEquals( '{"success":true}', $response ); + } + + public function test_revoke_wpcom_api_auth_wp_error() { + $this->jp->expects( $this->once() ) + ->method( 'remote_request' ) + ->willReturn( + new WP_Error( 'error', 'error message' ) + ); + + $this->expectException( Exception::class ); + $this->expectExceptionMessage( 'error message' ); + $this->expectExceptionCode( 400 ); + + $this->account_service->expects( $this->never() ) + ->method( 'reset_wpcom_api_authorization_data' ); + + $this->expect_track_event( + 'revoke_wpcom_api_auth', + [ + 'status' => 'error', + 'error' => 'error message', + ] + ); + + $this->service->revoke_wpcom_api_auth(); + } + + public function test_revoke_wpcom_api_auth_status_error() { + $this->jp->expects( $this->once() ) + ->method( 'remote_request' ) + ->willReturn( + [ + 'body' => '{"message":"error message"}', + 'response' => [ 'code' => 400 ], + ] + ); + + $this->expectException( Exception::class ); + $this->expectExceptionMessage( 'error message' ); + $this->expectExceptionCode( 400 ); + + $this->account_service->expects( $this->never() ) + ->method( 'reset_wpcom_api_authorization_data' ); + + $this->expect_track_event( + 'revoke_wpcom_api_auth', + [ + 'status' => 400, + 'error' => 'error message', + ] + ); + + $this->service->revoke_wpcom_api_auth(); + } } From db27c06711a86dd0462dfe2874041c08adee5ac2 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Thu, 4 Jul 2024 10:16:32 +0200 Subject: [PATCH 3/8] Add track evens when updating Auth status --- src/MerchantCenter/AccountService.php | 62 +++++++++++++++++++-------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/src/MerchantCenter/AccountService.php b/src/MerchantCenter/AccountService.php index d42fad3f8e..451b08eae7 100644 --- a/src/MerchantCenter/AccountService.php +++ b/src/MerchantCenter/AccountService.php @@ -551,28 +551,56 @@ public function reset_wpcom_api_authorization_data(): bool { * @throws ExceptionWithResponseData If the stored nonce / nonce from query param is not provided, or the nonces mismatch. */ public function update_wpcom_api_authorization( string $status, string $nonce ): bool { - $stored_nonce = $this->options->get( OptionsInterface::GOOGLE_WPCOM_AUTH_NONCE ); - if ( empty( $stored_nonce ) ) { - throw $this->prepare_exception( - __( 'No stored nonce found in the database, skip updating auth status.', 'google-listings-and-ads' ) - ); - } + try { + $stored_nonce = $this->options->get( OptionsInterface::GOOGLE_WPCOM_AUTH_NONCE ); + if ( empty( $stored_nonce ) ) { + throw $this->prepare_exception( + __( 'No stored nonce found in the database, skip updating auth status.', 'google-listings-and-ads' ) + ); + } - if ( empty( $nonce ) ) { - throw $this->prepare_exception( - __( 'Nonce is not provided, skip updating auth status.', 'google-listings-and-ads' ) - ); - } + if ( empty( $nonce ) ) { + throw $this->prepare_exception( + __( 'Nonce is not provided, skip updating auth status.', 'google-listings-and-ads' ) + ); + } + + if ( $stored_nonce !== $nonce ) { + $this->delete_wpcom_api_auth_nonce(); + throw $this->prepare_exception( + __( 'Nonces mismatch, skip updating auth status.', 'google-listings-and-ads' ) + ); + } - if ( $stored_nonce !== $nonce ) { $this->delete_wpcom_api_auth_nonce(); - throw $this->prepare_exception( - __( 'Nonces mismatch, skip updating auth status.', 'google-listings-and-ads' ) + + /** + * @event update_wpcom_api_authorization + */ + do_action( + 'woocommerce_gla_track_event', + 'update_wpcom_api_authorization', + [ + 'status' => $status, + ] ); - } - $this->delete_wpcom_api_auth_nonce(); - return $this->options->update( OptionsInterface::WPCOM_REST_API_STATUS, $status ); + return $this->options->update( OptionsInterface::WPCOM_REST_API_STATUS, $status ); + } catch ( ExceptionWithResponseData $e ) { + + /** + * @event update_wpcom_api_authorization + */ + do_action( + 'woocommerce_gla_track_event', + 'update_wpcom_api_authorization', + [ + 'status' => $e->getMessage(), + ] + ); + + throw $e; + } } /** From 792ef218fb28ceee23fdefdaffc63fccba56d68a Mon Sep 17 00:00:00 2001 From: Jorge M Date: Thu, 4 Jul 2024 10:16:42 +0200 Subject: [PATCH 4/8] Adjust test --- .../MerchantCenter/AccountServiceTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Unit/MerchantCenter/AccountServiceTest.php b/tests/Unit/MerchantCenter/AccountServiceTest.php index 94bc333d6b..08e687640a 100644 --- a/tests/Unit/MerchantCenter/AccountServiceTest.php +++ b/tests/Unit/MerchantCenter/AccountServiceTest.php @@ -24,6 +24,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Framework\UnitTest; use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\MerchantTrait; use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\League\Container\Container; +use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\TrackingTrait; use Exception; use PHPUnit\Framework\MockObject\MockObject; @@ -37,6 +38,7 @@ */ class AccountServiceTest extends UnitTest { + use TrackingTrait; use MerchantTrait; /** @var MockObject|Ads $ads */ @@ -877,6 +879,13 @@ public function test_update_wpcom_api_authorization() { ->method( 'delete' ) ->with( OptionsInterface::GOOGLE_WPCOM_AUTH_NONCE ); + $this->expect_track_event( + 'update_wpcom_api_authorization', + [ + 'status' => 'approved', + ] + ); + $this->account->update_wpcom_api_authorization( $status, $nonce ); } @@ -897,6 +906,13 @@ public function test_update_wpcom_api_authorization_nonce_not_provided() { $this->expectException( ExceptionWithResponseData::class ); $this->expectExceptionMessage( 'Nonce is not provided, skip updating auth status.' ); + $this->expect_track_event( + 'update_wpcom_api_authorization', + [ + 'status' => 'Nonce is not provided, skip updating auth status.', + ] + ); + $this->account->update_wpcom_api_authorization( $status, $nonce ); } @@ -917,6 +933,13 @@ public function test_update_wpcom_api_authorization_stored_nonce_not_in_db() { $this->expectException( ExceptionWithResponseData::class ); $this->expectExceptionMessage( 'No stored nonce found in the database, skip updating auth status.' ); + $this->expect_track_event( + 'update_wpcom_api_authorization', + [ + 'status' => 'No stored nonce found in the database, skip updating auth status.', + ] + ); + $this->account->update_wpcom_api_authorization( $status, $nonce ); } @@ -938,6 +961,13 @@ public function test_update_wpcom_api_authorization_nonces_mismatch() { $this->expectException( ExceptionWithResponseData::class ); $this->expectExceptionMessage( 'Nonces mismatch, skip updating auth status.' ); + $this->expect_track_event( + 'update_wpcom_api_authorization', + [ + 'status' => 'Nonces mismatch, skip updating auth status.', + ] + ); + $this->account->update_wpcom_api_authorization( $status, $nonce ); } From be2876d7e329c11c693329c8a6e141faae8c1809 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Thu, 4 Jul 2024 22:04:18 +0200 Subject: [PATCH 5/8] Add blog_id tracking --- src/API/WP/OAuthService.php | 13 ++++++++----- src/MerchantCenter/AccountService.php | 7 +++++-- tests/Unit/API/WP/OAuthServiceTest.php | 14 +++++++++----- tests/Unit/MerchantCenter/AccountServiceTest.php | 13 +++++++++---- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/API/WP/OAuthService.php b/src/API/WP/OAuthService.php index c67aa06111..05db794342 100644 --- a/src/API/WP/OAuthService.php +++ b/src/API/WP/OAuthService.php @@ -167,8 +167,9 @@ public function revoke_wpcom_api_auth(): string { 'woocommerce_gla_track_event', 'revoke_wpcom_api_auth', [ - 'status' => 'error', - 'error' => $request->get_error_message(), + 'status' => 'error', + 'error' => $request->get_error_message(), + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); @@ -188,8 +189,9 @@ public function revoke_wpcom_api_auth(): string { 'woocommerce_gla_track_event', 'revoke_wpcom_api_auth', [ - 'status' => $status, - 'error' => $message, + 'status' => $status, + 'error' => $message, + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); @@ -203,7 +205,8 @@ public function revoke_wpcom_api_auth(): string { 'woocommerce_gla_track_event', 'revoke_wpcom_api_auth', [ - 'status' => 200, + 'status' => 200, + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); diff --git a/src/MerchantCenter/AccountService.php b/src/MerchantCenter/AccountService.php index 451b08eae7..60fcc8d5d1 100644 --- a/src/MerchantCenter/AccountService.php +++ b/src/MerchantCenter/AccountService.php @@ -24,6 +24,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\PluginHelper; use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Psr\Container\ContainerInterface; use Exception; +use Jetpack_Options; defined( 'ABSPATH' ) || exit; @@ -581,7 +582,8 @@ public function update_wpcom_api_authorization( string $status, string $nonce ): 'woocommerce_gla_track_event', 'update_wpcom_api_authorization', [ - 'status' => $status, + 'status' => $status, + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); @@ -595,7 +597,8 @@ public function update_wpcom_api_authorization( string $status, string $nonce ): 'woocommerce_gla_track_event', 'update_wpcom_api_authorization', [ - 'status' => $e->getMessage(), + 'status' => $e->getMessage(), + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); diff --git a/tests/Unit/API/WP/OAuthServiceTest.php b/tests/Unit/API/WP/OAuthServiceTest.php index a5adfce8c4..fbeb5b5f29 100644 --- a/tests/Unit/API/WP/OAuthServiceTest.php +++ b/tests/Unit/API/WP/OAuthServiceTest.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\MockObject\MockObject; use WP_Error; use Exception; +use Jetpack_Options; defined( 'ABSPATH' ) || exit; @@ -224,7 +225,8 @@ public function test_revoke_wpcom_api_auth() { $this->expect_track_event( 'revoke_wpcom_api_auth', [ - 'status' => 200, + 'status' => 200, + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); @@ -250,8 +252,9 @@ public function test_revoke_wpcom_api_auth_wp_error() { $this->expect_track_event( 'revoke_wpcom_api_auth', [ - 'status' => 'error', - 'error' => 'error message', + 'status' => 'error', + 'error' => 'error message', + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); @@ -278,8 +281,9 @@ public function test_revoke_wpcom_api_auth_status_error() { $this->expect_track_event( 'revoke_wpcom_api_auth', [ - 'status' => 400, - 'error' => 'error message', + 'status' => 400, + 'error' => 'error message', + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); diff --git a/tests/Unit/MerchantCenter/AccountServiceTest.php b/tests/Unit/MerchantCenter/AccountServiceTest.php index 08e687640a..12c2c7ca73 100644 --- a/tests/Unit/MerchantCenter/AccountServiceTest.php +++ b/tests/Unit/MerchantCenter/AccountServiceTest.php @@ -27,6 +27,7 @@ use Automattic\WooCommerce\GoogleListingsAndAds\Tests\Tools\HelperTrait\TrackingTrait; use Exception; use PHPUnit\Framework\MockObject\MockObject; +use Jetpack_Options; defined( 'ABSPATH' ) || exit; @@ -882,7 +883,8 @@ public function test_update_wpcom_api_authorization() { $this->expect_track_event( 'update_wpcom_api_authorization', [ - 'status' => 'approved', + 'status' => 'approved', + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); @@ -909,7 +911,8 @@ public function test_update_wpcom_api_authorization_nonce_not_provided() { $this->expect_track_event( 'update_wpcom_api_authorization', [ - 'status' => 'Nonce is not provided, skip updating auth status.', + 'status' => 'Nonce is not provided, skip updating auth status.', + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); @@ -936,7 +939,8 @@ public function test_update_wpcom_api_authorization_stored_nonce_not_in_db() { $this->expect_track_event( 'update_wpcom_api_authorization', [ - 'status' => 'No stored nonce found in the database, skip updating auth status.', + 'status' => 'No stored nonce found in the database, skip updating auth status.', + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); @@ -964,7 +968,8 @@ public function test_update_wpcom_api_authorization_nonces_mismatch() { $this->expect_track_event( 'update_wpcom_api_authorization', [ - 'status' => 'Nonces mismatch, skip updating auth status.', + 'status' => 'Nonces mismatch, skip updating auth status.', + 'blog_id' => Jetpack_Options::get_option( 'id' ), ] ); From fb8b49cf7b43daf59cac9f48b00d162d432c4943 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Sun, 7 Jul 2024 12:56:30 +0200 Subject: [PATCH 6/8] Add event property directives and descriptions --- src/API/WP/OAuthService.php | 28 ++++++++++++++++++++------ src/MerchantCenter/AccountService.php | 8 ++++++++ tests/Unit/API/WP/OAuthServiceTest.php | 6 +++--- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/API/WP/OAuthService.php b/src/API/WP/OAuthService.php index 05db794342..ec0da936c6 100644 --- a/src/API/WP/OAuthService.php +++ b/src/API/WP/OAuthService.php @@ -161,11 +161,16 @@ public function revoke_wpcom_api_auth(): string { if ( is_wp_error( $request ) ) { /** - * @event revoke_wpcom_api_auth + * When the WPCOM token has been revoked with errors. + * + * @event revoke_wpcom_api_authorization + * @property string status The status of the request. + * @property string error The error message. + * @property mixed blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', - 'revoke_wpcom_api_auth', + 'revoke_wpcom_api_authorization', [ 'status' => 'error', 'error' => $request->get_error_message(), @@ -183,11 +188,17 @@ public function revoke_wpcom_api_auth(): string { $message = $data['message'] ?? 'Error revoking access to WPCOM.'; /** - * @event revoke_wpcom_api_auth + * + * When the WPCOM token has been revoked with errors. + * + * @event revoke_wpcom_api_authorization + * @property string status The status of the request. + * @property string error The error message. + * @property mixed blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', - 'revoke_wpcom_api_auth', + 'revoke_wpcom_api_authorization', [ 'status' => $status, 'error' => $message, @@ -199,11 +210,16 @@ public function revoke_wpcom_api_auth(): string { } /** - * @event revoke_wpcom_api_auth + * When the WPCOM token has been revoked successfully. + * + * @event revoke_wpcom_api_authorization + * @property string status The status of the request. + * @property string error The error message. + * @property mixed blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', - 'revoke_wpcom_api_auth', + 'revoke_wpcom_api_authorization', [ 'status' => 200, 'blog_id' => Jetpack_Options::get_option( 'id' ), diff --git a/src/MerchantCenter/AccountService.php b/src/MerchantCenter/AccountService.php index 60fcc8d5d1..26665cb500 100644 --- a/src/MerchantCenter/AccountService.php +++ b/src/MerchantCenter/AccountService.php @@ -576,7 +576,11 @@ public function update_wpcom_api_authorization( string $status, string $nonce ): $this->delete_wpcom_api_auth_nonce(); /** + * When the WPCOM Authorization status has been updated. + * * @event update_wpcom_api_authorization + * @property string status The status of the request. + * @property string blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', @@ -591,7 +595,11 @@ public function update_wpcom_api_authorization( string $status, string $nonce ): } catch ( ExceptionWithResponseData $e ) { /** + * When the WPCOM Authorization status has been updated with errors. + * * @event update_wpcom_api_authorization + * @property string status The status of the request. + * @property string blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', diff --git a/tests/Unit/API/WP/OAuthServiceTest.php b/tests/Unit/API/WP/OAuthServiceTest.php index fbeb5b5f29..4c75f7cea5 100644 --- a/tests/Unit/API/WP/OAuthServiceTest.php +++ b/tests/Unit/API/WP/OAuthServiceTest.php @@ -223,7 +223,7 @@ public function test_revoke_wpcom_api_auth() { ->method( 'reset_wpcom_api_authorization_data' ); $this->expect_track_event( - 'revoke_wpcom_api_auth', + 'revoke_wpcom_api_authorization', [ 'status' => 200, 'blog_id' => Jetpack_Options::get_option( 'id' ), @@ -250,7 +250,7 @@ public function test_revoke_wpcom_api_auth_wp_error() { ->method( 'reset_wpcom_api_authorization_data' ); $this->expect_track_event( - 'revoke_wpcom_api_auth', + 'revoke_wpcom_api_authorization', [ 'status' => 'error', 'error' => 'error message', @@ -279,7 +279,7 @@ public function test_revoke_wpcom_api_auth_status_error() { ->method( 'reset_wpcom_api_authorization_data' ); $this->expect_track_event( - 'revoke_wpcom_api_auth', + 'revoke_wpcom_api_authorization', [ 'status' => 400, 'error' => 'error message', From 2171ce66f05df20e43e2f0e5cec177c02e2d4bc1 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Mon, 8 Jul 2024 11:59:55 +0200 Subject: [PATCH 7/8] Adjust event properties --- src/API/WP/OAuthService.php | 13 ++++++------- src/MerchantCenter/AccountService.php | 4 ++-- tests/Unit/API/WP/OAuthServiceTest.php | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/API/WP/OAuthService.php b/src/API/WP/OAuthService.php index ec0da936c6..0ce3c3ebf5 100644 --- a/src/API/WP/OAuthService.php +++ b/src/API/WP/OAuthService.php @@ -164,15 +164,15 @@ public function revoke_wpcom_api_auth(): string { * When the WPCOM token has been revoked with errors. * * @event revoke_wpcom_api_authorization - * @property string status The status of the request. + * @property int status The status of the request. * @property string error The error message. - * @property mixed blog_id The blog ID. + * @property int|null blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', 'revoke_wpcom_api_authorization', [ - 'status' => 'error', + 'status' => 400, 'error' => $request->get_error_message(), 'blog_id' => Jetpack_Options::get_option( 'id' ), ] @@ -192,9 +192,9 @@ public function revoke_wpcom_api_auth(): string { * When the WPCOM token has been revoked with errors. * * @event revoke_wpcom_api_authorization - * @property string status The status of the request. + * @property int status The status of the request. * @property string error The error message. - * @property mixed blog_id The blog ID. + * @property int|null blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', @@ -214,8 +214,7 @@ public function revoke_wpcom_api_auth(): string { * * @event revoke_wpcom_api_authorization * @property string status The status of the request. - * @property string error The error message. - * @property mixed blog_id The blog ID. + * @property int|null blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', diff --git a/src/MerchantCenter/AccountService.php b/src/MerchantCenter/AccountService.php index 26665cb500..6932f80259 100644 --- a/src/MerchantCenter/AccountService.php +++ b/src/MerchantCenter/AccountService.php @@ -580,7 +580,7 @@ public function update_wpcom_api_authorization( string $status, string $nonce ): * * @event update_wpcom_api_authorization * @property string status The status of the request. - * @property string blog_id The blog ID. + * @property int|null blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', @@ -599,7 +599,7 @@ public function update_wpcom_api_authorization( string $status, string $nonce ): * * @event update_wpcom_api_authorization * @property string status The status of the request. - * @property string blog_id The blog ID. + * @property int|null blog_id The blog ID. */ do_action( 'woocommerce_gla_track_event', diff --git a/tests/Unit/API/WP/OAuthServiceTest.php b/tests/Unit/API/WP/OAuthServiceTest.php index 4c75f7cea5..4eb0f584d4 100644 --- a/tests/Unit/API/WP/OAuthServiceTest.php +++ b/tests/Unit/API/WP/OAuthServiceTest.php @@ -252,7 +252,7 @@ public function test_revoke_wpcom_api_auth_wp_error() { $this->expect_track_event( 'revoke_wpcom_api_authorization', [ - 'status' => 'error', + 'status' => 400, 'error' => 'error message', 'blog_id' => Jetpack_Options::get_option( 'id' ), ] From e7be1cadbfc6fee36a71b206cd7ae4f6de06f621 Mon Sep 17 00:00:00 2001 From: Jorge M Date: Mon, 8 Jul 2024 16:10:20 +0200 Subject: [PATCH 8/8] Adjust event property --- src/API/WP/OAuthService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API/WP/OAuthService.php b/src/API/WP/OAuthService.php index 0ce3c3ebf5..49e7da2799 100644 --- a/src/API/WP/OAuthService.php +++ b/src/API/WP/OAuthService.php @@ -213,7 +213,7 @@ public function revoke_wpcom_api_auth(): string { * When the WPCOM token has been revoked successfully. * * @event revoke_wpcom_api_authorization - * @property string status The status of the request. + * @property int status The status of the request. * @property int|null blog_id The blog ID. */ do_action(