diff --git a/.github/workflows/post-release-updates.yml b/.github/workflows/post-release-updates.yml index 813c9fd0bc1..bb9a1ef1175 100644 --- a/.github/workflows/post-release-updates.yml +++ b/.github/workflows/post-release-updates.yml @@ -155,8 +155,10 @@ jobs: echo ":warning: File "$NEXT_RELEASE_VERSION_INSTRUCTIONS_FILENAME.md" already exists. No action needed." >> $GITHUB_STEP_SUMMARY fi - # If an entry for the next version doesn't exist yet + # Check if this release version exists in Release-testing-instructions.md if ! grep -q "v$NEXT_RELEASE_VERSION" Release-testing-instructions.md; then + # If it doesn't exist, remove all trailing newlines and add the new version for this release + perl -pi -e 'BEGIN{undef $/;} s/\n+\z//' Release-testing-instructions.md echo -ne "\n* [v$NEXT_RELEASE_VERSION](https://github.com/Automattic/woocommerce-payments/wiki/$NEXT_RELEASE_VERSION_INSTRUCTIONS_FILENAME)" >> Release-testing-instructions.md echo "Added a new entry for v$NEXT_RELEASE_VERSION in \"Release-testing-instructions.md\"." >> $GITHUB_STEP_SUMMARY HAS_CHANGES=true diff --git a/changelog/fix-5151-fraud-outcome-type-error b/changelog/fix-5151-fraud-outcome-type-error new file mode 100644 index 00000000000..43dcb1cf8c4 --- /dev/null +++ b/changelog/fix-5151-fraud-outcome-type-error @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix type error for fraud outcome API. diff --git a/changelog/update-post-release-updates b/changelog/update-post-release-updates new file mode 100644 index 00000000000..83360bae0a3 --- /dev/null +++ b/changelog/update-post-release-updates @@ -0,0 +1,5 @@ +Significance: patch +Type: dev +Comment: Just a minor change in a GitHub Actions workflow to make it more robust. + + diff --git a/includes/core/server/request/class-list-fraud-outcome-transactions.php b/includes/core/server/request/class-list-fraud-outcome-transactions.php index d7d3770c7c5..4d01cff2666 100644 --- a/includes/core/server/request/class-list-fraud-outcome-transactions.php +++ b/includes/core/server/request/class-list-fraud-outcome-transactions.php @@ -11,6 +11,7 @@ use WC_Payments_Utils; use WC_Payments_API_Client; use WCPay\Constants\Fraud_Meta_Box_Type; +use WCPay\Fraud_Prevention\Models\Rule; /** * Request class for getting intents. @@ -37,6 +38,10 @@ class List_Fraud_Outcome_Transactions extends Paginated { * @throws Invalid_Request_Parameter_Exception */ public function get_api(): string { + $status = $this->status ?? 'null'; + if ( ! Rule::is_valid_fraud_outcome_status( $status ) ) { + throw new Invalid_Request_Parameter_Exception( "Invalid fraud outcome status provided: $status", 'invalid_fraud_outcome_status' ); + } return WC_Payments_API_Client::FRAUD_OUTCOMES_API . '/status/' . $this->status; } diff --git a/tests/unit/core/server/request/test-class-list-fraud-outcome-transactions-request.php b/tests/unit/core/server/request/test-class-list-fraud-outcome-transactions-request.php index 2e08bf04425..9a77afb8537 100644 --- a/tests/unit/core/server/request/test-class-list-fraud-outcome-transactions-request.php +++ b/tests/unit/core/server/request/test-class-list-fraud-outcome-transactions-request.php @@ -6,6 +6,7 @@ */ use PHPUnit\Framework\MockObject\MockObject; +use WCPay\Core\Exceptions\Server\Request\Invalid_Request_Parameter_Exception; use WCPay\Core\Server\Request\List_Fraud_Outcome_Transactions; /** @@ -68,6 +69,7 @@ public function test_list_fraud_outcome_transactions_request() { $this->assertSame( 'GET', $request->get_method() ); $this->assertSame( WC_Payments_API_Client::FRAUD_OUTCOMES_API . '/status/' . $status, $request->get_api() ); } + public function test_list_fraud_outcome_transactions_request_using_from_rest_request_function() { $page = 2; $page_size = 50; @@ -569,4 +571,29 @@ public function test_list_fraud_outcome_transactions_request_filters_out_non_blo $this->assertEquals( $expected, $result ); } + + /** + * Checks to see if the get_api method throws an exception if an invalid status is passed. + * + * @param ?string $status The status to check. + * + * @return void + * + * @dataProvider provider_get_api_exception_on_invalid_status + */ + public function test_get_api_exception_on_invalid_status( $status ): void { + $request = new List_Fraud_Outcome_Transactions( $this->mock_api_client, $this->mock_wc_payments_http_client ); + $request->set_status( $status ); + + $status = $status ?? 'null'; + + $this->expectException( Invalid_Request_Parameter_Exception::class ); + $this->expectExceptionMessage( "Invalid fraud outcome status provided: $status" ); + + $request->get_api(); + } + + public function provider_get_api_exception_on_invalid_status(): array { + return [ [ 'invalid' ], [ null ] ]; + } }