diff --git a/src/CloudTasksQueue.php b/src/CloudTasksQueue.php index 9a35298..cdcbcf4 100644 --- a/src/CloudTasksQueue.php +++ b/src/CloudTasksQueue.php @@ -101,7 +101,7 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0) $availableAt = $this->availableAt($delay); $httpRequest = $this->createHttpRequest(); - $httpRequest->setUrl(Config::getHandler($this->config['handler'])); + $httpRequest->setUrl($this->getHandler()); $httpRequest->setHttpMethod(HttpMethod::POST); $httpRequest->setBody( // Laravel 7+ jobs have a uuid, but Laravel 6 doesn't have it. @@ -183,4 +183,9 @@ private function createTask(): Task { return app(Task::class); } + + public function getHandler(): string + { + return Config::getHandler($this->config['handler']); + } } diff --git a/src/OpenIdVerificatorConcrete.php b/src/OpenIdVerificatorConcrete.php index 01f4c0b..196e0ac 100644 --- a/src/OpenIdVerificatorConcrete.php +++ b/src/OpenIdVerificatorConcrete.php @@ -18,7 +18,7 @@ public function verify(?string $token, array $config): void (new AccessToken())->verify( $token, [ - 'audience' => $config['handler'], + 'audience' => app('queue')->getHandler(), 'throwException' => true, ] ); diff --git a/src/OpenIdVerificatorFake.php b/src/OpenIdVerificatorFake.php index f109207..971ede2 100644 --- a/src/OpenIdVerificatorFake.php +++ b/src/OpenIdVerificatorFake.php @@ -17,7 +17,7 @@ public function verify(?string $token, array $config): void (new AccessToken())->verify( $token, [ - 'audience' => $config['handler'], + 'audience' => app('queue')->getHandler(), 'throwException' => true, 'certsLocation' => __DIR__ . '/../tests/Support/self-signed-public-key-as-jwk.json', ] diff --git a/tests/QueueTest.php b/tests/QueueTest.php index 68c1e10..0a89bda 100644 --- a/tests/QueueTest.php +++ b/tests/QueueTest.php @@ -25,7 +25,7 @@ public function a_http_request_with_the_handler_url_is_made() // Assert CloudTasksApi::assertTaskCreated(function (Task $task): bool { - return $task->getHttpRequest()->getUrl() === 'http://docker.for.mac.localhost:8080'; + return $task->getHttpRequest()->getUrl() === 'http://docker.for.mac.localhost:8080/handle-task'; }); } @@ -46,6 +46,24 @@ public function it_posts_to_the_handler() }); } + /** + * @test + */ + public function it_posts_to_the_correct_handler_url() + { + // Arrange + $this->setConfigValue('handler', 'http://docker.for.mac.localhost:8081'); + CloudTasksApi::fake(); + + // Act + $this->dispatch(new SimpleJob()); + + // Assert + CloudTasksApi::assertTaskCreated(function (Task $task): bool { + return $task->getHttpRequest()->getUrl() === 'http://docker.for.mac.localhost:8081/handle-task'; + }); + } + /** * @test */