This commit is contained in:
@@ -165,7 +165,7 @@ class CartController extends Controller
|
|||||||
return response()->json($validation);
|
return response()->json($validation);
|
||||||
|
|
||||||
// check for not valid company
|
// check for not valid company
|
||||||
$validation = Company::validate_with_name($companyName);
|
$validation = Company::validateWithName($companyName);
|
||||||
if(array_key_exists('error', $validation))
|
if(array_key_exists('error', $validation))
|
||||||
return response()->json($validation);
|
return response()->json($validation);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Company extends Model
|
|||||||
return $count != 0;
|
return $count != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function validate_with_name(string $name)
|
public static function validateWithName(string $name)
|
||||||
{
|
{
|
||||||
$name = $name ?? '';
|
$name = $name ?? '';
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ class Company extends Model
|
|||||||
'error' => 'The company name is empty, please, write the name!!!'
|
'error' => 'The company name is empty, please, write the name!!!'
|
||||||
];
|
];
|
||||||
|
|
||||||
$company = company::where('name', $name)->first();
|
$company = Company::where('name', $name)->first();
|
||||||
|
|
||||||
if(!$company)
|
if(!$company)
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
|
||||||
|
class CompanyValidationTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCompanyWithEmptyName(): void
|
||||||
|
{
|
||||||
|
$json = Company::validateWithName('');
|
||||||
|
|
||||||
|
$this->assertEquals($json['error'], 'The company name is empty, please, write the name!!!');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotExistingCompanyWithName(): void
|
||||||
|
{
|
||||||
|
$name = '404 Company';
|
||||||
|
|
||||||
|
$json = Company::validateWithName($name);
|
||||||
|
|
||||||
|
$this->assertEquals($json['error'], 'A company with the name does not exist!!!');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testValidCompanyWithName(): void
|
||||||
|
{
|
||||||
|
$name = 'testCompany';
|
||||||
|
|
||||||
|
$json = Company::validateWithName($name);
|
||||||
|
|
||||||
|
$this->assertEquals($json['ok'], 'A company with the name is valid.');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user