From 987c865620e29d0f0f95264c7f8850b1468d867f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 13 Jan 2023 07:27:42 +0000 Subject: [PATCH] Fix issues found during normal scenario testing. #727 --- config/services.yaml | 5 +++ src/Command/TestInsuranceConnectorCommand.php | 23 ++++++---- src/Insurance/ClientType.php | 4 +- src/Insurance/LineType.php | 4 +- src/Service/InsuranceClientDataValidator.php | 42 +++++++++++++------ 5 files changed, 56 insertions(+), 22 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index b2460c3f..053cce20 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -336,3 +336,8 @@ services: $username: "%env(INSURANCE_USERNAME)%" $password: "%env(INSURANCE_PASSWORD)%" $token: "%env(INSURANCE_TOKEN)%" + + # insurance data validator + App\Service\InsuranceDataValidator: + arguments: + $em: "@doctrine.orm.entity_manager" diff --git a/src/Command/TestInsuranceConnectorCommand.php b/src/Command/TestInsuranceConnectorCommand.php index a2846e49..f8ac2d7f 100644 --- a/src/Command/TestInsuranceConnectorCommand.php +++ b/src/Command/TestInsuranceConnectorCommand.php @@ -8,12 +8,16 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use App\Service\InsuranceConnector; +use App\Service\InsuranceDataValidator; use App\Insurance\ClientData; +use App\Insurance\ClientType; +use App\Insurance\LineType; class TestInsuranceConnectorCommand extends Command { protected $insurance; + protected $ins_validator; protected function configure() { @@ -22,9 +26,10 @@ class TestInsuranceConnectorCommand extends Command ->setHelp('Test the create insuranace application service.'); } - public function __construct(InsuranceConnector $insurance) + public function __construct(InsuranceConnector $insurance, InsuranceDataValidator $ins_validator) { $this->insurance = $insurance; + $this->ins_validator = $ins_validator; parent::__construct(); } @@ -34,7 +39,7 @@ class TestInsuranceConnectorCommand extends Command $client_data = new ClientData(); // set client info part - $client_data->setClientType('I') + $client_data->setClientType(ClientType::INDIVIDUAL) ->setFirstName('Test') ->setMiddleName('Resq') ->setSurname('Customer') @@ -63,14 +68,18 @@ class TestInsuranceConnectorCommand extends Command ->setYearModel('2020') ->setMvTypeID(1) ->setBodyType('SEDAN') - ->setLine('pcoc') + ->setLine(LineType::PRIVATE_CAR) ->setPublic(false); - // TOOD: add validation here + $error_message = $this->ins_validator->validateClientData($client_data); + if ($error_message == null) + { + $result = $this->insurance->processApplication($client_data); - $result = $this->insurance->processApplication($client_data); - - error_log(json_encode($result)); + error_log(json_encode($result)); + } + else + error_log($error_message); return 0; } diff --git a/src/Insurance/ClientType.php b/src/Insurance/ClientType.php index a63d058d..8b28d443 100644 --- a/src/Insurance/ClientType.php +++ b/src/Insurance/ClientType.php @@ -1,6 +1,8 @@ em = $em; + } + public function validateClientData(ClientData$client_data) { // client type is required @@ -20,10 +29,10 @@ class InsuranceClientDataValidator } // client type values should either be C or I - if (($client_data->getClientType() != ClientType::CORPORATE) || - ($client_type->ClientType() != ClientType::INDIVIDUAL)) + if (($client_data->getClientType() !== ClientType::CORPORATE) && + ($client_data->getClientType() !== ClientType::INDIVIDUAL)) { - $error = 'Invalid cilent type values. Values should only be C for corporate type or I for individual.'; + $error = 'Invalid client type values. Values should only be C for corporate type or I for individual.'; return $error; } @@ -175,10 +184,17 @@ class InsuranceClientDataValidator return $error; } - // TODO: should we check if it's a valid MV type? + // check if it's a valid MV type + $mv_type_id = $client_data->getMvTypeID(); + $mv_type = $this->em->getRepository(MotorVehicleType::class)->findBy(['mv_type_id' => $mv_type_id]); + if ($mv_type == null) + { + $error = 'Invalid motor vehicle type.'; + return $error; + } // body type is required - if ($client_data->getBodyType()) + if (empty($client_data->getBodyType())) { $error = 'Vehicle body type is required.'; return $error; @@ -192,9 +208,9 @@ class InsuranceClientDataValidator } // check line if valid - if (($client_data->getLine() !== LineType::PRIVATE_CAR) || - ($client_data->getLine() !== LineType::PRIVATE_MOTORCYCLE) || - ($client_data->getLine() !== LineType::COMMERCIAL_VEHICLE) || + if (($client_data->getLine() !== LineType::PRIVATE_CAR) && + ($client_data->getLine() !== LineType::PRIVATE_MOTORCYCLE) && + ($client_data->getLine() !== LineType::COMMERCIAL_VEHICLE) && ($client_data->getLine() !== LineType::PUBLIC_MOTORCYCLE)) { $error = 'Invalid line type.'; @@ -202,9 +218,9 @@ class InsuranceClientDataValidator } // check line type and flag_public combination - // if line type is MCOC, flag_public should be false - // if line type is LCOC, flag_public should be true - if ($client_data->getLine() == LineType::MCOC) + // if line type is MCOC/private motorcycle, flag_public should be false + // if line type is LCOC/public motorcycle, flag_public should be true + if ($client_data->getLine() == LineType::PRIVATE_MOTORCYCLE) { if ($client_data->isPublic()) { @@ -213,7 +229,7 @@ class InsuranceClientDataValidator } } - if ($client_data->getLine() == LineType::LCOC) + if ($client_data->getLine() == LineType::PUBLIC_MOTORCYCLE) { if (!($client_data->isPublic())) {