From 76a71e33cde34c88ab2efac2f66ab9225e7bbd12 Mon Sep 17 00:00:00 2001 From: Maciej Kwiatkowski Date: Thu, 28 Nov 2024 11:54:42 +0100 Subject: [PATCH] SP-1024 Adding stricter assertions to unit tests --- .../UpdateInvoice/ValidateBitPayWebhookTest.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/Unit/Features/Invoice/UpdateInvoice/ValidateBitPayWebhookTest.php b/tests/Unit/Features/Invoice/UpdateInvoice/ValidateBitPayWebhookTest.php index 36ef579..a1c5159 100644 --- a/tests/Unit/Features/Invoice/UpdateInvoice/ValidateBitPayWebhookTest.php +++ b/tests/Unit/Features/Invoice/UpdateInvoice/ValidateBitPayWebhookTest.php @@ -6,6 +6,7 @@ use App\Features\Shared\Configuration\BitPayConfigurationInterface; use App\Features\Invoice\UpdateInvoice\BitPaySignatureValidator; +use App\Shared\Exceptions\SignatureVerificationFailed; use Tests\Unit\AbstractUnitTestCase; class ValidateBitPayWebhookTest extends AbstractUnitTestCase @@ -22,9 +23,7 @@ public function it_should_return_error_when_signing_key_is_missing(): void $validator = new BitPaySignatureValidator($bitpayConfig); $this->expectException(\RuntimeException::class); - $validator->execute([], [ - 'x-signature' => 'test-signature', - ]); + $validator->execute([], []); } /** @@ -33,8 +32,12 @@ public function it_should_return_error_when_signing_key_is_missing(): void public function it_should_return_error_when_signature_header_is_missing(): void { $bitpayConfig = $this->createMock(BitPayConfigurationInterface::class); + $bitpayConfig->expects($this->once()) + ->method('getToken') + ->willReturn('test-token'); + $validator = new BitPaySignatureValidator($bitpayConfig); - $this->expectException(\RuntimeException::class); + $this->expectException(SignatureVerificationFailed::class); $validator->execute([], []); } @@ -49,10 +52,10 @@ public function it_should_return_error_when_signature_does_not_match(): void ->method('getToken') ->willReturn('test-token'); - $headers = ['x-signature' => 'invalid-signature']; + $headers = ['x-signature' => ['invalid-signature']]; $validator = new BitPaySignatureValidator($bitpayConfig); - $this->expectException(\RuntimeException::class); + $this->expectException(SignatureVerificationFailed::class); $validator->execute([], $headers); }