mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Issue316 addresses search by postal code
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class AddressReferenceApiControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
public function provideData()
|
||||
{
|
||||
self::bootKernel();
|
||||
/** @var EntityManagerInterface $em */
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$postalCode = $em->createQueryBuilder()
|
||||
->select('pc')
|
||||
->from(PostalCode::class, 'pc')
|
||||
->where('pc.origin = :origin')
|
||||
->setParameter('origin', 0)
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getSingleResult();
|
||||
|
||||
yield [$postalCode->getId(), 'rue'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideData
|
||||
*/
|
||||
public function testSearch(int $postCodeId, string $pattern)
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
"/api/1.0/main/address-reference/by-postal-code/{$postCodeId}/search.json",
|
||||
['q' => $pattern]
|
||||
);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Controller;
|
||||
|
||||
use Chill\MainBundle\Test\PrepareClientTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use function json_decode;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class PostalCodeApiControllerTest extends WebTestCase
|
||||
{
|
||||
use PrepareClientTrait;
|
||||
|
||||
public function testSearch()
|
||||
{
|
||||
$client = $this->getClientAuthenticated();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/1.0/main/postal-code/search.json',
|
||||
['q' => 'fontenay le comte']
|
||||
);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
$data = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('Fontenay Le Comte', $data['results'][0]['name']);
|
||||
|
||||
// test response with invalid search pattern
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/1.0/main/postal-code/search.json',
|
||||
['q' => '']
|
||||
);
|
||||
$this->assertResponseStatusCodeSame(400);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user