Skip to content

Commit

Permalink
test: added more WebhookManagement unit test scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateus Picoloto committed Apr 23, 2024
1 parent 70d3573 commit e8621f9
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion Test/Unit/Model/WebhookManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,52 @@ public function testeSaveWithRecipientWebhook()
];

$account = [
"id" => "acc_pBLvRR1HAAhXvD34",
"id" => "acc_xxxxxxxxxxxxxxxx",
"name" => "Account Test"
];
$result = $webhookManagement->save($id, $type, $data, $account);

$this->assertSame($webhookRecipientResponse, $result);
}


public function testeSaveWithNonPlatformWebhook()
{
$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);
$expectedResponse = [
'message' => 'Webhook Received',
'code' => 200
];

$webhookManagement = new WebhookManagement($orderFactoryMock, $accountMock, $webhookReceiverServiceMock);

$id = "hook_aaaaaaaaaaaaaaaa";
$type = "charge.paid";
$data = [];

$account = [
"id" => "acc_xxxxxxxxxxxxxxxx",
"name" => "Account Test"
];
$result = $webhookManagement->save($id, $type, $data, $account);

$this->assertSame($expectedResponse, $result);
}
}

0 comments on commit e8621f9

Please sign in to comment.