-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aee1666
commit a617c1a
Showing
2 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
tests/Unit/Framework/PaymentGateways/Webhooks/WebhookTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Unit\Framework\PaymentGateways\Webhooks; | ||
|
||
use Give\Framework\Exceptions\Primitives\Exception; | ||
use Give\Framework\PaymentGateways\Webhooks\Webhook; | ||
use Give\PaymentGateways\Gateways\Offline\OfflineGateway; | ||
use Give\PaymentGateways\Gateways\TestGateway\TestGateway; | ||
use Give\Tests\TestCase; | ||
use Give\Tests\TestTraits\RefreshDatabase; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class WebhookTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @throws Exception | ||
*/ | ||
public function testGetNotificationUrlShouldThrowException() | ||
{ | ||
$this->expectException(Exception::class); | ||
|
||
$testGateway = new OfflineGateway(); // This gateway doesn't implement the WebhookNotificationsListener interface | ||
$webhook = new Webhook($testGateway); | ||
$webhook->getNotificationUrl(); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @throws Exception | ||
*/ | ||
public function testGetNotificationUrlShouldGenerateValidRoute() | ||
{ | ||
$testGateway = new TestGateway(); | ||
$webhook = new Webhook($testGateway); | ||
$notificationUrl = $webhook->getNotificationUrl(); | ||
$expectedUrl = $testGateway->generateGatewayRouteUrl('webhookNotificationsListener'); | ||
|
||
$this->assertEquals($expectedUrl, $notificationUrl); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @throws Exception | ||
*/ | ||
public function testGetNotificationUrlShouldGenerateValidRouteWithArgs() | ||
{ | ||
$testGateway = new TestGateway(); | ||
$webhook = new Webhook($testGateway); | ||
|
||
$args = [ | ||
'notification_type' => 'payments', | ||
'payment_id' => '123', | ||
]; | ||
|
||
$notificationUrl = $webhook->getNotificationUrl($args); | ||
$expectedUrl = $testGateway->generateGatewayRouteUrl('webhookNotificationsListener', $args); | ||
|
||
$this->assertEquals($expectedUrl, $notificationUrl); | ||
} | ||
} |