This commit is contained in:
@@ -22,7 +22,7 @@ use App\DotsAPI\Fetcher\v2\AuthApiSender;
|
|||||||
use App\Http\Resources\API\v2\CartItemCollection;
|
use App\Http\Resources\API\v2\CartItemCollection;
|
||||||
|
|
||||||
use App\Models\Validation\UserValidationByMatrixUsername;
|
use App\Models\Validation\UserValidationByMatrixUsername;
|
||||||
use App\Models\Validation\CityValidationByName;
|
use App\Models\Validation\Validators\Informative\Factories\CityInformativeValidatorByNameFactory;
|
||||||
use App\Models\Validation\Validators\Informative\Factories\CompanyInformativeValidatorByNameFactory;
|
use App\Models\Validation\Validators\Informative\Factories\CompanyInformativeValidatorByNameFactory;
|
||||||
use App\Models\Validation\Validators\Informative\Factories\ItemInformativeValidatorByNameFactory;
|
use App\Models\Validation\Validators\Informative\Factories\ItemInformativeValidatorByNameFactory;
|
||||||
|
|
||||||
@@ -123,9 +123,9 @@ class CartController extends Controller
|
|||||||
if(!$validator->isValid())
|
if(!$validator->isValid())
|
||||||
return response()->json($validator->getMessageMap());
|
return response()->json($validator->getMessageMap());
|
||||||
|
|
||||||
$validator = new CityValidationByName($cityName);
|
$validator = (new CityInformativeValidatorByNameFactory($cityName))->create();
|
||||||
if(!$validator->isValid())
|
if(!$validator->isValid())
|
||||||
return response()->json($validator->getMessageMap());
|
return response()->json($validator->getOkStatus());
|
||||||
|
|
||||||
// Get objects
|
// Get objects
|
||||||
$user = User::where('matrix_username', $matrixUsername)->first();
|
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Validation\Validators\Informative\Factories;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\Informative\Factories\InformativeValidatorByNameFactory;
|
||||||
|
use App\Models\Validation\Validators\Informative\InformativeValidator;
|
||||||
|
use App\Models\Validation\Messages\Factories\MessageByNameFactory;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\Validator;
|
||||||
|
use App\Models\Validation\Validators\CityValidatorByName;
|
||||||
|
|
||||||
|
class CityInformativeValidatorByNameFactory extends InformativeValidatorByNameFactory
|
||||||
|
{
|
||||||
|
public function __construct(string $name)
|
||||||
|
{
|
||||||
|
$this->setMessages((new MessageByNameFactory('city'))->create());
|
||||||
|
|
||||||
|
$this->setName($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValidatorByName(InformativeValidator $okValidator): Validator
|
||||||
|
{
|
||||||
|
return new CityValidatorByName($this->name, $okValidator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
use App\Models\Validation\Validators\Informative\Factories\CityInformativeValidatorByNameFactory;
|
||||||
|
|
||||||
|
class CityInformativeValidatorByNameFactoryTest extends TestCase
|
||||||
|
{
|
||||||
|
public function dataProvider() {
|
||||||
|
return [
|
||||||
|
'Found Case' => [
|
||||||
|
'name' => 'testCity',
|
||||||
|
'key' => 'ok',
|
||||||
|
'message' => 'A city with the name is valid.',
|
||||||
|
'isValid' => true,
|
||||||
|
],
|
||||||
|
'Not Found Case' => [
|
||||||
|
'name' => '404 City',
|
||||||
|
'key' => 'error',
|
||||||
|
'message' => 'A city with the name does not exist!!!',
|
||||||
|
'isValid' => false,
|
||||||
|
],
|
||||||
|
'Invalid Case' => [
|
||||||
|
'name' => '',
|
||||||
|
'key' => 'error',
|
||||||
|
'message' => 'The city name is empty, please, write the name!!!',
|
||||||
|
'isValid' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataProvider
|
||||||
|
*/
|
||||||
|
public function testValidatorFactory(string $name, string $key, string $message, bool $isValid): void
|
||||||
|
{
|
||||||
|
$factory = new CityInformativeValidatorByNameFactory($name);
|
||||||
|
$validator = $factory->create();
|
||||||
|
|
||||||
|
$this->assertEquals($validator->getMessage(), $message);
|
||||||
|
$this->assertEquals($validator->getOkStatus(), [$key => $message]);
|
||||||
|
$this->assertEquals($validator->isValid(), $isValid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user