mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-23 04:17:45 +00:00
Add filtering tickets by person center
This commit is contained in:
@@ -54,6 +54,20 @@ paths:
|
|||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "OK"
|
description: "OK"
|
||||||
|
/1.0/ticket/search/authorized-centers:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- ticket
|
||||||
|
summary: List of centers authorized for the current user
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "OK"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/Center'
|
||||||
/1.0/ticket/ticket/list:
|
/1.0/ticket/ticket/list:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
@@ -190,6 +204,18 @@ paths:
|
|||||||
type: integer
|
type: integer
|
||||||
format: integer
|
format: integer
|
||||||
minimum: 1
|
minimum: 1
|
||||||
|
- name: byPersonCenter
|
||||||
|
in: query
|
||||||
|
description: The id of the centers. The list of centers can be search through /api/1.0/ticket/search/authorized-centers endpoint.
|
||||||
|
required: false
|
||||||
|
style: form
|
||||||
|
explode: false
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
format: integer
|
||||||
|
minimum: 1
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: OK
|
description: OK
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?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\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give a list of Centers usable for searching amongst tickets.
|
||||||
|
*/
|
||||||
|
final readonly class CenterForTicketListApiController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser,
|
||||||
|
private Security $security,
|
||||||
|
private SerializerInterface $serializer,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
#[Route(path: '/api/1.0/ticket/search/authorized-centers')]
|
||||||
|
public function __invoke(): JsonResponse
|
||||||
|
{
|
||||||
|
$user = $this->security->getUser();
|
||||||
|
|
||||||
|
if (!$user instanceof User) {
|
||||||
|
throw new AccessDeniedHttpException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$centers = $this->authorizationHelperForCurrentUser->getReachableCenters(PersonVoter::SEE);
|
||||||
|
|
||||||
|
return new JsonResponse(
|
||||||
|
$this->serializer->serialize($centers, 'json', ['groups' => 'read']),
|
||||||
|
Response::HTTP_OK,
|
||||||
|
json: true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\TicketBundle\Controller;
|
namespace Chill\TicketBundle\Controller;
|
||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -46,6 +47,7 @@ final readonly class TicketListApiController
|
|||||||
ParameterBagInterface $parameterBag,
|
ParameterBagInterface $parameterBag,
|
||||||
private UserRepositoryInterface $userRepository,
|
private UserRepositoryInterface $userRepository,
|
||||||
private UserGroupRepositoryInterface $userGroupRepository,
|
private UserGroupRepositoryInterface $userGroupRepository,
|
||||||
|
private CenterRepositoryInterface $centerRepository,
|
||||||
) {
|
) {
|
||||||
$this->expectedTimeResponseDelay = new \DateInterval($parameterBag->get('chill_ticket')['ticket']['response_time_exceeded_delay']);
|
$this->expectedTimeResponseDelay = new \DateInterval($parameterBag->get('chill_ticket')['ticket']['response_time_exceeded_delay']);
|
||||||
}
|
}
|
||||||
@@ -191,6 +193,21 @@ final readonly class TicketListApiController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->query->has('byPersonCenter')) {
|
||||||
|
$centerIds = explode(',', $request->query->get('byPersonCenter'));
|
||||||
|
foreach ($centerIds as $id) {
|
||||||
|
if (!is_numeric($id) || 0 === ((int) $id)) {
|
||||||
|
throw new BadRequestHttpException('Only numbers are allowed in by center parameter');
|
||||||
|
}
|
||||||
|
|
||||||
|
$center = $this->centerRepository->find($id);
|
||||||
|
if (null === $center) {
|
||||||
|
throw new BadRequestHttpException('Center not found');
|
||||||
|
}
|
||||||
|
$params['byPersonCenter'][] = $center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$nb = $this->ticketRepository->countTickets($params);
|
$nb = $this->ticketRepository->countTickets($params);
|
||||||
$paginator = $this->paginatorFactory->create($nb);
|
$paginator = $this->paginatorFactory->create($nb);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\TicketBundle\Repository;
|
namespace Chill\TicketBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
|
||||||
use Chill\TicketBundle\Entity\AddresseeHistory;
|
use Chill\TicketBundle\Entity\AddresseeHistory;
|
||||||
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
|
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
|
||||||
use Chill\TicketBundle\Entity\MotiveHistory;
|
use Chill\TicketBundle\Entity\MotiveHistory;
|
||||||
@@ -203,6 +204,35 @@ final readonly class TicketACLAwareRepository implements TicketACLAwareRepositor
|
|||||||
$qb->andWhere($addresseeGroupOr);
|
$qb->andWhere($addresseeGroupOr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('byPersonCenter', $params)) {
|
||||||
|
$orx = $qb->expr()->orX();
|
||||||
|
foreach ($params['byPersonCenter'] as $userCenter) {
|
||||||
|
$orx->add(
|
||||||
|
$qb->expr()->exists(sprintf(
|
||||||
|
'SELECT 1 FROM %s ticket_person_%d
|
||||||
|
JOIN %s person_center_%d WITH person_center_%d.person = ticket_person_%d.person AND TRUE = OVERLAPSI(ticket_person_%d.startDate, ticket_person_%d.startDate),(person_center_%d.startDate, person_center_%d.endDate)
|
||||||
|
WHERE ticket_person_%d.ticket = t AND ticket_person_%d.endDate IS NULL AND person_center_%d.center = :center_%d',
|
||||||
|
PersonHistory::class,
|
||||||
|
++$i,
|
||||||
|
PersonCenterHistory::class,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
$i,
|
||||||
|
))
|
||||||
|
);
|
||||||
|
$qb->setParameter(sprintf('center_%d', $i), $userCenter);
|
||||||
|
}
|
||||||
|
$qb->andWhere($orx);
|
||||||
|
}
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\TicketBundle\Repository;
|
namespace Chill\TicketBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Entity\UserGroup;
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
@@ -22,7 +23,7 @@ use Chill\TicketBundle\Entity\Ticket;
|
|||||||
/**
|
/**
|
||||||
* Repository to find tickets, taking care of permissions.
|
* Repository to find tickets, taking care of permissions.
|
||||||
*
|
*
|
||||||
* @phpstan-type TicketACLAwareRepositoryParam array{byPerson?: list<Person>, byCurrentState?: list<StateEnum>, byCurrentStateEmergency?: list<EmergencyStatusEnum>, byMotives?: list<Motive>, byCreatedBefore?: \DateTimeImmutable, byCreatedAfter?: \DateTimeImmutable, byAddressee?: list<User>, byAddresseeGroup?: list<UserGroup>, byCreator?: list<User>, byTicketId?: int}
|
* @phpstan-type TicketACLAwareRepositoryParam array{byPerson?: list<Person>, byCurrentState?: list<StateEnum>, byCurrentStateEmergency?: list<EmergencyStatusEnum>, byMotives?: list<Motive>, byCreatedBefore?: \DateTimeImmutable, byCreatedAfter?: \DateTimeImmutable, byAddressee?: list<User>, byAddresseeGroup?: list<UserGroup>, byCreator?: list<User>, byTicketId?: int, byPersonCenter?: list<Center>}
|
||||||
*/
|
*/
|
||||||
interface TicketACLAwareRepositoryInterface
|
interface TicketACLAwareRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
use Chill\MainBundle\Entity\UserGroup;
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -93,6 +94,7 @@ final class TicketListApiControllerByAddresseeGroupTest extends TestCase
|
|||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$groupRepository->reveal(),
|
$groupRepository->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new Request(query: ['byAddresseeGroup' => '10']);
|
$request = new Request(query: ['byAddresseeGroup' => '10']);
|
||||||
@@ -159,6 +161,7 @@ final class TicketListApiControllerByAddresseeGroupTest extends TestCase
|
|||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$groupRepository->reveal(),
|
$groupRepository->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new Request(query: ['byAddresseeGroup' => '10,20']);
|
$request = new Request(query: ['byAddresseeGroup' => '10,20']);
|
||||||
@@ -201,6 +204,7 @@ final class TicketListApiControllerByAddresseeGroupTest extends TestCase
|
|||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$groupRepository->reveal(),
|
$groupRepository->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new Request(query: ['byAddresseeGroup' => '10,20']);
|
$request = new Request(query: ['byAddresseeGroup' => '10,20']);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -94,7 +95,8 @@ final class TicketListApiControllerByAddresseeTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byAddressee filter
|
// Create request with byAddressee filter
|
||||||
@@ -168,7 +170,8 @@ final class TicketListApiControllerByAddresseeTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with multiple byAddressee filter
|
// Create request with multiple byAddressee filter
|
||||||
@@ -216,7 +219,8 @@ final class TicketListApiControllerByAddresseeTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byAddressee filter with non-existent user
|
// Create request with byAddressee filter with non-existent user
|
||||||
@@ -286,7 +290,8 @@ final class TicketListApiControllerByAddresseeTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with both byAddressee and byAddresseeToMe filters
|
// Create request with both byAddressee and byAddresseeToMe filters
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
@@ -92,7 +93,8 @@ final class TicketListApiControllerByAddresseeToMeTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byAddresseeToMe filter
|
// Create request with byAddresseeToMe filter
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -99,7 +100,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in RFC3339 format
|
// Create request with byCreatedAfter filter in RFC3339 format
|
||||||
@@ -173,7 +175,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
||||||
@@ -204,6 +207,7 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$centerRepository = $this->prophesize(CenterRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@@ -216,7 +220,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$centerRepository->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in invalid format
|
// Create request with byCreatedAfter filter in invalid format
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -99,7 +100,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in RFC3339 format
|
// Create request with byCreatedAfter filter in RFC3339 format
|
||||||
@@ -173,7 +175,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
||||||
@@ -204,6 +207,7 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$centerRepository = $this->prophesize(CenterRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@@ -216,7 +220,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$centerRepository->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byCreatedAfter filter in invalid format
|
// Create request with byCreatedAfter filter in invalid format
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -90,7 +91,8 @@ final class TicketListApiControllerByCreatorTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new Request(query: ['byCreator' => '1']);
|
$request = new Request(query: ['byCreator' => '1']);
|
||||||
@@ -151,7 +153,8 @@ final class TicketListApiControllerByCreatorTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new Request(query: ['byCreator' => '1,2']);
|
$request = new Request(query: ['byCreator' => '1,2']);
|
||||||
@@ -194,7 +197,8 @@ final class TicketListApiControllerByCreatorTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
$request = new Request(query: ['byCreator' => '99']);
|
$request = new Request(query: ['byCreator' => '99']);
|
||||||
|
|||||||
@@ -0,0 +1,240 @@
|
|||||||
|
<?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\Entity\Center;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||||
|
use Chill\TicketBundle\Entity\Ticket;
|
||||||
|
use Chill\TicketBundle\Repository\MotiveRepository;
|
||||||
|
use Chill\TicketBundle\Repository\TicketACLAwareRepositoryInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
|
use Symfony\Component\Clock\MockClock;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @covers \Chill\TicketBundle\Controller\TicketListApiController
|
||||||
|
*/
|
||||||
|
final class TicketListApiControllerByPersonCenterTest extends TestCase
|
||||||
|
{
|
||||||
|
use ProphecyTrait;
|
||||||
|
|
||||||
|
public function testListTicketWithSingleCenter(): void
|
||||||
|
{
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
|
||||||
|
$center = new Center();
|
||||||
|
|
||||||
|
$centerRepository = $this->prophesize(CenterRepositoryInterface::class);
|
||||||
|
$centerRepository->find(10)->willReturn($center);
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$tickets = [new Ticket(), new Ticket()];
|
||||||
|
$ticketRepository->countTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byPersonCenter']) && in_array($center, $params['byPersonCenter'], true))
|
||||||
|
)->shouldBeCalled()->willReturn(2);
|
||||||
|
$ticketRepository->findTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byPersonCenter']) && in_array($center, $params['byPersonCenter'], true)),
|
||||||
|
0,
|
||||||
|
10
|
||||||
|
)->shouldBeCalled()->willReturn($tickets);
|
||||||
|
|
||||||
|
$paginator = $this->prophesize(PaginatorInterface::class);
|
||||||
|
$paginator->getCurrentPageFirstItemNumber()->willReturn(0);
|
||||||
|
$paginator->getItemsPerPage()->willReturn(10);
|
||||||
|
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$paginatorFactory->create(2)->willReturn($paginator->reveal());
|
||||||
|
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$serializer->serialize(
|
||||||
|
Argument::that(fn (Collection $collection) => $collection->getItems() === $tickets),
|
||||||
|
'json',
|
||||||
|
['groups' => 'read:simple']
|
||||||
|
)->willReturn('{"items":[{},{}],"pagination":{}}');
|
||||||
|
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal(),
|
||||||
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$centerRepository->reveal(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$request = new Request(query: ['byPersonCenter' => '10']);
|
||||||
|
|
||||||
|
$response = $controller->listTicket($request);
|
||||||
|
|
||||||
|
self::assertInstanceOf(JsonResponse::class, $response);
|
||||||
|
self::assertSame('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListTicketWithMultipleCenters(): void
|
||||||
|
{
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
|
||||||
|
$center1 = new Center();
|
||||||
|
$center2 = new Center();
|
||||||
|
|
||||||
|
$centerRepository = $this->prophesize(CenterRepositoryInterface::class);
|
||||||
|
$centerRepository->find(10)->willReturn($center1);
|
||||||
|
$centerRepository->find(20)->willReturn($center2);
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$tickets = [new Ticket(), new Ticket()];
|
||||||
|
$ticketRepository->countTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byPersonCenter']) && in_array($center1, $params['byPersonCenter'], true) && in_array($center2, $params['byPersonCenter'], true))
|
||||||
|
)->willReturn(2);
|
||||||
|
$ticketRepository->findTickets(
|
||||||
|
Argument::that(fn ($params) => isset($params['byPersonCenter']) && in_array($center1, $params['byPersonCenter'], true) && in_array($center2, $params['byPersonCenter'], true)),
|
||||||
|
0,
|
||||||
|
10
|
||||||
|
)->willReturn($tickets);
|
||||||
|
|
||||||
|
$paginator = $this->prophesize(PaginatorInterface::class);
|
||||||
|
$paginator->getCurrentPageFirstItemNumber()->willReturn(0);
|
||||||
|
$paginator->getItemsPerPage()->willReturn(10);
|
||||||
|
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$paginatorFactory->create(2)->willReturn($paginator->reveal());
|
||||||
|
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$serializer->serialize(
|
||||||
|
Argument::that(fn (Collection $collection) => $collection->getItems() === $tickets),
|
||||||
|
'json',
|
||||||
|
['groups' => 'read:simple']
|
||||||
|
)->willReturn('{"items":[{},{}],"pagination":{}}');
|
||||||
|
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal(),
|
||||||
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$centerRepository->reveal(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$request = new Request(query: ['byPersonCenter' => '10,20']);
|
||||||
|
|
||||||
|
$response = $controller->listTicket($request);
|
||||||
|
|
||||||
|
self::assertInstanceOf(JsonResponse::class, $response);
|
||||||
|
self::assertSame('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListTicketWithNonNumericCenterId(): void
|
||||||
|
{
|
||||||
|
self::expectException(BadRequestHttpException::class);
|
||||||
|
self::expectExceptionMessage('Only numbers are allowed in by center parameter');
|
||||||
|
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$userGroupRepository = $this->prophesize(UserGroupRepositoryInterface::class);
|
||||||
|
$centerRepository = $this->prophesize(CenterRepositoryInterface::class);
|
||||||
|
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal(),
|
||||||
|
$userGroupRepository->reveal(),
|
||||||
|
$centerRepository->reveal(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$request = new Request(query: ['byPersonCenter' => 'foo']);
|
||||||
|
$controller->listTicket($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListTicketWithCenterNotFound(): void
|
||||||
|
{
|
||||||
|
self::expectException(BadRequestHttpException::class);
|
||||||
|
self::expectExceptionMessage('Center not found');
|
||||||
|
|
||||||
|
$security = $this->prophesize(Security::class);
|
||||||
|
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||||
|
|
||||||
|
$centerRepository = $this->prophesize(CenterRepositoryInterface::class);
|
||||||
|
$centerRepository->find(10)->willReturn(null);
|
||||||
|
|
||||||
|
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||||
|
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||||
|
$serializer = $this->prophesize(SerializerInterface::class);
|
||||||
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
|
||||||
|
$controller = new TicketListApiController(
|
||||||
|
$security->reveal(),
|
||||||
|
$ticketRepository->reveal(),
|
||||||
|
$paginatorFactory->reveal(),
|
||||||
|
$serializer->reveal(),
|
||||||
|
$personRepository->reveal(),
|
||||||
|
$motiveRepository->reveal(),
|
||||||
|
new MockClock(),
|
||||||
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
|
$userRepository->reveal(),
|
||||||
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$centerRepository->reveal(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$request = new Request(query: ['byPersonCenter' => '10']);
|
||||||
|
$controller->listTicket($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -109,7 +110,8 @@ final class TicketListApiControllerByResponseTimeExceededTest extends TestCase
|
|||||||
$mockClock,
|
$mockClock,
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byResponseTimeExceeded parameter only
|
// Create request with byResponseTimeExceeded parameter only
|
||||||
@@ -194,7 +196,8 @@ final class TicketListApiControllerByResponseTimeExceededTest extends TestCase
|
|||||||
$mockClock,
|
$mockClock,
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with both byCreatedAfter and byResponseTimeExceeded parameters
|
// Create request with both byCreatedAfter and byResponseTimeExceeded parameters
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -92,7 +93,8 @@ final class TicketListApiControllerByTicketIdTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$userGroupRepository->reveal()
|
$userGroupRepository->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with byTicketId filter
|
// Create request with byTicketId filter
|
||||||
@@ -135,7 +137,8 @@ final class TicketListApiControllerByTicketIdTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$userGroupRepository->reveal()
|
$userGroupRepository->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Use -1 to trigger the controller's validation error
|
// Use -1 to trigger the controller's validation error
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -89,7 +90,8 @@ final class TicketListApiControllerCurrentStateEmergencyTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with emergency filter
|
// Create request with emergency filter
|
||||||
@@ -131,7 +133,8 @@ final class TicketListApiControllerCurrentStateEmergencyTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with invalid emergency filter
|
// Create request with invalid emergency filter
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -89,7 +90,8 @@ final class TicketListApiControllerCurrentStateTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with person filter
|
// Create request with person filter
|
||||||
@@ -131,7 +133,8 @@ final class TicketListApiControllerCurrentStateTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with person filter
|
// Create request with person filter
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -94,7 +95,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with multiple motives filter
|
// Create request with multiple motives filter
|
||||||
@@ -160,7 +162,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with single motive filter
|
// Create request with single motive filter
|
||||||
@@ -204,7 +207,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with non-existent motive
|
// Create request with non-existent motive
|
||||||
@@ -231,6 +235,7 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
$personRepository = $this->prophesize(PersonRepository::class);
|
$personRepository = $this->prophesize(PersonRepository::class);
|
||||||
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
$motiveRepository = $this->prophesize(MotiveRepository::class);
|
||||||
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||||
|
$centerRepository = $this->prophesize(CenterRepositoryInterface::class);
|
||||||
|
|
||||||
// Create controller
|
// Create controller
|
||||||
$controller = new TicketListApiController(
|
$controller = new TicketListApiController(
|
||||||
@@ -243,7 +248,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$centerRepository->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with non-integer motive parameter
|
// Create request with non-integer motive parameter
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
|||||||
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||||
|
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||||
use Chill\MainBundle\Serializer\Model\Collection;
|
use Chill\MainBundle\Serializer\Model\Collection;
|
||||||
@@ -83,7 +84,8 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request
|
// Create request
|
||||||
@@ -145,7 +147,8 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with person filter
|
// Create request with person filter
|
||||||
@@ -185,7 +188,8 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request
|
// Create request
|
||||||
@@ -228,7 +232,8 @@ final class TicketListApiControllerTest extends TestCase
|
|||||||
new MockClock(),
|
new MockClock(),
|
||||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||||
$userRepository->reveal(),
|
$userRepository->reveal(),
|
||||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
$this->prophesize(UserGroupRepositoryInterface::class)->reveal(),
|
||||||
|
$this->prophesize(CenterRepositoryInterface::class)->reveal()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create request with person filter
|
// Create request with person filter
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\TicketBundle\Tests\Repository;
|
namespace Chill\TicketBundle\Tests\Repository;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\MainBundle\Entity\UserGroup;
|
use Chill\MainBundle\Entity\UserGroup;
|
||||||
use Chill\PersonBundle\DataFixtures\Helper\RandomPersonHelperTrait;
|
use Chill\PersonBundle\DataFixtures\Helper\RandomPersonHelperTrait;
|
||||||
@@ -192,4 +193,19 @@ class TicketACLAwareRepositoryTest extends KernelTestCase
|
|||||||
|
|
||||||
self::assertIsArray($actual);
|
self::assertIsArray($actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFindByPersonCenter(): void
|
||||||
|
{
|
||||||
|
$centers = $this->entityManager->createQuery('SELECT c FROM '.Center::class.' c')
|
||||||
|
->setMaxResults(2)
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
if ([] === $centers) {
|
||||||
|
throw new \UnexpectedValueException('No centers found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$actual = $this->repository->findTickets(['byPersonCenter' => $centers]);
|
||||||
|
|
||||||
|
self::assertIsArray($actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user