From 0357eea34c004126b261ea950de51748c1d01b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 1 Mar 2024 15:45:51 +0100 Subject: [PATCH] Closes #6438: Adapt the URL for the job so the SaaS uses the correct one (#6455) --- .../JobManager/APIHandler/APIClient.php | 2 +- .../Database/Queries/UsedCSS/createNewJob.php | 7 +- .../RUCSS/Frontend/APIClient/addToQueue.php | 74 +++++++++++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/inc/Engine/Common/JobManager/APIHandler/APIClient.php b/inc/Engine/Common/JobManager/APIHandler/APIClient.php index de4bec1bff..2591dd0363 100644 --- a/inc/Engine/Common/JobManager/APIHandler/APIClient.php +++ b/inc/Engine/Common/JobManager/APIHandler/APIClient.php @@ -44,7 +44,7 @@ public function add_to_queue( string $url, array $options ): array { 'nowprocket' => 1, 'no_optimize' => 1, ], - $url + user_trailingslashit( $url ) ), 'config' => $options, ], diff --git a/tests/Fixtures/inc/Engine/Optimization/RUCSS/Database/Queries/UsedCSS/createNewJob.php b/tests/Fixtures/inc/Engine/Optimization/RUCSS/Database/Queries/UsedCSS/createNewJob.php index 3567644db8..8084bbac6f 100644 --- a/tests/Fixtures/inc/Engine/Optimization/RUCSS/Database/Queries/UsedCSS/createNewJob.php +++ b/tests/Fixtures/inc/Engine/Optimization/RUCSS/Database/Queries/UsedCSS/createNewJob.php @@ -7,7 +7,7 @@ 'queue_name' => 'EU', 'is_mobile' => false, 'now' => '2023-10-11 20:21:00', - 'result' => true + 'result' => true, ], 'expected' => [ 'item' => [ @@ -29,7 +29,7 @@ 'queue_name' => '', 'is_mobile' => false, 'now' => '2023-10-11 20:21:00', - 'result' => true + 'result' => true, ], 'expected' => [ 'item' => [ @@ -43,5 +43,6 @@ ], 'result' => true ] - ], + ] + ]; diff --git a/tests/Fixtures/inc/Engine/Optimization/RUCSS/Frontend/APIClient/addToQueue.php b/tests/Fixtures/inc/Engine/Optimization/RUCSS/Frontend/APIClient/addToQueue.php index aeb120d134..4f90372341 100644 --- a/tests/Fixtures/inc/Engine/Optimization/RUCSS/Frontend/APIClient/addToQueue.php +++ b/tests/Fixtures/inc/Engine/Optimization/RUCSS/Frontend/APIClient/addToQueue.php @@ -182,4 +182,78 @@ ], ] ], + 'testSucceedTrailingSlashRequestShouldReturnBody' => [ + 'config' => [ + 'url' => 'https://example.com/test', + 'api_url' => 'https://api.example.com', + 'email' => 'example@email.com', + 'key' => 'key', + 'response' => [ + 'code' => 200, + 'message' => 'message', + 'body' => 'body', + ], + 'errors_count' => 1, + 'request_uri' => 'https://api.example.comrucss-job', + 'args' => [ + 'body' => [ + 'wpr_email' => 'example@email.com', + 'wpr_key' => 'key', + 'url' => 'https://example.com/test/', + 'config' => [ + 'aa' => 'aa' + ], + ], + 'timeout' => 5, + 'method' => 'POST' + ], + 'options' => [ + 'aa' => 'aa' + ], + 'is_succeed' => true, + 'code' => 200, + 'message' => 'message', + 'body' => json_encode([ + 'code' => 200, + 'message' => 'message', + 'contents' => [ + 'jobId' => 10, + 'queueName' => 'EU', + ], + ]), + 'to_merge' => [ + 'code' => 200, + 'message' => 'message', + 'contents' => [ + 'jobId' => 10, + 'queueName' => 'EU', + ], + ], + 'merged' => [ + 'code' => 200, + 'message' => 'message', + 'contents' => [ + 'jobId' => 10, + 'queueName' => 'EU', + ], + ], + 'default' => [ + 'code' => 400, + 'message' => 'Bad json', + 'contents' => [ + 'jobId' => 0, + 'queueName' => '', + ], + ], + 'is_unauthorized' => false, + ], + 'expected' => [ + 'code' => 200, + 'message' => 'message', + 'contents' => [ + 'jobId' => 10, + 'queueName' => 'EU', + ], + ] + ], ];