-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added WebhookManagement recipient unit test
- Loading branch information
Mateus Picoloto
committed
Apr 23, 2024
1 parent
1bcda4c
commit 70d3573
Showing
2 changed files
with
80 additions
and
4 deletions.
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
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,69 @@ | ||
<?php | ||
|
||
namespace Pagarme\Pagarme\Test\Unit\Model; | ||
|
||
use Mockery; | ||
use Magento\Sales\Model\Order; | ||
use Pagarme\Pagarme\Model\Account; | ||
use Magento\Sales\Model\OrderFactory; | ||
use Pagarme\Pagarme\Test\Unit\BaseTest; | ||
use Pagarme\Pagarme\Model\WebhookManagement; | ||
use Pagarme\Core\Webhook\Services\WebhookReceiverService; | ||
|
||
class WebhookManagementTest extends BaseTest | ||
{ | ||
public function testeSaveWithRecipientWebhook() | ||
{ | ||
$moduleCoreSetupMock = Mockery::mock('alias:Pagarme\Core\Kernel\Abstractions\AbstractModuleCoreSetup'); | ||
$moduleCoreSetupMock->shouldReceive('bootstrap') | ||
->andReturnSelf(); | ||
|
||
|
||
$orderMock = Mockery::mock(Order::class); | ||
$orderMock->shouldReceive('loadByIncrementId') | ||
->andReturnSelf(); | ||
$orderMock->shouldReceive('getId') | ||
->andReturnFalse(); | ||
|
||
$orderFactoryMock = Mockery::mock(OrderFactory::class); | ||
$orderFactoryMock->shouldReceive('create') | ||
->andReturn($orderMock); | ||
$accountMock = Mockery::mock(Account::class); | ||
|
||
$webhookReceiverServiceMock = Mockery::mock(WebhookReceiverService::class); | ||
$webhookRecipientResponse = [ | ||
'message' => 'Recipient updated', | ||
'code' => 200 | ||
]; | ||
$webhookReceiverServiceMock->shouldReceive('handle') | ||
->once() | ||
->andReturn($webhookRecipientResponse); | ||
|
||
$webhookManagement = new WebhookManagement($orderFactoryMock, $accountMock, $webhookReceiverServiceMock); | ||
|
||
$id = "hook_aaaaaaaaaaaaaaaa"; | ||
$type = "recipient.updated"; | ||
$data = [ | ||
"id" => 'rp_xxxxxxxxxxxxxxxx', | ||
"name" => "Test recipient", | ||
"email" => "test@recipient.test", | ||
"document" => "11111111111", | ||
"description" => "Test description", | ||
"type" => "individual", | ||
"payment_mode" => "bank_transfer", | ||
"status" => "active", | ||
"kyc_details" => | ||
[ | ||
"status" => "approved" | ||
], | ||
]; | ||
|
||
$account = [ | ||
"id" => "acc_pBLvRR1HAAhXvD34", | ||
"name" => "Account Test" | ||
]; | ||
$result = $webhookManagement->save($id, $type, $data, $account); | ||
|
||
$this->assertSame($webhookRecipientResponse, $result); | ||
} | ||
} |