mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-30 22:16:14 +00:00
Track caller changes in ticket normalization and history serialization
This commit is contained in:
parent
7c17d4f2cb
commit
c0f320ba1a
@ -15,6 +15,7 @@ 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;
|
||||||
use Chill\TicketBundle\Entity\AddresseeHistory;
|
use Chill\TicketBundle\Entity\AddresseeHistory;
|
||||||
|
use Chill\TicketBundle\Entity\CallerHistory;
|
||||||
use Chill\TicketBundle\Entity\Comment;
|
use Chill\TicketBundle\Entity\Comment;
|
||||||
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
|
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
|
||||||
use Chill\TicketBundle\Entity\MotiveHistory;
|
use Chill\TicketBundle\Entity\MotiveHistory;
|
||||||
@ -53,6 +54,7 @@ final class TicketNormalizer implements NormalizerInterface, NormalizerAwareInte
|
|||||||
'createdBy' => $this->normalizer->normalize($object->getCreatedBy(), $format, $context),
|
'createdBy' => $this->normalizer->normalize($object->getCreatedBy(), $format, $context),
|
||||||
'currentState' => $object->getState()?->value ?? 'open',
|
'currentState' => $object->getState()?->value ?? 'open',
|
||||||
'emergency' => $object->getEmergencyStatus()?->value ?? 'no',
|
'emergency' => $object->getEmergencyStatus()?->value ?? 'no',
|
||||||
|
'caller' => $this->normalizer->normalize($object->getCaller(), $format, ['groups' => 'read']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +117,17 @@ final class TicketNormalizer implements NormalizerInterface, NormalizerAwareInte
|
|||||||
],
|
],
|
||||||
$ticket->getEmergencyStatusHistories()->toArray(),
|
$ticket->getEmergencyStatusHistories()->toArray(),
|
||||||
),
|
),
|
||||||
|
...array_map(
|
||||||
|
fn (CallerHistory $stateHistory) => [
|
||||||
|
'event_type' => 'set_caller',
|
||||||
|
'at' => $stateHistory->getStartDate(),
|
||||||
|
'by' => $stateHistory->getCreatedBy(),
|
||||||
|
'data' => [
|
||||||
|
'new_caller' => $this->normalizer->normalize($ticket->getCaller(), $format, ['groups' => ['read']]),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
$ticket->getCallerHistories()->toArray(),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (null !== $ticket->getCreatedBy() && null !== $ticket->getCreatedAt()) {
|
if (null !== $ticket->getCreatedBy() && null !== $ticket->getCreatedAt()) {
|
||||||
|
@ -15,6 +15,7 @@ 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;
|
||||||
use Chill\TicketBundle\Entity\AddresseeHistory;
|
use Chill\TicketBundle\Entity\AddresseeHistory;
|
||||||
|
use Chill\TicketBundle\Entity\CallerHistory;
|
||||||
use Chill\TicketBundle\Entity\Comment;
|
use Chill\TicketBundle\Entity\Comment;
|
||||||
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
|
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
|
||||||
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
|
use Chill\TicketBundle\Entity\EmergencyStatusHistory;
|
||||||
@ -91,27 +92,16 @@ class TicketNormalizerTest extends KernelTestCase
|
|||||||
'history' => [
|
'history' => [
|
||||||
[
|
[
|
||||||
'event_type' => 'create_ticket',
|
'event_type' => 'create_ticket',
|
||||||
'at' => 1718495999,
|
|
||||||
'by' => [
|
|
||||||
0 => 'user',
|
|
||||||
],
|
|
||||||
'data' => [],
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'event_type' => 'state_change',
|
'event_type' => 'state_change',
|
||||||
'at' => 1718495999,
|
|
||||||
'by' => [
|
|
||||||
0 => 'user',
|
|
||||||
],
|
|
||||||
'data' => [
|
|
||||||
'new_state' => 'open',
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'currentState' => 'open',
|
'currentState' => 'open',
|
||||||
'updatedAt' => $t->getUpdatedAt()->getTimestamp(),
|
'updatedAt' => $t->getUpdatedAt()->getTimestamp(),
|
||||||
'updatedBy' => ['user'],
|
'updatedBy' => ['user'],
|
||||||
'emergency' => 'no',
|
'emergency' => 'no',
|
||||||
|
'caller' => null,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -165,6 +155,36 @@ class TicketNormalizerTest extends KernelTestCase
|
|||||||
'updatedAt' => $ticket->getUpdatedAt()->getTimestamp(),
|
'updatedAt' => $ticket->getUpdatedAt()->getTimestamp(),
|
||||||
'updatedBy' => ['user'],
|
'updatedBy' => ['user'],
|
||||||
'emergency' => 'yes',
|
'emergency' => 'yes',
|
||||||
|
'caller' => null,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
// ticket with caller
|
||||||
|
$ticket = new Ticket();
|
||||||
|
$ticket->setCreatedAt(new \DateTimeImmutable('2024-06-16T00:00:00'));
|
||||||
|
$ticket->setUpdatedAt(new \DateTimeImmutable('2024-06-16T00:00:00'));
|
||||||
|
new CallerHistory(new Person(), $ticket, new \DateTimeImmutable('2024-04-01T12:00:00'));
|
||||||
|
|
||||||
|
yield [
|
||||||
|
$ticket,
|
||||||
|
[
|
||||||
|
'type' => 'ticket_ticket',
|
||||||
|
'createdAt' => $ticket->getCreatedAt()?->getTimestamp(),
|
||||||
|
'createdBy' => null,
|
||||||
|
'id' => null,
|
||||||
|
'externalRef' => '',
|
||||||
|
'currentPersons' => [],
|
||||||
|
'currentAddressees' => [],
|
||||||
|
'currentInputs' => [],
|
||||||
|
'currentMotive' => null,
|
||||||
|
'history' => [
|
||||||
|
['event_type' => 'set_caller'],
|
||||||
|
],
|
||||||
|
'currentState' => 'open',
|
||||||
|
'updatedAt' => $ticket->getUpdatedAt()->getTimestamp(),
|
||||||
|
'updatedBy' => null,
|
||||||
|
'emergency' => 'no',
|
||||||
|
'caller' => ['person'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -224,6 +244,11 @@ class TicketNormalizerTest extends KernelTestCase
|
|||||||
'json',
|
'json',
|
||||||
['groups' => 'read']
|
['groups' => 'read']
|
||||||
)->will(fn ($args): array => $args[0]);
|
)->will(fn ($args): array => $args[0]);
|
||||||
|
$normalizer->normalize(
|
||||||
|
Argument::that(fn ($arg) => is_array($arg) && 1 === count($arg) && array_key_exists('new_caller', $arg)),
|
||||||
|
'json',
|
||||||
|
['groups' => 'read']
|
||||||
|
)->will(fn ($args): array => ['new_caller' => ['dummy']]);
|
||||||
|
|
||||||
// datetime
|
// datetime
|
||||||
$normalizer->normalize(Argument::type(\DateTimeImmutable::class), 'json', Argument::type('array'))
|
$normalizer->normalize(Argument::type(\DateTimeImmutable::class), 'json', Argument::type('array'))
|
||||||
@ -231,6 +256,9 @@ class TicketNormalizerTest extends KernelTestCase
|
|||||||
// user
|
// user
|
||||||
$normalizer->normalize(Argument::type(User::class), 'json', Argument::type('array'))
|
$normalizer->normalize(Argument::type(User::class), 'json', Argument::type('array'))
|
||||||
->willReturn(['user']);
|
->willReturn(['user']);
|
||||||
|
// person
|
||||||
|
$normalizer->normalize(Argument::type(Person::class), 'json', Argument::type('array'))
|
||||||
|
->willReturn(['person']);
|
||||||
// motive
|
// motive
|
||||||
$normalizer->normalize(Argument::type(Motive::class), 'json', Argument::type('array'))->willReturn(['type' => 'motive', 'id' => 0]);
|
$normalizer->normalize(Argument::type(Motive::class), 'json', Argument::type('array'))->willReturn(['type' => 'motive', 'id' => 0]);
|
||||||
// person history
|
// person history
|
||||||
|
Loading…
x
Reference in New Issue
Block a user