From f85bc047b8493b70d7a22964984053045de2bcb3 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 29 Aug 2023 17:02:59 +0300 Subject: [PATCH] Refactor to use CompanyInformativeValidatorByNameFactory. --- .../Controllers/API/v2/CartController.php | 6 +-- .../Validation/CompanyValidationByName.php | 18 -------- .../Messages/CompanyMessagesFactory.php | 20 --------- .../CompanyValidationByNameTest.php | 45 ------------------- 4 files changed, 3 insertions(+), 86 deletions(-) delete mode 100644 app/Models/Validation/CompanyValidationByName.php delete mode 100644 app/Models/Validation/Messages/CompanyMessagesFactory.php delete mode 100644 tests/Feature/Validation/CompanyValidationByNameTest.php diff --git a/app/Http/Controllers/API/v2/CartController.php b/app/Http/Controllers/API/v2/CartController.php index 5f2817c..1bdb782 100644 --- a/app/Http/Controllers/API/v2/CartController.php +++ b/app/Http/Controllers/API/v2/CartController.php @@ -23,7 +23,7 @@ use App\Http\Resources\API\v2\CartItemCollection; use App\Models\Validation\UserValidationByMatrixUsername; use App\Models\Validation\CityValidationByName; -use App\Models\Validation\CompanyValidationByName; +use App\Models\Validation\Messages\Factories\CompanyInformativeValidatorByNameFactory; use App\Models\Validation\Messages\Factories\ItemInformativeValidatorByNameFactory; class CartController extends Controller @@ -166,9 +166,9 @@ class CartController extends Controller if(!$validator->isValid()) return response()->json($validator->getMessageMap()); - $validator = new CompanyValidationByName($companyName); + $validator = (new CompanyInformativeValidatorByNameFactory($companyName))->create(); if(!$validator->isValid()) - return response()->json($validator->getMessageMap()); + return response()->json($validator->getOkStatus()); // Get objects $user = User::where('matrix_username', $matrixUsername)->first(); diff --git a/app/Models/Validation/CompanyValidationByName.php b/app/Models/Validation/CompanyValidationByName.php deleted file mode 100644 index 684a706..0000000 --- a/app/Models/Validation/CompanyValidationByName.php +++ /dev/null @@ -1,18 +0,0 @@ -create(), - ); - } -} diff --git a/app/Models/Validation/Messages/CompanyMessagesFactory.php b/app/Models/Validation/Messages/CompanyMessagesFactory.php deleted file mode 100644 index bc3d6f6..0000000 --- a/app/Models/Validation/Messages/CompanyMessagesFactory.php +++ /dev/null @@ -1,20 +0,0 @@ - 'A company with the name is valid.', - 'not_found' => 'A company with the name does not exist!!!', - 'invalid_name' => 'The company name is empty, please, write the name!!!', - ]; - - public function create() - { - return new BaseMessages($this->messages); - } -} - diff --git a/tests/Feature/Validation/CompanyValidationByNameTest.php b/tests/Feature/Validation/CompanyValidationByNameTest.php deleted file mode 100644 index 61c3be2..0000000 --- a/tests/Feature/Validation/CompanyValidationByNameTest.php +++ /dev/null @@ -1,45 +0,0 @@ - [ - 'name' => '', - 'key' => 'error', - 'message' => 'The company name is empty, please, write the name!!!', - 'isValid' => false, - ], - 'Not Found Case' => [ - 'name' => '404 Company', - 'key' => 'error', - 'message' => 'A company with the name does not exist!!!', - 'isValid' => false, - ], - 'Found Case' => [ - 'name' => 'testCompany', - 'key' => 'ok', - 'message' => 'A company with the name is valid.', - 'isValid' => true, - ] - ]; - } - - /** - * @dataProvider dataProvider - */ - public function testCompanyValidationWithName(string $name, string $key, string $message, bool $isValid): void - { - $validator = new CompanyValidationByName($name); - $json = $validator->getMessageMap(); - - $this->assertEquals($json[$key], $message); - $this->assertEquals($validator->isValid(), $isValid); - } -}