Fix issues found during normal scenario testing. #727
This commit is contained in:
parent
675bca1592
commit
987c865620
5 changed files with 56 additions and 22 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Ramcar;
|
||||
namespace App\Insurance;
|
||||
|
||||
use App\Ramcar\NameValue;
|
||||
|
||||
class ClientType extends NameValue
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace App\Ramcar;
|
||||
namespace App\Insurance;
|
||||
|
||||
use App\Ramcar\NameValue;
|
||||
|
||||
class LineType extends NameValue
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,14 +2,23 @@
|
|||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Entity\MotorVehicleType;
|
||||
|
||||
use App\Insurance\ClientData;
|
||||
use App\Insurance\LineType;
|
||||
use App\Insurance\ClientType;
|
||||
|
||||
class InsuranceClientDataValidator
|
||||
class InsuranceDataValidator
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->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()))
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue