mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-01-04 00:11:23 +00:00
Add functionality to find a caller by phone number
Added a new method in PersonRepository to allow querying people by phone number. Also, a new REST API endpoint "/public/api/1.0/ticket/find-caller" was introduced and it can find a caller by their phone number. Accompanied this feature addition with corresponding test cases.
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
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 Chill\TicketBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Phonenumber\PhonenumberHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
|
||||
use Chill\TicketBundle\Controller\FindCallerController;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Psr\Log\NullLogger;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class FindCallerControllerTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
/**
|
||||
* @dataProvider provideFindCaller
|
||||
*/
|
||||
public function testFindCaller(string $caller, array $persons, array $expected): void
|
||||
{
|
||||
$controller = $this->buildController($persons);
|
||||
|
||||
$request = new Request(query: ['caller' => $caller]);
|
||||
|
||||
$response = $controller->findCaller($request);
|
||||
|
||||
$actual = json_decode($response->getContent(), true);
|
||||
|
||||
self::assertEqualsCanonicalizing($expected, $actual);
|
||||
}
|
||||
|
||||
public function testFindCallerWithoutCallerArgument(): void
|
||||
{
|
||||
self::expectException(BadRequestHttpException::class);
|
||||
|
||||
$controller = $this->buildController([]);
|
||||
|
||||
$request = new Request(query: []);
|
||||
|
||||
$controller->findCaller($request);
|
||||
}
|
||||
|
||||
public function testFindCallerWithEmptyCallerArgument(): void
|
||||
{
|
||||
self::expectException(BadRequestHttpException::class);
|
||||
|
||||
$controller = $this->buildController([]);
|
||||
|
||||
$request = new Request(query: ['caller' => '']);
|
||||
|
||||
$controller->findCaller($request);
|
||||
}
|
||||
|
||||
public function testFindCallerWithInvalidCaller(): void
|
||||
{
|
||||
self::expectException(BadRequestHttpException::class);
|
||||
|
||||
$controller = $this->buildController([]);
|
||||
|
||||
$request = new Request(query: ['caller' => 'abcde']);
|
||||
|
||||
$controller->findCaller($request);
|
||||
}
|
||||
|
||||
public static function provideFindCaller(): iterable
|
||||
{
|
||||
yield [
|
||||
'32486540600',
|
||||
[],
|
||||
['found' => false, 'name' => null],
|
||||
];
|
||||
|
||||
yield [
|
||||
'32486540600',
|
||||
[new Person()],
|
||||
['found' => true, 'name' => 'pppp'],
|
||||
]
|
||||
;
|
||||
yield [
|
||||
'32486540600',
|
||||
[new Person(), new Person()],
|
||||
['found' => true, 'name' => 'multiple'],
|
||||
];
|
||||
}
|
||||
|
||||
private function buildController(array $personsFound): FindCallerController
|
||||
{
|
||||
$phonenumberHelper =
|
||||
$subject = new PhonenumberHelper(
|
||||
new ArrayAdapter(),
|
||||
new ParameterBag([
|
||||
'chill_main.phone_helper' => [
|
||||
'default_carrier_code' => 'BE',
|
||||
],
|
||||
]),
|
||||
new NullLogger()
|
||||
);
|
||||
|
||||
$personRepository = $this->prophesize(PersonRepository::class);
|
||||
$personRepository->findByPhoneNumber(Argument::any(), Argument::type('int'), Argument::type('int'))->willReturn($personsFound);
|
||||
|
||||
$personRender = $this->prophesize(PersonRenderInterface::class);
|
||||
$personRender->renderString(Argument::type(Person::class), Argument::type('array'))->willReturn('pppp');
|
||||
|
||||
return new FindCallerController($phonenumberHelper, $personRepository->reveal(), $personRender->reveal());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user