diff --git a/tests/Controller/Admin/ClientsControllerTest.php b/tests/Controller/Admin/ClientsControllerTest.php index a7b9e4b..7ad5b6c 100644 --- a/tests/Controller/Admin/ClientsControllerTest.php +++ b/tests/Controller/Admin/ClientsControllerTest.php @@ -8,6 +8,8 @@ use App\Entity\User; use App\Repository\CustomerRepository; use App\Service\MeilisearchService; use App\Service\UserManagementService; +use Symfony\Contracts\HttpClient\HttpClientInterface; +use Symfony\Contracts\HttpClient\ResponseInterface; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; @@ -143,6 +145,42 @@ class ClientsControllerTest extends TestCase $this->assertStringContainsString('John Doe', $response->getContent()); } + public function testEntrepriseSearchTooShort(): void + { + $controller = new ClientsController(); + $request = new Request(['q' => 'a']); + $response = $controller->entrepriseSearch($request, $this->createStub(HttpClientInterface::class)); + $this->assertInstanceOf(JsonResponse::class, $response); + $this->assertStringContainsString('"total_results":0', $response->getContent()); + } + + public function testEntrepriseSearchSuccess(): void + { + $apiResponse = $this->createStub(ResponseInterface::class); + $apiResponse->method('toArray')->willReturn(['results' => [['siren' => '123456789']], 'total_results' => 1]); + + $httpClient = $this->createStub(HttpClientInterface::class); + $httpClient->method('request')->willReturn($apiResponse); + + $controller = new ClientsController(); + $request = new Request(['q' => 'siteconseil']); + $response = $controller->entrepriseSearch($request, $httpClient); + $this->assertInstanceOf(JsonResponse::class, $response); + $this->assertStringContainsString('123456789', $response->getContent()); + } + + public function testEntrepriseSearchApiError(): void + { + $httpClient = $this->createStub(HttpClientInterface::class); + $httpClient->method('request')->willThrowException(new \RuntimeException('API down')); + + $controller = new ClientsController(); + $request = new Request(['q' => 'test']); + $response = $controller->entrepriseSearch($request, $httpClient); + $this->assertSame(502, $response->getStatusCode()); + $this->assertStringContainsString('Service indisponible', $response->getContent()); + } + public function testToggle(): void { $user = new User(); diff --git a/tests/Entity/CustomerTest.php b/tests/Entity/CustomerTest.php index ec1b32e..cbc9cd9 100644 --- a/tests/Entity/CustomerTest.php +++ b/tests/Entity/CustomerTest.php @@ -117,9 +117,13 @@ class CustomerTest extends TestCase $c->setSiret('12345678901234'); $c->setRcs('RCS Paris'); $c->setNumTva('FR12345678901'); + $c->setApe('62.01Z'); + $c->setRna('W502004724'); $this->assertSame('12345678901234', $c->getSiret()); $this->assertSame('RCS Paris', $c->getRcs()); $this->assertSame('FR12345678901', $c->getNumTva()); + $this->assertSame('62.01Z', $c->getApe()); + $this->assertSame('W502004724', $c->getRna()); } public function testStripe(): void