From 18ad749a1d2991d2f8da8f0215de34070f125c98 Mon Sep 17 00:00:00 2001 From: Jack Goodby Date: Thu, 19 Dec 2024 12:13:19 +0000 Subject: [PATCH] DDLS-360 Add new clients found in the LayDeputy csv (#1771) * Clients that are associated with existing deputies are now created automatically as part of the daily ingest * Report are also created with the corresponding report type and reporting period, and attached to the newly created clients * Logic added to check that discharged clients aren't recreated for the same deputy --------- Co-authored-by: Gugandeep Chani --- api/app/src/Command/ProcessLayCSVCommand.php | 12 +- api/app/src/Entity/Client.php | 2 +- api/app/src/Repository/ClientRepository.php | 18 ++- .../Repository/PreRegistrationRepository.php | 43 +++++++ api/app/src/Repository/UserRepository.php | 19 +++ api/app/src/v2/Assembler/ClientAssembler.php | 23 ++++ .../CSVDeputyshipProcessing.php | 6 + .../Uploader/LayDeputyshipUploader.php | 108 +++++++++++++++++- .../bootstrap/v2/Registration/IngestTrait.php | 68 +++++++++++ .../registration/ingest.lay.sirius.feature | 14 ++- ...deputy-has-multiple-client-deputyships.csv | 3 + .../lay-2-valid-rows-not-unique.csv | 4 +- .../Unit/Command/ProcessLayCSVCommandTest.php | 8 ++ .../Uploader/LayDeputyshipUploaderTest.php | 10 +- 14 files changed, 325 insertions(+), 13 deletions(-) create mode 100644 api/app/tests/Behat/fixtures/sirius-csvs/lay-2-rows-deputy-has-multiple-client-deputyships.csv diff --git a/api/app/src/Command/ProcessLayCSVCommand.php b/api/app/src/Command/ProcessLayCSVCommand.php index 324cc3cd7e..3e09879f19 100644 --- a/api/app/src/Command/ProcessLayCSVCommand.php +++ b/api/app/src/Command/ProcessLayCSVCommand.php @@ -71,7 +71,7 @@ class ProcessLayCSVCommand extends Command public function __construct( private readonly S3Client $s3, private readonly ParameterBagInterface $params, - private readonly LoggerInterface $logger, + private readonly LoggerInterface $verboseLogger, private readonly CSVDeputyshipProcessing $csvProcessing, private readonly PreRegistrationRepository $preReg, ) { @@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $logMessage = sprintf($logMessage, $layReportFile, $bucket); - $this->logger->error($logMessage); + $this->verboseLogger->error($logMessage); $this->cliOutput->writeln(sprintf('%s - failure - %s', self::JOB_NAME, $logMessage)); return Command::FAILURE; @@ -118,7 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!unlink($fileLocation)) { $logMessage = sprintf('Unable to delete file %s.', $fileLocation); - $this->logger->error($logMessage); + $this->verboseLogger->error($logMessage); $this->cliOutput->writeln( sprintf( '%s - failure - (partial) %s Output: %s', @@ -164,7 +164,7 @@ private function csvToArray(string $fileName): array } catch (\RuntimeException $e) { $logMessage = sprintf('Error processing CSV: %s', $e->getMessage()); - $this->logger->error($logMessage); + $this->verboseLogger->error($logMessage); $this->cliOutput->writeln(self::JOB_NAME.' - failure - '.$logMessage); } @@ -179,11 +179,13 @@ private function process(mixed $data): bool $chunks = array_chunk($data, self::CHUNK_SIZE); foreach ($chunks as $index => $chunk) { - $this->logger->notice(sprintf('Uploading chunk with Id: %s', $index)); + $this->verboseLogger->notice(sprintf('Uploading chunk with Id: %s', $index)); $result = $this->csvProcessing->layProcessing($chunk, $index); $this->storeOutput($result); } + $this->verboseLogger->notice('Directly creating any new Lay clients for active deputies'); + $this->csvProcessing->layProcessingHandleNewMultiClients(); return true; } diff --git a/api/app/src/Entity/Client.php b/api/app/src/Entity/Client.php index d8636facd8..a0b3f185ec 100644 --- a/api/app/src/Entity/Client.php +++ b/api/app/src/Entity/Client.php @@ -725,7 +725,7 @@ public function setAddress5(?string $address5): Client return $this; } - public function getAddress5(): string + public function getAddress5(): ?string { return $this->address5; } diff --git a/api/app/src/Repository/ClientRepository.php b/api/app/src/Repository/ClientRepository.php index 5aafd6a75c..e9ef95487c 100644 --- a/api/app/src/Repository/ClientRepository.php +++ b/api/app/src/Repository/ClientRepository.php @@ -135,6 +135,22 @@ public function findByCaseNumber(string $caseNumber): ?Client ->getOneOrNullResult(); } + public function findByCaseNumberIncludingDischarged(string $caseNumber): ?Client + { + $filter = $this->_em->getFilters()->getFilter('softdeleteable'); + $filter->disableForEntity(Client::class); + + $client = $this + ->getEntityManager() + ->createQuery('SELECT c FROM App\Entity\Client c WHERE LOWER(c.caseNumber) = LOWER(:caseNumber)') + ->setParameter('caseNumber', $caseNumber) + ->getOneOrNullResult(); + + $this->_em->getFilters()->enable('softdeleteable'); + + return $client; + } + public function findByIdIncludingDischarged(int $id): ?Client { /** @var SoftDeleteableFilter $filter */ @@ -152,7 +168,7 @@ public function findByFiltersWithCounts( $q, $offset, $limit, - $id + $id, ) { // BASE QUERY BUILDER with filters (for both count and results) $qb = $this->createQueryBuilder('c'); diff --git a/api/app/src/Repository/PreRegistrationRepository.php b/api/app/src/Repository/PreRegistrationRepository.php index e651b34f7c..fdd14c3d40 100644 --- a/api/app/src/Repository/PreRegistrationRepository.php +++ b/api/app/src/Repository/PreRegistrationRepository.php @@ -60,4 +60,47 @@ public function findByCaseNumber(string $caseNumber) ->getQuery() ->getResult(); } + + public function getNewClientsForExistingDeputiesArray(): array + { + $conn = $this->getEntityManager()->getConnection(); + + $newMultiClentsQuery = <<executeQuery($newMultiClentsQuery); + $result = $stmt->fetchAllAssociative(); + + return $result; + } } diff --git a/api/app/src/Repository/UserRepository.php b/api/app/src/Repository/UserRepository.php index f025e0bc23..c3c0d63b5c 100644 --- a/api/app/src/Repository/UserRepository.php +++ b/api/app/src/Repository/UserRepository.php @@ -419,4 +419,23 @@ public function findDeputyUidsForClient(int $clientId) return $query->getArrayResult(); } + + public function findActiveClientsCountForDeputyUid(string $deputyUid): int + { + $query = $this + ->getEntityManager() + ->createQuery("SELECT COUNT(u) FROM App\Entity\User u INNER JOIN u.clients c where c.archivedAt IS NULL and c.deletedAt IS NULL AND u.deputyUid = :deputyUid") + ->setParameter('deputyUid', $deputyUid); + + return $query->getSingleScalarResult(); + } + + public function findPrimaryUserByDeputyUid(string $deputyUid): ?User + { + $query = $this + ->getEntityManager() + ->createQuery("SELECT u FROM App\Entity\User u WHERE u.deputyUid = :deputyUid AND u.isPrimary = True") + ->setParameter('deputyUid', $deputyUid); + return $query->getSingleResult(); + } } diff --git a/api/app/src/v2/Assembler/ClientAssembler.php b/api/app/src/v2/Assembler/ClientAssembler.php index be8f8caf22..8aa062d7c7 100644 --- a/api/app/src/v2/Assembler/ClientAssembler.php +++ b/api/app/src/v2/Assembler/ClientAssembler.php @@ -8,6 +8,7 @@ use App\v2\DTO\DtoPropertySetterTrait; use App\v2\DTO\OrganisationDto; use App\v2\DTO\UserDto; +use App\v2\Registration\DTO\LayDeputyshipDto; use App\v2\Registration\DTO\OrgDeputyshipDto; class ClientAssembler @@ -131,6 +132,28 @@ public function assembleFromOrgDeputyshipDto(OrgDeputyshipDto $dto) return $client; } + + public function assembleFromLayDeputyshipDto(LayDeputyshipDto $dto) + { + $client = (new Client()) + ->setCaseNumber($dto->getCaseNumber()) + ->setFirstname($dto->getClientFirstname() ?: null) + ->setLastname($dto->getClientSurname()) + ->setAddress($dto->getClientAddress1() ?: null) + ->setAddress2($dto->getClientAddress2() ?: null) + ->setAddress3($dto->getClientAddress3() ?: null) + ->setAddress4($dto->getClientAddress4() ?: null) + ->setAddress5($dto->getClientAddress5() ?: null) + ->setPostcode($dto->getClientPostcode() ?: null) + ->setCourtDate($dto->getOrderDate() ?: null); + + if (!empty($dto->getClientPostCode())) { + $client->setPostcode($dto->getClientPostCode()); + $client->setCountry('GB'); // postcode given means a UK address is given + } + + return $client; + } private function assembleClientDeputies(array $deputies) { diff --git a/api/app/src/v2/Registration/DeputyshipProcessing/CSVDeputyshipProcessing.php b/api/app/src/v2/Registration/DeputyshipProcessing/CSVDeputyshipProcessing.php index 623f8a1e1f..0c39d3a8ee 100644 --- a/api/app/src/v2/Registration/DeputyshipProcessing/CSVDeputyshipProcessing.php +++ b/api/app/src/v2/Registration/DeputyshipProcessing/CSVDeputyshipProcessing.php @@ -62,6 +62,12 @@ public function layProcessing(array $data, ?int $chunkId) return $result; } + public function layProcessingHandleNewMultiClients(): array + { + $result = $this->layUploader->handleNewMultiClients(); + return $result; + } + public function orgProcessing(array $data) { $rowCount = count($data); diff --git a/api/app/src/v2/Registration/Uploader/LayDeputyshipUploader.php b/api/app/src/v2/Registration/Uploader/LayDeputyshipUploader.php index ebf04f405f..f84a57ef5d 100644 --- a/api/app/src/v2/Registration/Uploader/LayDeputyshipUploader.php +++ b/api/app/src/v2/Registration/Uploader/LayDeputyshipUploader.php @@ -2,16 +2,21 @@ namespace App\v2\Registration\Uploader; +use App\Entity\Client; use App\Entity\PreRegistration; use App\Entity\Report\Report; use App\Entity\User; use App\Repository\ReportRepository; +use App\v2\Assembler\ClientAssembler; +use App\v2\Registration\Assembler\SiriusToLayDeputyshipDtoAssembler; use App\v2\Registration\DTO\LayDeputyshipDto; use App\v2\Registration\DTO\LayDeputyshipDtoCollection; use App\v2\Registration\SelfRegistration\Factory\PreRegistrationCreationException; use App\v2\Registration\SelfRegistration\Factory\PreRegistrationFactory; use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\NonUniqueResultException; +use Doctrine\ORM\NoResultException; use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\ORMException; use Psr\Log\LoggerInterface; @@ -34,7 +39,9 @@ public function __construct( private EntityManagerInterface $em, private ReportRepository $reportRepository, private PreRegistrationFactory $preRegistrationFactory, - private LoggerInterface $logger + private LoggerInterface $logger, + private SiriusToLayDeputyshipDtoAssembler $assembler, + private ClientAssembler $clientAssembler, ) { } @@ -81,6 +88,105 @@ public function upload(LayDeputyshipDtoCollection $collection): array ]; } + public function handleNewMultiClients(): array + { + $preRegistrationNewClients = $this->em->getRepository(PreRegistration::class)->getNewClientsForExistingDeputiesArray(); + $clientsAdded = 0; + $errors = []; + + foreach ($preRegistrationNewClients as $preReg) { + $layDeputyshipDto = $this->assembler->assembleFromArray($preReg); + try { + $this->em->beginTransaction(); + $user = $this->handleNewUser($layDeputyshipDto); + $client = $this->handleNewClient($layDeputyshipDto, $user); + $this->handleNewReport($layDeputyshipDto, $client); + $this->commitTransactionToDatabase(); + ++$clientsAdded; + } catch (\Throwable $e) { + $message = sprintf('Error when creating additional client for deputyUID %s for case %s: %s', + $layDeputyshipDto->getDeputyUid(), + $layDeputyshipDto->getCaseNumber(), + str_replace(PHP_EOL, '', $e->getMessage()) + ); + $this->logger->warning($message); + $errors[] = $message; + continue; + } + } + + return [ + 'new-clients-found' => count($preRegistrationNewClients), + 'clients-added' => $clientsAdded, + 'errors' => $errors, + ]; + } + + private function handleNewUser(LayDeputyshipDto $dto): ?User + { + try { + $primaryDeputyUser = $this->em->getRepository(User::class)->findPrimaryUserByDeputyUid($dto->getDeputyUid()); + } catch (NoResultException|NonUniqueResultException $e) { + throw new \RuntimeException(sprintf('The primary user for deputy UID %s was either missing or not unique', $dto->getDeputyUid())); + } + + $users = $this->em->getRepository(User::class)->findBy(['deputyUid' => $dto->getDeputyUid()]); + $newSecondaryUser = clone $primaryDeputyUser; + $newSecondaryUser->setEmail('secondary-'.count($users).'-'.$primaryDeputyUser->getEmail()); + $newSecondaryUser->setIsPrimary(false); + $this->em->persist($newSecondaryUser); + + return $newSecondaryUser; + } + + private function handleNewClient(LayDeputyshipDto $dto, User $newUser): ?Client + { + $existingClient = $this->em->getRepository(Client::class)->findByCaseNumberIncludingDischarged($dto->getCaseNumber()); + + if ($existingClient instanceof Client) { + foreach ($existingClient->getUsers() as $user) { + if ($user->getDeputyUid() == $newUser->getDeputyUid()) { + throw new \RuntimeException(sprintf('a client with case number %s already exists that is associated with a user with deputy UID %s', $existingClient->getCaseNumber(), $newUser->getDeputyUid())); + } + } + } else { + $newClient = $this->clientAssembler->assembleFromLayDeputyshipDto($dto); + $newClient->addUser($newUser); + $this->em->persist($newClient); + $this->added['clients'][] = $dto->getCaseNumber(); + } + + return $newClient; + } + + private function handleNewReport(LayDeputyshipDto $dto, Client $newClient): ?Report + { + $existingReport = $newClient->getCurrentReport(); + + if ($existingReport instanceof Report) { + throw new \RuntimeException('report already exists'); + } else { + $determinedReportType = PreRegistration::getReportTypeByOrderType($dto->getTypeOfReport(), $dto->getOrderType(), PreRegistration::REALM_LAY); + + $reportStartDate = clone $dto->getOrderDate(); + $reportEndDate = clone $reportStartDate; + $reportEndDate->add(new \DateInterval('P364D')); + + $newReport = new Report( + $newClient, + $determinedReportType, + $reportStartDate, + $reportEndDate, + false + ); + + $newReport->setClient($newClient); + $this->em->persist($newReport); + } + + return $newReport; + } + private function throwExceptionIfDataTooLarge(LayDeputyshipDtoCollection $collection): void { if ($collection->count() > self::MAX_UPLOAD) { diff --git a/api/app/tests/Behat/bootstrap/v2/Registration/IngestTrait.php b/api/app/tests/Behat/bootstrap/v2/Registration/IngestTrait.php index 3ab2d1aedb..a664f55652 100644 --- a/api/app/tests/Behat/bootstrap/v2/Registration/IngestTrait.php +++ b/api/app/tests/Behat/bootstrap/v2/Registration/IngestTrait.php @@ -9,6 +9,7 @@ use App\Entity\Organisation; use App\Entity\PreRegistration; use App\Entity\Report\Report; +use App\Entity\User; use App\Tests\Behat\BehatException; use Behat\Gherkin\Node\TableNode; use Symfony\Component\Console\Input\ArrayInput; @@ -1107,6 +1108,73 @@ public function iRunTheLayCsvCommandTheFileContainsNewPreRegistrationEntitesForT $this->uploadCsvAndCountCreatedEntities($this->csvFileName); } + /** + * @Given the Lay deputy with deputy UID :deputyUid has :deputyClientCount associated active clients + */ + public function theLayDeputyWithDeputyUidHasAssociatedClient($deputyUid, $deputyClientCount): void + { + $clientCount = $this->em + ->getRepository(User::class) + ->findActiveClientsCountForDeputyUid($deputyUid); + + if ($clientCount != $deputyClientCount) { + throw new BehatException(sprintf("Unexpected number of active clients associated with this Deputy UID. Expected: '%s', got '%s'", $deputyClientCount, $clientCount)); + } + } + + /** + * @Then the client with case number :caseNumber should have the address :fullAddress + */ + public function clientWithCaseNumberShouldHaveAddress(string $caseNumber, string $fullAddress): void + { + $client = $this->em + ->getRepository(Client::class) + ->findOneBy(['caseNumber' => $caseNumber]); + + if (is_null($client)) { + throw new BehatException(sprintf('Client not found with case number "%s"', $caseNumber)); + } + + $actualClientAddress = sprintf( + '%s, %s, %s, %s, %s, %s', + $client->getAddress() ?? '', + $client->getAddress2() ?? '', + $client->getAddress3() ?? '', + $client->getAddress4() ?? '', + $client->getAddress5() ?? '', + $client->getPostcode() ?? '' + ); + + $this->assertStringEqualsString( + $fullAddress, + $actualClientAddress, + 'Comparing address defined in step against actual client address' + ); + } + + /** + * @Then the client with case number :caseNumber should have an active report with type :expectedReportType + */ + public function clientWithCaseNumberShouldHaveReportType(string $caseNumber, string $expectedReportType): void + { + /* @var Client $client */ + $client = $this->em + ->getRepository(Client::class) + ->findOneBy(['caseNumber' => $caseNumber]); + + if (is_null($client)) { + throw new BehatException(sprintf('Client not found with case number "%s"', $caseNumber)); + } + + $report = $client->getCurrentReport(); + + $this->assertStringEqualsString( + $report->getType(), + $expectedReportType, + 'Comparing expected report type with actual report type' + ); + } + protected function runCSVCommand(string $type, string $fileName) { $command = ('lay' === $type) ? diff --git a/api/app/tests/Behat/features-v2/registration/ingest.lay.sirius.feature b/api/app/tests/Behat/features-v2/registration/ingest.lay.sirius.feature index cefb7873a0..a82960019d 100644 --- a/api/app/tests/Behat/features-v2/registration/ingest.lay.sirius.feature +++ b/api/app/tests/Behat/features-v2/registration/ingest.lay.sirius.feature @@ -22,12 +22,24 @@ Feature: Lay CSV data ingestion - sirius source data And the count of the new 'lay' entities added should be in the command output @super-admin - Scenario: Uploading a Lay CSV that contains contains a row with an invalid report type + Scenario: Uploading a Lay CSV that contains a row with an invalid report type Given a csv has been uploaded to the sirius bucket with the file 'lay-1-row-invalid-report-type-1-valid-row.csv' When I run the lay CSV command the file has 1 row with an invalid report type and 1 valid row Then the new 'lay' entities should be added to the database And the count of the new 'lay' entities added should be in the command output + @super-admin + Scenario: Uploading a Lay CSV that contains details of a new deputyship for an existing Lay deputy with a single active client + Given the Lay deputy with deputy UID 700761111001 has 1 associated active clients + And a csv has been uploaded to the sirius bucket with the file 'lay-2-rows-deputy-has-multiple-client-deputyships.csv' + When I run the lay CSV command the file contains 2 new pre-registration entities + And the Lay deputy with deputy UID 700761111001 has 2 associated active clients + And the client with case number '12345673' should have the address '64 zoo lane, vrombaut, beebies, london, , cl1 3nt' + And the client with case number '12345673' should have an active report with type '102' + When I run the lay CSV command the file contains 2 new pre-registration entities + And the Lay deputy with deputy UID 700761111001 has 2 associated active clients + And the client with case number '12345673' should have an active report with type '102' + # Needs further rewrite so we're gracefully handling missing columns & not just stopping the process. # Currently throws critical error # @super-admin diff --git a/api/app/tests/Behat/fixtures/sirius-csvs/lay-2-rows-deputy-has-multiple-client-deputyships.csv b/api/app/tests/Behat/fixtures/sirius-csvs/lay-2-rows-deputy-has-multiple-client-deputyships.csv new file mode 100644 index 0000000000..33d1bcc084 --- /dev/null +++ b/api/app/tests/Behat/fixtures/sirius-csvs/lay-2-rows-deputy-has-multiple-client-deputyships.csv @@ -0,0 +1,3 @@ +Case,ClientFirstname,ClientSurname,ClientAddress1,ClientAddress2,ClientAddress3,ClientAddress4,ClientAddress5,ClientPostcode,DeputyUid,DeputyFirstname,DeputySurname,DeputyAddress1,DeputyAddress2,DeputyAddress3,DeputyAddress4,DeputyAddress5,DeputyPostcode,ReportType,MadeDate,OrderType,CoDeputy,Hybrid,CourtOrderUid +61111001,Client 1,Clientsurname,Client Road,,,,,CL1 3NT,700761111001,Lay-OPG102-User-1,User,ABC Road,,,,,AB1 2CD,OPG102,2011-04-14,pfa,no,SINGLE,45123468745 +12345673,Client 2,SecondClient,64 Zoo Lane,Vrombaut,Beebies,London,,CL1 3NT,700761111001,Julie,DUCK,ABC Road,,,,,D3P UTY,OPG102,2011-04-15,pfa,no,SINGLE,34518742346 diff --git a/api/app/tests/Behat/fixtures/sirius-csvs/lay-2-valid-rows-not-unique.csv b/api/app/tests/Behat/fixtures/sirius-csvs/lay-2-valid-rows-not-unique.csv index dd8f9de644..e2bb8f47f2 100644 --- a/api/app/tests/Behat/fixtures/sirius-csvs/lay-2-valid-rows-not-unique.csv +++ b/api/app/tests/Behat/fixtures/sirius-csvs/lay-2-valid-rows-not-unique.csv @@ -1,3 +1,3 @@ Case,ClientFirstname,ClientSurname,ClientAddress1,ClientAddress2,ClientAddress3,ClientAddress4,ClientAddress5,ClientPostcode,DeputyUid,DeputyFirstname,DeputySurname,DeputyAddress1,DeputyAddress2,DeputyAddress3,DeputyAddress4,DeputyAddress5,DeputyPostcode,ReportType,MadeDate,OrderType,CoDeputy,Hybrid -31313135,JAMIE,HUEY,1 Victoria Road,Harrow,London,,,N7,19371937,Julie,DUCK,2 London Road,Padstow,Brentwood,Cornwall,,B1,OPG102,2011-04-14,pfa,no,SINGLE -31313135,JAMIE,HUEY,1 Victoria Road,Harrow,London,,,N7,19371938,Julie,DUCK,2 London Road,Padstow,Brentwood,Cornwall,,B1,OPG102,2011-04-15,pfa,no,SINGLE +31313135,JAMIE,HUEY,1 Victoria Road,Harrow,London,,,N7,1937193700,Julie,DUCK,2 London Road,Padstow,Brentwood,Cornwall,,B1,OPG102,2011-04-14,pfa,no,SINGLE +31313135,JAMIE,HUEY,1 Victoria Road,Harrow,London,,,N7,1937193800,Julie,DUCK,2 London Road,Padstow,Brentwood,Cornwall,,B1,OPG102,2011-04-15,pfa,no,SINGLE diff --git a/api/app/tests/Unit/Command/ProcessLayCSVCommandTest.php b/api/app/tests/Unit/Command/ProcessLayCSVCommandTest.php index bb5d2984bf..19be114677 100644 --- a/api/app/tests/Unit/Command/ProcessLayCSVCommandTest.php +++ b/api/app/tests/Unit/Command/ProcessLayCSVCommandTest.php @@ -15,6 +15,7 @@ use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Tester\CommandTester; use App\Command\ProcessLayCSVCommand; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; @@ -75,6 +76,13 @@ public function testExecuteWithSuccessfulFilePull(): void 'source' => 'sirius', ]); + $this->csvProcessing->layProcessingHandleNewMultiClients() + ->shouldBeCalled() + ->willReturn([ + 'added' => 0, + 'errors' => [] + ]); + $this->commandTester->execute(['csv-filename' => $this->csvFilename]); $this->commandTester->assertCommandIsSuccessful(); $output = $this->commandTester->getDisplay(); diff --git a/api/app/tests/Unit/v2/Registration/Uploader/LayDeputyshipUploaderTest.php b/api/app/tests/Unit/v2/Registration/Uploader/LayDeputyshipUploaderTest.php index 4448590d8a..5e1f7aa0ba 100644 --- a/api/app/tests/Unit/v2/Registration/Uploader/LayDeputyshipUploaderTest.php +++ b/api/app/tests/Unit/v2/Registration/Uploader/LayDeputyshipUploaderTest.php @@ -15,8 +15,9 @@ use Doctrine\ORM\EntityManager; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -class LayDeputyshipUploaderTest extends TestCase +class LayDeputyshipUploaderTest extends KernelTestCase { /** @var EntityManager|\PHPUnit_Framework_MockObject_MockObject */ protected $em; @@ -35,16 +36,21 @@ class LayDeputyshipUploaderTest extends TestCase protected function setUp(): void { + $container = static::getContainer(); $this->em = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock(); $this->reportRepository = $this->getMockBuilder(ReportRepository::class)->disableOriginalConstructor()->getMock(); $this->factory = $this->getMockBuilder(PreRegistrationFactory::class)->disableOriginalConstructor()->enableArgumentCloning()->getMock(); $this->logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock(); + $layDeputyshipDtoAssembler = $container->get('App\v2\Registration\Assembler\SiriusToLayDeputyshipDtoAssembler'); + $clientAssembler = $container->get('App\v2\Assembler\ClientAssembler'); $this->sut = new LayDeputyshipUploader( $this->em, $this->reportRepository, $this->factory, - $this->logger + $this->logger, + $layDeputyshipDtoAssembler, + $clientAssembler ); }