mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-09 23:47:46 +00:00
Fix bugs in api endpoint to filter tickets, and add parameters byAddresseeGroup and byCreator
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
<?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\UserGroup;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
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 TicketListApiControllerByAddresseeGroupTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testListTicketWithSingleByAddresseeGroupFilter(): void
|
||||
{
|
||||
// Mocks
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||
|
||||
$group = new UserGroup();
|
||||
|
||||
$groupRepository = $this->prophesize(UserGroupRepositoryInterface::class);
|
||||
$groupRepository->find(10)->willReturn($group);
|
||||
|
||||
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||
$tickets = [new Ticket(), new Ticket()];
|
||||
$ticketRepository->countTickets(
|
||||
Argument::that(fn ($params) => isset($params['byAddresseeGroup']) && in_array($group, $params['byAddresseeGroup'], true))
|
||||
)->shouldBeCalled()->willReturn(2);
|
||||
$ticketRepository->findTickets(
|
||||
Argument::that(fn ($params) => isset($params['byAddresseeGroup']) && in_array($group, $params['byAddresseeGroup'], 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(),
|
||||
$groupRepository->reveal(),
|
||||
);
|
||||
|
||||
$request = new Request(query: ['byAddresseeGroup' => '10']);
|
||||
|
||||
$response = $controller->listTicket($request);
|
||||
|
||||
self::assertInstanceOf(JsonResponse::class, $response);
|
||||
self::assertSame('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testListTicketWithMultipleByAddresseeGroupFilter(): void
|
||||
{
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||
|
||||
$group1 = new UserGroup();
|
||||
$group2 = new UserGroup();
|
||||
|
||||
$groupRepository = $this->prophesize(UserGroupRepositoryInterface::class);
|
||||
$groupRepository->find(10)->willReturn($group1);
|
||||
$groupRepository->find(20)->willReturn($group2);
|
||||
|
||||
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||
$tickets = [new Ticket(), new Ticket()];
|
||||
$ticketRepository->countTickets(
|
||||
Argument::that(fn ($params) => isset($params['byAddresseeGroup'])
|
||||
&& in_array($group1, $params['byAddresseeGroup'], true)
|
||||
&& in_array($group2, $params['byAddresseeGroup'], true))
|
||||
)->shouldBeCalled()->willReturn(2);
|
||||
$ticketRepository->findTickets(
|
||||
Argument::that(fn ($params) => isset($params['byAddresseeGroup'])
|
||||
&& in_array($group1, $params['byAddresseeGroup'], true)
|
||||
&& in_array($group2, $params['byAddresseeGroup'], 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(),
|
||||
$groupRepository->reveal(),
|
||||
);
|
||||
|
||||
$request = new Request(query: ['byAddresseeGroup' => '10,20']);
|
||||
|
||||
$response = $controller->listTicket($request);
|
||||
|
||||
self::assertInstanceOf(JsonResponse::class, $response);
|
||||
self::assertSame('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testListTicketWithByAddresseeGroupFilterGroupNotFound(): void
|
||||
{
|
||||
self::expectException(BadRequestHttpException::class);
|
||||
self::expectExceptionMessage('User group not found');
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||
|
||||
$group1 = new UserGroup();
|
||||
|
||||
$groupRepository = $this->prophesize(UserGroupRepositoryInterface::class);
|
||||
$groupRepository->find(10)->willReturn($group1);
|
||||
$groupRepository->find(20)->willReturn(null); // not found
|
||||
|
||||
$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(),
|
||||
$groupRepository->reveal(),
|
||||
);
|
||||
|
||||
$request = new Request(query: ['byAddresseeGroup' => '10,20']);
|
||||
|
||||
// should throw
|
||||
$controller->listTicket($request);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||
@@ -92,7 +93,8 @@ final class TicketListApiControllerByAddresseeTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byAddressee filter
|
||||
@@ -165,7 +167,8 @@ final class TicketListApiControllerByAddresseeTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with multiple byAddressee filter
|
||||
@@ -212,7 +215,8 @@ final class TicketListApiControllerByAddresseeTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byAddressee filter with non-existent user
|
||||
@@ -281,7 +285,8 @@ final class TicketListApiControllerByAddresseeTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// 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\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
@@ -90,7 +91,8 @@ final class TicketListApiControllerByAddresseeToMeTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byAddresseeToMe filter
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\TicketBundle\Controller\TicketListApiController;
|
||||
@@ -50,7 +51,7 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
||||
$tickets = [new Ticket(), new Ticket()];
|
||||
|
||||
// The date in RFC3339 format
|
||||
$dateString = '2025-05-15T15:05:00Z';
|
||||
$dateString = '2025-05-15T15:05:00+00:00';
|
||||
$date = \DateTimeImmutable::createFromFormat(\DateTimeImmutable::RFC3339, $dateString);
|
||||
|
||||
$ticketRepository->countTickets(
|
||||
@@ -97,7 +98,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byCreatedAfter filter in RFC3339 format
|
||||
@@ -170,7 +172,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
||||
@@ -212,7 +215,8 @@ final class TicketListApiControllerByCreatedAfterTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// 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\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
@@ -97,7 +98,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byCreatedAfter filter in RFC3339 format
|
||||
@@ -170,7 +172,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byCreatedAfter filter in RFC3339_EXTENDED format
|
||||
@@ -212,7 +215,8 @@ final class TicketListApiControllerByCreatedBeforeTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byCreatedAfter filter in invalid format
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
<?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\User;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
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\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Clock\MockClock;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @covers \Chill\TicketBundle\Controller\TicketListApiController
|
||||
*/
|
||||
final class TicketListApiControllerByCreatorTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
public function testListTicketWithSingleByCreatorFilter(): void
|
||||
{
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||
|
||||
$user = new User();
|
||||
|
||||
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||
$userRepository->find(1)->willReturn($user);
|
||||
|
||||
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||
$tickets = [new Ticket(), new Ticket()];
|
||||
$ticketRepository->countTickets(
|
||||
Argument::that(fn ($params) => isset($params['byCreator']) && in_array($user, $params['byCreator'], true))
|
||||
)->shouldBeCalled()->willReturn(2);
|
||||
$ticketRepository->findTickets(
|
||||
Argument::that(fn ($params) => isset($params['byCreator']) && in_array($user, $params['byCreator'], 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);
|
||||
|
||||
$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()
|
||||
);
|
||||
|
||||
$request = new Request(query: ['byCreator' => '1']);
|
||||
|
||||
$response = $controller->listTicket($request);
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$this->assertEquals('{"items":[{},{}],"pagination":{}}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testListTicketWithMultipleByCreatorFilter(): void
|
||||
{
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||
|
||||
$user1 = new User();
|
||||
$user2 = new User();
|
||||
|
||||
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||
$userRepository->find(1)->willReturn($user1);
|
||||
$userRepository->find(2)->willReturn($user2);
|
||||
|
||||
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||
$tickets = [new Ticket()];
|
||||
$ticketRepository->countTickets(
|
||||
Argument::that(fn ($params) => isset($params['byCreator']) && in_array($user1, $params['byCreator'], true) && in_array($user2, $params['byCreator'], true))
|
||||
)->willReturn(1);
|
||||
$ticketRepository->findTickets(
|
||||
Argument::that(fn ($params) => isset($params['byCreator']) && in_array($user1, $params['byCreator'], true) && in_array($user2, $params['byCreator'], 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(1)->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);
|
||||
|
||||
$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()
|
||||
);
|
||||
|
||||
$request = new Request(query: ['byCreator' => '1,2']);
|
||||
$response = $controller->listTicket($request);
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$this->assertEquals('{"items":[{}],"pagination":{}}', $response->getContent());
|
||||
}
|
||||
|
||||
public function testListTicketWithByCreatorFilterUserNotFound(): void
|
||||
{
|
||||
$this->expectException(BadRequestHttpException::class);
|
||||
|
||||
$security = $this->prophesize(Security::class);
|
||||
$security->isGranted('ROLE_USER')->willReturn(true);
|
||||
|
||||
$userRepository = $this->prophesize(UserRepositoryInterface::class);
|
||||
$userRepository->find(99)->willReturn(null);
|
||||
|
||||
$ticketRepository = $this->prophesize(TicketACLAwareRepositoryInterface::class);
|
||||
|
||||
$paginator = $this->prophesize(PaginatorInterface::class);
|
||||
$paginator->getCurrentPageFirstItemNumber()->willReturn(0);
|
||||
$paginator->getItemsPerPage()->willReturn(10);
|
||||
|
||||
$paginatorFactory = $this->prophesize(PaginatorFactoryInterface::class);
|
||||
$paginatorFactory->create(0)->willReturn($paginator->reveal());
|
||||
|
||||
$serializer = $this->prophesize(SerializerInterface::class);
|
||||
$personRepository = $this->prophesize(PersonRepository::class);
|
||||
$motiveRepository = $this->prophesize(MotiveRepository::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()
|
||||
);
|
||||
|
||||
$request = new Request(query: ['byCreator' => '99']);
|
||||
$controller->listTicket($request);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
@@ -107,7 +108,8 @@ final class TicketListApiControllerByResponseTimeExceededTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
$mockClock,
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with byResponseTimeExceeded parameter only
|
||||
@@ -191,7 +193,8 @@ final class TicketListApiControllerByResponseTimeExceededTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
$mockClock,
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// 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\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
@@ -87,7 +88,8 @@ final class TicketListApiControllerCurrentStateEmergencyTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with emergency filter
|
||||
@@ -128,7 +130,8 @@ final class TicketListApiControllerCurrentStateEmergencyTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with invalid emergency filter
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
@@ -87,7 +88,8 @@ final class TicketListApiControllerCurrentStateTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with person filter
|
||||
@@ -128,7 +130,8 @@ final class TicketListApiControllerCurrentStateTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with person filter
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
||||
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
@@ -92,7 +93,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with multiple motives filter
|
||||
@@ -157,7 +159,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with single motive filter
|
||||
@@ -200,7 +203,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with non-existent motive
|
||||
@@ -238,7 +242,8 @@ final class TicketListApiControllerMotivesTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with non-integer motive parameter
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Chill\TicketBundle\Tests\Controller;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactoryInterface;
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
@@ -81,7 +82,8 @@ final class TicketListApiControllerTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request
|
||||
@@ -142,7 +144,8 @@ final class TicketListApiControllerTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with person filter
|
||||
@@ -181,7 +184,8 @@ final class TicketListApiControllerTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request
|
||||
@@ -223,7 +227,8 @@ final class TicketListApiControllerTest extends TestCase
|
||||
$motiveRepository->reveal(),
|
||||
new MockClock(),
|
||||
new ParameterBag(['chill_ticket' => ['ticket' => ['response_time_exceeded_delay' => 'PT12H']]]),
|
||||
$userRepository->reveal()
|
||||
$userRepository->reveal(),
|
||||
$this->prophesize(UserGroupRepositoryInterface::class)->reveal()
|
||||
);
|
||||
|
||||
// Create request with person filter
|
||||
|
||||
@@ -12,6 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\TicketBundle\Tests\Repository;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\UserGroup;
|
||||
use Chill\PersonBundle\DataFixtures\Helper\RandomPersonHelperTrait;
|
||||
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
|
||||
use Chill\TicketBundle\Entity\Motive;
|
||||
@@ -139,4 +140,49 @@ class TicketACLAwareRepositoryTest extends KernelTestCase
|
||||
|
||||
self::assertIsArray($actual);
|
||||
}
|
||||
|
||||
public function testFindByCreator(): void
|
||||
{
|
||||
$users = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')
|
||||
->setMaxResults(2)
|
||||
->getResult();
|
||||
|
||||
if ([] === $users) {
|
||||
throw new \UnexpectedValueException('No users found');
|
||||
}
|
||||
|
||||
$actual = $this->repository->findTickets(['byCreator' => $users]);
|
||||
|
||||
self::assertIsArray($actual);
|
||||
}
|
||||
|
||||
public function testCountByCreator(): void
|
||||
{
|
||||
$users = $this->entityManager->createQuery('SELECT u FROM '.User::class.' u')
|
||||
->setMaxResults(2)
|
||||
->getResult();
|
||||
|
||||
if ([] === $users) {
|
||||
throw new \UnexpectedValueException('No users found');
|
||||
}
|
||||
|
||||
$count = $this->repository->countTickets(['byCreator' => $users]);
|
||||
|
||||
self::assertIsInt($count);
|
||||
}
|
||||
|
||||
public function testFindByAddresseeGroup(): void
|
||||
{
|
||||
$userGroups = $this->entityManager->createQuery('SELECT ug FROM '.UserGroup::class.' ug')
|
||||
->setMaxResults(2)
|
||||
->getResult();
|
||||
|
||||
if ([] === $userGroups) {
|
||||
throw new \UnexpectedValueException('No users found');
|
||||
}
|
||||
|
||||
$actual = $this->repository->findTickets(['byCreator' => $userGroups]);
|
||||
|
||||
self::assertIsArray($actual);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user