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)%"
|
$username: "%env(INSURANCE_USERNAME)%"
|
||||||
$password: "%env(INSURANCE_PASSWORD)%"
|
$password: "%env(INSURANCE_PASSWORD)%"
|
||||||
$token: "%env(INSURANCE_TOKEN)%"
|
$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 Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
use App\Service\InsuranceConnector;
|
use App\Service\InsuranceConnector;
|
||||||
|
use App\Service\InsuranceDataValidator;
|
||||||
|
|
||||||
use App\Insurance\ClientData;
|
use App\Insurance\ClientData;
|
||||||
|
use App\Insurance\ClientType;
|
||||||
|
use App\Insurance\LineType;
|
||||||
|
|
||||||
class TestInsuranceConnectorCommand extends Command
|
class TestInsuranceConnectorCommand extends Command
|
||||||
{
|
{
|
||||||
protected $insurance;
|
protected $insurance;
|
||||||
|
protected $ins_validator;
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
|
|
@ -22,9 +26,10 @@ class TestInsuranceConnectorCommand extends Command
|
||||||
->setHelp('Test the create insuranace application service.');
|
->setHelp('Test the create insuranace application service.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(InsuranceConnector $insurance)
|
public function __construct(InsuranceConnector $insurance, InsuranceDataValidator $ins_validator)
|
||||||
{
|
{
|
||||||
$this->insurance = $insurance;
|
$this->insurance = $insurance;
|
||||||
|
$this->ins_validator = $ins_validator;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
@ -34,7 +39,7 @@ class TestInsuranceConnectorCommand extends Command
|
||||||
$client_data = new ClientData();
|
$client_data = new ClientData();
|
||||||
|
|
||||||
// set client info part
|
// set client info part
|
||||||
$client_data->setClientType('I')
|
$client_data->setClientType(ClientType::INDIVIDUAL)
|
||||||
->setFirstName('Test')
|
->setFirstName('Test')
|
||||||
->setMiddleName('Resq')
|
->setMiddleName('Resq')
|
||||||
->setSurname('Customer')
|
->setSurname('Customer')
|
||||||
|
|
@ -63,14 +68,18 @@ class TestInsuranceConnectorCommand extends Command
|
||||||
->setYearModel('2020')
|
->setYearModel('2020')
|
||||||
->setMvTypeID(1)
|
->setMvTypeID(1)
|
||||||
->setBodyType('SEDAN')
|
->setBodyType('SEDAN')
|
||||||
->setLine('pcoc')
|
->setLine(LineType::PRIVATE_CAR)
|
||||||
->setPublic(false);
|
->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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Ramcar;
|
namespace App\Insurance;
|
||||||
|
|
||||||
|
use App\Ramcar\NameValue;
|
||||||
|
|
||||||
class ClientType extends NameValue
|
class ClientType extends NameValue
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Ramcar;
|
namespace App\Insurance;
|
||||||
|
|
||||||
|
use App\Ramcar\NameValue;
|
||||||
|
|
||||||
class LineType extends NameValue
|
class LineType extends NameValue
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,23 @@
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
use App\Entity\MotorVehicleType;
|
use App\Entity\MotorVehicleType;
|
||||||
|
|
||||||
use App\Insurance\ClientData;
|
use App\Insurance\ClientData;
|
||||||
use App\Insurance\LineType;
|
use App\Insurance\LineType;
|
||||||
use App\Insurance\ClientType;
|
use App\Insurance\ClientType;
|
||||||
|
|
||||||
class InsuranceClientDataValidator
|
class InsuranceDataValidator
|
||||||
{
|
{
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
}
|
||||||
|
|
||||||
public function validateClientData(ClientData$client_data)
|
public function validateClientData(ClientData$client_data)
|
||||||
{
|
{
|
||||||
// client type is required
|
// client type is required
|
||||||
|
|
@ -20,10 +29,10 @@ class InsuranceClientDataValidator
|
||||||
}
|
}
|
||||||
|
|
||||||
// client type values should either be C or I
|
// client type values should either be C or I
|
||||||
if (($client_data->getClientType() != ClientType::CORPORATE) ||
|
if (($client_data->getClientType() !== ClientType::CORPORATE) &&
|
||||||
($client_type->ClientType() != ClientType::INDIVIDUAL))
|
($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;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,10 +184,17 @@ class InsuranceClientDataValidator
|
||||||
return $error;
|
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
|
// body type is required
|
||||||
if ($client_data->getBodyType())
|
if (empty($client_data->getBodyType()))
|
||||||
{
|
{
|
||||||
$error = 'Vehicle body type is required.';
|
$error = 'Vehicle body type is required.';
|
||||||
return $error;
|
return $error;
|
||||||
|
|
@ -192,9 +208,9 @@ class InsuranceClientDataValidator
|
||||||
}
|
}
|
||||||
|
|
||||||
// check line if valid
|
// check line if valid
|
||||||
if (($client_data->getLine() !== LineType::PRIVATE_CAR) ||
|
if (($client_data->getLine() !== LineType::PRIVATE_CAR) &&
|
||||||
($client_data->getLine() !== LineType::PRIVATE_MOTORCYCLE) ||
|
($client_data->getLine() !== LineType::PRIVATE_MOTORCYCLE) &&
|
||||||
($client_data->getLine() !== LineType::COMMERCIAL_VEHICLE) ||
|
($client_data->getLine() !== LineType::COMMERCIAL_VEHICLE) &&
|
||||||
($client_data->getLine() !== LineType::PUBLIC_MOTORCYCLE))
|
($client_data->getLine() !== LineType::PUBLIC_MOTORCYCLE))
|
||||||
{
|
{
|
||||||
$error = 'Invalid line type.';
|
$error = 'Invalid line type.';
|
||||||
|
|
@ -202,9 +218,9 @@ class InsuranceClientDataValidator
|
||||||
}
|
}
|
||||||
|
|
||||||
// check line type and flag_public combination
|
// check line type and flag_public combination
|
||||||
// if line type is MCOC, flag_public should be false
|
// if line type is MCOC/private motorcycle, flag_public should be false
|
||||||
// if line type is LCOC, flag_public should be true
|
// if line type is LCOC/public motorcycle, flag_public should be true
|
||||||
if ($client_data->getLine() == LineType::MCOC)
|
if ($client_data->getLine() == LineType::PRIVATE_MOTORCYCLE)
|
||||||
{
|
{
|
||||||
if ($client_data->isPublic())
|
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()))
|
if (!($client_data->isPublic()))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue