From da6d260610ea003fbbe6090e5496648df14554ed Mon Sep 17 00:00:00 2001 From: Saidi Date: Wed, 15 Nov 2023 18:38:43 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=20do=20not=20notify=20by=20mail=20for=20es?= =?UTF-8?q?abora=20dossier=20=C3=A0=20traiter=20#1942?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Service/Esabora/EsaboraManager.php | 19 +++++++++++++------ .../Manager/Esabora/EsaboraManagerTest.php | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Service/Esabora/EsaboraManager.php b/src/Service/Esabora/EsaboraManager.php index fc904b3f9..544fc3279 100644 --- a/src/Service/Esabora/EsaboraManager.php +++ b/src/Service/Esabora/EsaboraManager.php @@ -6,6 +6,7 @@ use App\Entity\Enum\InterfacageType; use App\Entity\Enum\InterventionType; use App\Entity\Intervention; +use App\Entity\Suivi; use App\Entity\User; use App\Event\InterventionCreatedEvent; use App\Factory\InterventionFactory; @@ -45,15 +46,21 @@ public function synchronizeAffectationFrom( $description = $this->updateStatusFor($affectation, $adminUser, $dossierResponse); if (!empty($description)) { + $params = [ + 'domain' => 'esabora', + 'action' => 'synchronize', + 'description' => $description, + 'name_partner' => $affectation->getPartner()->getNom(), + ]; + + if (EsaboraStatus::ESABORA_WAIT->value === $dossierResponse->getSasEtat()) { + $params['type'] = Suivi::TYPE_TECHNICAL; + } + $suivi = $this->suiviManager->createSuivi( user: $adminUser, signalement: $signalement, - params: [ - 'domain' => 'esabora', - 'action' => 'synchronize', - 'description' => $description, - 'name_partner' => $affectation->getPartner()->getNom(), - ], + params: $params, ); $this->suiviManager->save($suivi); } diff --git a/tests/Functional/Manager/Esabora/EsaboraManagerTest.php b/tests/Functional/Manager/Esabora/EsaboraManagerTest.php index 912efa0b2..196c49204 100644 --- a/tests/Functional/Manager/Esabora/EsaboraManagerTest.php +++ b/tests/Functional/Manager/Esabora/EsaboraManagerTest.php @@ -54,7 +54,9 @@ public function testAffectationSynchronizedWith( string $referenceSignalement, string $filename, string $suiviDescription, - int $expectedAffectationStatus + int $expectedAffectationStatus, + int $suiviStatus, + bool $mailSent, ): void { /** @var Signalement $signalement */ $signalement = $this->entityManager->getRepository(Signalement::class)->findOneBy([ @@ -93,7 +95,8 @@ public function testAffectationSynchronizedWith( $suivi = $signalement->getSuivis()->last(); $this->assertStringContainsString($suiviDescription, $suivi->getDescription()); $this->assertFalse($suivi->getIsPublic()); - $this->assertEquals(Suivi::TYPE_AUTO, $suivi->getType()); + $this->assertEquals($suiviStatus, $suivi->getType()); + $this->assertEmailCount($mailSent ? 1 : 0); /** @var Affectation $affectationUpdated */ $affectationUpdated = $signalement->getAffectations()->get(0); @@ -107,6 +110,8 @@ public function provideDataForSynchronization(): \Generator 'etat_a_traiter.json', 'remis en attente', Affectation::STATUS_WAIT, + Suivi::TYPE_TECHNICAL, + false, // suivi mail not sent cause suivi techical ]; yield EsaboraStatus::ESABORA_ACCEPTED->value => [ @@ -114,6 +119,8 @@ public function provideDataForSynchronization(): \Generator 'etat_importe.json', 'accepté via Esabora', Affectation::STATUS_ACCEPTED, + Suivi::TYPE_AUTO, + true, // suivi mail sent ]; yield EsaboraStatus::ESABORA_CLOSED->value => [ @@ -121,6 +128,8 @@ public function provideDataForSynchronization(): \Generator 'etat_termine.json', 'cloturé via Esabora', Affectation::STATUS_CLOSED, + Suivi::TYPE_AUTO, + true, // suivi mail sent ]; yield EsaboraStatus::ESABORA_REFUSED->value => [ @@ -128,6 +137,8 @@ public function provideDataForSynchronization(): \Generator 'etat_non_importe.json', 'refusé via Esabora', Affectation::STATUS_REFUSED, + Suivi::TYPE_AUTO, + false, // suivi mail not sent cause signalement closed ]; yield EsaboraStatus::ESABORA_REJECTED->value => [ @@ -135,6 +146,8 @@ public function provideDataForSynchronization(): \Generator '../../sish/ws_etat_dossier_sas/etat_rejete.json', 'refusé via SI-SH pour motif suivant:', Affectation::STATUS_REFUSED, + Suivi::TYPE_AUTO, + false, // suivi mail not sent cause signalement closed ]; } } From 9d121359483260a068e85237e8777344fb1b5f1c Mon Sep 17 00:00:00 2001 From: Saidi Date: Thu, 16 Nov 2023 09:23:36 +0100 Subject: [PATCH 2/3] fix error exception esabora response #1942 --- .../Response/DossierStateSCHSResponse.php | 16 ++++++------ .../Response/DossierStateSISHResponse.php | 26 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Service/Esabora/Response/DossierStateSCHSResponse.php b/src/Service/Esabora/Response/DossierStateSCHSResponse.php index 623d50d53..54019448b 100644 --- a/src/Service/Esabora/Response/DossierStateSCHSResponse.php +++ b/src/Service/Esabora/Response/DossierStateSCHSResponse.php @@ -20,14 +20,14 @@ public function __construct(array $response, ?int $statusCode) if (!empty($response)) { $data = $response['rowList'][0]['columnDataList'] ?? null; if (null !== $data) { - $this->sasReference = $data[0]; - $this->sasEtat = $data[1]; - $this->id = $data[2]; - $this->numero = $data[3]; - $this->statutAbrege = $data[4]; - $this->statut = $data[5]; - $this->etat = $data[6]; - $this->dateCloture = $data[7]; + $this->sasReference = $data[0] ?? null; + $this->sasEtat = $data[1] ?? null; + $this->id = $data[2] ?? null; + $this->numero = $data[3] ?? null; + $this->statutAbrege = $data[4] ?? null; + $this->statut = $data[5] ?? null; + $this->etat = $data[6] ?? null; + $this->dateCloture = $data[7] ?? null; } else { $this->errorReason = json_encode($response); } diff --git a/src/Service/Esabora/Response/DossierStateSISHResponse.php b/src/Service/Esabora/Response/DossierStateSISHResponse.php index 164eb7327..c0df1e332 100644 --- a/src/Service/Esabora/Response/DossierStateSISHResponse.php +++ b/src/Service/Esabora/Response/DossierStateSISHResponse.php @@ -25,19 +25,19 @@ public function __construct(array $response, ?int $statusCode) if (!empty($response)) { $data = $response['rowList'][0]['columnDataList'] ?? null; if (null !== $data) { - $this->referenceDossier = $data[0]; - $this->sasEtat = $data[1]; - $this->sasDateDecision = $data[2]; - $this->sasCauseRefus = $data[3]; - $this->dossId = $data[4]; - $this->dossNum = $data[5]; - $this->dossObjet = $data[6]; - $this->dossDateCloture = $data[7]; - $this->dossStatutAbr = $data[8]; - $this->dossStatut = $data[9]; - $this->dossEtat = $data[10]; - $this->dossTypeCode = $data[11]; - $this->dossTypeLib = $data[12]; + $this->referenceDossier = $data[0] ?? null; + $this->sasEtat = $data[1] ?? null; + $this->sasDateDecision = $data[2] ?? null; + $this->sasCauseRefus = $data[3] ?? null; + $this->dossId = $data[4] ?? null; + $this->dossNum = $data[5] ?? null; + $this->dossObjet = $data[6] ?? null; + $this->dossDateCloture = $data[7] ?? null; + $this->dossStatutAbr = $data[8] ?? null; + $this->dossStatut = $data[9] ?? null; + $this->dossEtat = $data[10] ?? null; + $this->dossTypeCode = $data[11] ?? null; + $this->dossTypeLib = $data[12] ?? null; } else { $this->errorReason = json_encode($response); } From 526876319080970b409bd4ef3030329ea2e74671 Mon Sep 17 00:00:00 2001 From: Saidi Date: Thu, 16 Nov 2023 09:27:00 +0100 Subject: [PATCH 3/3] improve buildNbEnfant to prevent operation error #1942 --- .../Esabora/DossierMessageSCHSFactory.php | 20 ++++++----- .../Esabora/DossierMessageSCHSFactoryTest.php | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/Factory/Esabora/DossierMessageSCHSFactory.php b/src/Factory/Esabora/DossierMessageSCHSFactory.php index 48a70bd17..1fbfd7de5 100644 --- a/src/Factory/Esabora/DossierMessageSCHSFactory.php +++ b/src/Factory/Esabora/DossierMessageSCHSFactory.php @@ -56,18 +56,18 @@ public function createInstance(Affectation $affectation): DossierMessageSCHS private function buildCommentaire(Signalement $signalement): string { - $commentaire = 'Points signalés:\n'; + $commentaire = 'Points signalés:'.\PHP_EOL; foreach ($signalement->getCriticites() as $criticite) { - $commentaire .= '\n'.$criticite->getCritere()->getLabel().' => Etat '.$criticite->getScoreLabel(); + $commentaire .= \PHP_EOL.$criticite->getCritere()->getLabel().' => Etat '.$criticite->getScoreLabel(); } - $commentaire .= '\nPropriétaire averti: '.$signalement->getIsProprioAverti() ? 'OUI' : 'NON'; - $commentaire .= '\nAdultes: '.$signalement->getNbAdultes().' Adultes'; + $commentaire .= \PHP_EOL.'Propriétaire averti: '.$signalement->getIsProprioAverti() ? 'OUI' : 'NON'; + $commentaire .= \PHP_EOL.'Adultes: '.$signalement->getNbAdultes().' Adulte(s)'; $commentaire .= $this->buildNbEnfants($signalement); foreach ($signalement->getAffectations() as $affectation) { - $commentaire .= '\n'.$affectation->getPartner()->getNom().' => '.$affectation->getAffectationLabel(); + $commentaire .= \PHP_EOL.$affectation->getPartner()->getNom().' => '.$affectation->getAffectationLabel(); } return $commentaire; @@ -76,13 +76,17 @@ private function buildCommentaire(Signalement $signalement): string private function buildNbEnfants(Signalement $signalement) { $suffix = ''; - if (str_ends_with($signalement->getNbEnfantsM6(), '+') || str_ends_with($signalement->getNbEnfantsP6(), '+')) { + if (null !== $signalement->getNbEnfantsM6() && str_ends_with($signalement->getNbEnfantsM6(), '+') || + null !== $signalement->getNbEnfantsP6() && str_ends_with($signalement->getNbEnfantsP6(), '+') + ) { $suffix = '+'; } - $nbEnfants = str_replace('+', '', $signalement->getNbEnfantsM6()) + str_replace('+', '', $signalement->getNbEnfantsP6()); + $nbEnfantsM6 = (int) str_replace('+', '', $signalement->getNbEnfantsM6()); + $nbEnfantsP6 = (int) str_replace('+', '', $signalement->getNbEnfantsP6()); + $nbEnfants = $nbEnfantsM6 + $nbEnfantsP6; $nbEnfants .= $suffix; - return '\n'.$nbEnfants.' Enfants'; + return \PHP_EOL.$nbEnfants.' Enfant(s)'; } private function buildPiecesJointesObservation(Signalement $signalement): string diff --git a/tests/Unit/Factory/Esabora/DossierMessageSCHSFactoryTest.php b/tests/Unit/Factory/Esabora/DossierMessageSCHSFactoryTest.php index 406f50b8c..b6cfa47c6 100644 --- a/tests/Unit/Factory/Esabora/DossierMessageSCHSFactoryTest.php +++ b/tests/Unit/Factory/Esabora/DossierMessageSCHSFactoryTest.php @@ -3,6 +3,7 @@ namespace App\Tests\Unit\Factory\Esabora; use App\Entity\Enum\PartnerType; +use App\Entity\Signalement; use App\Factory\Esabora\DossierMessageSCHSFactory; use App\Service\UploadHandlerService; use App\Tests\FixturesHelper; @@ -34,4 +35,37 @@ public function testDossierMessageFactoryIsFullyCreated(): void $this->assertStringContainsString('25', $dossierMessage->getNumeroAdresseSignalement()); $this->assertStringContainsString('Rue du test', $dossierMessage->getAdresseSignalement()); } + + /** + * @dataProvider provideNbChildren + */ + public function testBuildNbEnfants(string $expectedResult, ?string $nbEnfantsM6 = null, ?string $nbEnfantsP6 = null): void + { + $uploadHandlerServiceMock = $this->createMock(UploadHandlerService::class); + $uploadHandlerServiceMock + ->expects($this->exactly(0)) + ->method('getTmpFilepath') + ->willReturn(self::FILE); + + $dossierMessageFactory = new DossierMessageSCHSFactory($uploadHandlerServiceMock); + $signalement = (new Signalement())->setNbEnfantsM6($nbEnfantsM6)->setNbEnfantsP6($nbEnfantsP6); + + $buildNbEnfantsMethod = new \ReflectionMethod(DossierMessageSCHSFactory::class, 'buildNbEnfants'); + $buildNbEnfantsMethod->setAccessible(true); + + $actualResult = $buildNbEnfantsMethod->invoke($dossierMessageFactory, $signalement); + + $this->assertStringContainsString($expectedResult, $actualResult); + } + + public function provideNbChildren(): \Generator + { + yield 'No child' => ['0 Enfant(s)', null, null]; + yield '1 children M6, 0 children P6' => ['1 Enfant(s)', '1', null]; + yield '3 children M6, 2 children P6' => ['5 Enfant(s)', '3', '2']; + yield '4+ children M6, 4+ children P6' => ['8+ Enfant(s)', '4+', '4+']; + yield '4+ children M6, 1 children P6' => ['5+ Enfant(s)', '4+', '1']; + yield '4+ children M6, 0 children P6' => ['4+ Enfant(s)', '4+', null]; + yield '0 children M6, 4+ children P6' => ['4+ Enfant(s)', null, '4+']; + } }