Skip to content

Commit

Permalink
Merge pull request #1945 from MTES-MCT/feature/1942-no-notification-e…
Browse files Browse the repository at this point in the history
…sabora-waiting-status

[BO - Notification Email] SISH/SCHS
  • Loading branch information
hmeneuvrier authored Nov 17, 2023
2 parents 9911440 + 5268763 commit 0474bd7
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 37 deletions.
20 changes: 12 additions & 8 deletions src/Factory/Esabora/DossierMessageSCHSFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
19 changes: 13 additions & 6 deletions src/Service/Esabora/EsaboraManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Service/Esabora/Response/DossierStateSCHSResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
26 changes: 13 additions & 13 deletions src/Service/Esabora/Response/DossierStateSISHResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 15 additions & 2 deletions tests/Functional/Manager/Esabora/EsaboraManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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);
Expand All @@ -107,34 +110,44 @@ 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 => [
'2022-1',
'etat_importe.json',
'accepté via Esabora',
Affectation::STATUS_ACCEPTED,
Suivi::TYPE_AUTO,
true, // suivi mail sent
];

yield EsaboraStatus::ESABORA_CLOSED->value => [
'2022-10',
'etat_termine.json',
'cloturé via Esabora',
Affectation::STATUS_CLOSED,
Suivi::TYPE_AUTO,
true, // suivi mail sent
];

yield EsaboraStatus::ESABORA_REFUSED->value => [
'2022-2',
'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 => [
'2022-2',
'../../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
];
}
}
34 changes: 34 additions & 0 deletions tests/Unit/Factory/Esabora/DossierMessageSCHSFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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+'];
}
}

0 comments on commit 0474bd7

Please sign in to comment.