first commit

This commit is contained in:
2024-12-17 13:43:22 +01:00
commit 8e6cd8b410
21292 changed files with 3514826 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
<?php
use PHPUnit\Framework\TestCase;
use PrestaShop\Module\PsEventbus\Api\EventBusSyncClient;
use PrestaShop\Module\PsEventbus\Repository\EventbusSyncRepository;
use PrestaShop\Module\PsEventbus\Service\ApiAuthorizationService;
class ApiAuthorizationServiceTest extends TestCase
{
/**
* @var EventbusSyncRepository
*/
private $eventbusSyncRepository;
/**
* @var ApiAuthorizationService
*/
private $apiAuthorizationService;
/**
* @var EventBusSyncClient
*/
private $eventBusSyncClient;
public function setUp()
{
parent::setUp();
$this->eventbusSyncRepository = $this->createMock(EventbusSyncRepository::class);
$this->eventBusSyncClient = $this->createMock(EventBusSyncClient::class);
$this->apiAuthorizationService = new ApiAuthorizationService(
$this->eventbusSyncRepository,
$this->eventBusSyncClient
);
}
public function testAuthorizeCallSucceeds()
{
$jobId = '12345';
$this->eventbusSyncRepository
->expects($this->at(0))
->method('findJobById')
->with($jobId)
->willReturn(['job_id' => '12345']);
$this->eventBusSyncClient->expects($this->at(-1))->method('validateJobId')->willReturn(true);
$this->assertTrue($this->apiAuthorizationService->authorizeCall($jobId));
$this->eventbusSyncRepository
->expects($this->at(0))
->method('findJobById')
->with($jobId)
->willReturn(false);
$this->eventBusSyncClient->expects($this->at(0))->method('validateJobId')->willReturn(['httpCode' => 201]);
$this->eventbusSyncRepository
->expects($this->atLeastOnce())
->method('insertJob')
->willReturn(true);
$this->assertTrue($this->apiAuthorizationService->authorizeCall($jobId));
}
public function testAuthorizeCallFails()
{
$jobId = '12345';
$this->eventbusSyncRepository
->expects($this->at(0))
->method('findJobById')
->with($jobId)
->willReturn(false);
$this->eventbusSyncRepository
->expects($this->atLeastOnce())
->method('insertJob')
->willReturn(false);
$this->eventBusSyncClient->method('validateJobId')->willReturn(['httpCode' => 201]);
$this->assertFalse($this->apiAuthorizationService->authorizeCall($jobId));
}
}