mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-07 15:25:00 +00:00
Add api endpoint to open and close ticket
This commit is contained in:
@@ -19,6 +19,8 @@ use Chill\TicketBundle\Entity\Comment;
|
||||
use Chill\TicketBundle\Entity\Motive;
|
||||
use Chill\TicketBundle\Entity\MotiveHistory;
|
||||
use Chill\TicketBundle\Entity\PersonHistory;
|
||||
use Chill\TicketBundle\Entity\StateEnum;
|
||||
use Chill\TicketBundle\Entity\StateHistory;
|
||||
use Chill\TicketBundle\Entity\Ticket;
|
||||
use Chill\TicketBundle\Serializer\Normalizer\TicketNormalizer;
|
||||
use Prophecy\Argument;
|
||||
@@ -41,7 +43,6 @@ class TicketNormalizerTest extends KernelTestCase
|
||||
public function testNormalize(Ticket $ticket, array $expected): void
|
||||
{
|
||||
$actual = $this->buildNormalizer()->normalize($ticket, 'json', ['groups' => 'read']);
|
||||
|
||||
self::assertEqualsCanonicalizing(array_keys($expected), array_keys($actual));
|
||||
|
||||
foreach (array_keys($expected) as $k) {
|
||||
@@ -61,23 +62,67 @@ class TicketNormalizerTest extends KernelTestCase
|
||||
|
||||
public static function provideTickets(): iterable
|
||||
{
|
||||
$t = new Ticket();
|
||||
|
||||
// added by action
|
||||
new StateHistory(StateEnum::OPEN, $t, new \DateTimeImmutable('2024-06-16T00:00:00Z'));
|
||||
|
||||
// those are added by doctrine listeners
|
||||
$t->setCreatedAt(new \DateTimeImmutable('2024-06-16T00:00:00Z'));
|
||||
$t->setCreatedBy(new User());
|
||||
$t->setUpdatedAt(new \DateTimeImmutable('2024-06-16T00:00:00Z'));
|
||||
$t->setUpdatedBy(new User());
|
||||
|
||||
yield [
|
||||
// this a nearly empty ticket
|
||||
new Ticket(),
|
||||
$t,
|
||||
[
|
||||
'type' => 'ticket_ticket',
|
||||
'createdAt' => $t->getCreatedAt()?->getTimestamp(),
|
||||
'createdBy' => ['user'],
|
||||
'id' => null,
|
||||
'externalRef' => '',
|
||||
'currentPersons' => [],
|
||||
'currentAddressees' => [],
|
||||
'currentInputs' => [],
|
||||
'currentMotive' => null,
|
||||
'history' => [],
|
||||
'history' => [
|
||||
[
|
||||
'event_type' => 'create_ticket',
|
||||
'at' => 1718495999,
|
||||
'by' => [
|
||||
0 => 'user',
|
||||
],
|
||||
'data' => [],
|
||||
],
|
||||
[
|
||||
'event_type' => 'state_change',
|
||||
'at' => 1718495999,
|
||||
'by' => [
|
||||
0 => 'user',
|
||||
],
|
||||
'data' => [
|
||||
'new_state' => 'open',
|
||||
],
|
||||
],
|
||||
],
|
||||
'currentState' => 'open',
|
||||
'updatedAt' => $t->getUpdatedAt()->getTimestamp(),
|
||||
'updatedBy' => ['user'],
|
||||
],
|
||||
];
|
||||
|
||||
// ticket with more features
|
||||
$ticket = new Ticket();
|
||||
|
||||
// added by action
|
||||
new StateHistory(StateEnum::OPEN, $ticket, new \DateTimeImmutable('2024-06-16T00:00:00Z'));
|
||||
|
||||
// those are added by doctrine listeners
|
||||
$ticket->setCreatedAt(new \DateTimeImmutable('2024-06-16T00:00:00Z'));
|
||||
$ticket->setCreatedBy(new User());
|
||||
$ticket->setUpdatedAt(new \DateTimeImmutable('2024-06-16T00:00:00Z'));
|
||||
$ticket->setUpdatedBy(new User());
|
||||
$ticket->setExternalRef('2134');
|
||||
$personHistory = new PersonHistory(new Person(), $ticket, new \DateTimeImmutable('2024-04-01T12:00:00'));
|
||||
$ticketHistory = new MotiveHistory(new Motive(), $ticket, new \DateTimeImmutable('2024-04-01T12:02:00'));
|
||||
@@ -92,6 +137,8 @@ class TicketNormalizerTest extends KernelTestCase
|
||||
$ticket,
|
||||
[
|
||||
'type' => 'ticket_ticket',
|
||||
'createdAt' => $ticket->getCreatedAt()?->getTimestamp(),
|
||||
'createdBy' => ['user'],
|
||||
'id' => null,
|
||||
'externalRef' => '2134',
|
||||
'currentPersons' => ['embedded'],
|
||||
@@ -100,12 +147,18 @@ class TicketNormalizerTest extends KernelTestCase
|
||||
'currentMotive' => ['type' => 'motive', 'id' => 0],
|
||||
'history' => [
|
||||
['event_type' => 'add_person'],
|
||||
['event_type' => 'persons_state'],
|
||||
['event_type' => 'set_motive'],
|
||||
['event_type' => 'add_comment'],
|
||||
['event_type' => 'add_addressee'],
|
||||
['event_type' => 'remove_addressee'],
|
||||
['event_type' => 'add_addressee'],
|
||||
['event_type' => 'addressees_state'],
|
||||
['event_type' => 'addressees_state'],
|
||||
['event_type' => 'addressees_state'],
|
||||
['event_type' => 'create_ticket'],
|
||||
['event_type' => 'state_change'],
|
||||
],
|
||||
'currentState' => 'open',
|
||||
'updatedAt' => $ticket->getUpdatedAt()->getTimestamp(),
|
||||
'updatedBy' => ['user'],
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -126,9 +179,7 @@ class TicketNormalizerTest extends KernelTestCase
|
||||
Argument::that(fn ($arg) => is_array($arg) && 0 < count($arg) && is_object($arg[0])),
|
||||
'json',
|
||||
Argument::type('array')
|
||||
)->will(function ($args) {
|
||||
return array_fill(0, count($args[0]), 'embedded');
|
||||
});
|
||||
)->will(fn ($args) => array_fill(0, count($args[0]), 'embedded'));
|
||||
|
||||
// array of event type
|
||||
$normalizer->normalize(
|
||||
@@ -144,10 +195,28 @@ class TicketNormalizerTest extends KernelTestCase
|
||||
|
||||
return $events;
|
||||
});
|
||||
// array of persons
|
||||
$normalizer->normalize(
|
||||
Argument::that(fn ($arg) => is_array($arg) && 1 === count($arg) && array_key_exists('persons', $arg)),
|
||||
'json',
|
||||
['groups' => 'read']
|
||||
)->will(fn ($args): array => ['persons' => []]);
|
||||
// array of addresses
|
||||
$normalizer->normalize(
|
||||
Argument::that(fn ($arg) => is_array($arg) && 1 === count($arg) && array_key_exists('addressees', $arg)),
|
||||
'json',
|
||||
['groups' => 'read']
|
||||
)->will(fn ($args): array => ['addressees' => []]);
|
||||
// state data
|
||||
$normalizer->normalize(
|
||||
Argument::that(fn ($arg) => is_array($arg) && 1 === count($arg) && array_key_exists('new_state', $arg)),
|
||||
'json',
|
||||
['groups' => 'read']
|
||||
)->will(fn ($args): array => $args[0]);
|
||||
|
||||
// datetime
|
||||
$normalizer->normalize(Argument::type(\DateTimeImmutable::class), 'json', Argument::type('array'))
|
||||
->will(function ($args) { return $args[0]->getTimestamp(); });
|
||||
->will(fn ($args) => $args[0]->getTimestamp());
|
||||
// user
|
||||
$normalizer->normalize(Argument::type(User::class), 'json', Argument::type('array'))
|
||||
->willReturn(['user']);
|
||||
|
Reference in New Issue
Block a user