Skip to content

Commit

Permalink
ACP-2626 Return error response in case of no handler was executed. (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
stereomon authored Jul 17, 2024
1 parent 37b186f commit a55934a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public function handleWebhook(WebhookRequestTransfer $webhookRequestTransfer, We
$webhookResponseTransfer = $webhookHandlerPlugin->handleWebhook($webhookRequestTransfer, $webhookResponseTransfer);
}

if ($webhookResponseTransfer->getIsSuccessful() === null) {
$webhookResponseTransfer
->setIsSuccessful(false)
->setMessage(sprintf('The webhook was not handled by any of the registered plugins. WebhookRequestTransfer: %s', json_encode($webhookRequestTransfer->toArray())));
}

return $webhookResponseTransfer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ public function testGivenAGlueRequestWithoutContentWhenTheRequestIsHandledThenAH
$this->assertSame('POST content is required.', $glueResponseTransfer->getErrors()[0]->getMessage());
}

public function testGivenAValidGlueRequestWhenTheRequestIsNotHandledByAnyOfTheAttachedPluginsThenAnExceptionIsThrownHttpStatus400IsReturnedTogetherWithAMessageInTheGlueResponseTransfer(): void
{
// Arrange
$glueRequestTransfer = new GlueRequestTransfer();
$glueRequestTransfer
->setContent('{"key": "value"}')
->setPath('/webhooks');

$webhooksController = new WebhooksController();

// Act
$glueResponseTransfer = $webhooksController->postAction($glueRequestTransfer);

// Assert
$this->assertSame(Response::HTTP_BAD_REQUEST, $glueResponseTransfer->getHttpStatus());
$this->assertCount(1, $glueResponseTransfer->getErrors());
}

public function testGivenAValidGlueRequestWhenTheRequestIsHandledAndTheWebhookResponseIsSuccessfulThenAHttpStatus200IsReturnedInTheGlueResponseTransfer(): void
{
// Arrange
Expand Down

0 comments on commit a55934a

Please sign in to comment.