HEX
Server: LiteSpeed
System: Linux premium260.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: aliazzsr (627)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /home/aliazzsr/api.crm.vqode.com/tests/api/ProjectStrictValidationCept.php
<?php
$I = new ApiTester($scenario);
$I->wantTo('perform strict project validation');

$I->login();

$I->comment('validating new project with unique name');
$faker = \Faker\Factory::create();
$sectors = array_map('intval', $I->grabColumnFromDatabase('sector', 'id'));

$nonuniqueProjectName = $faker->text;

$firstProject = $I->getRandomProjectJSON();
$firstProject['name'] = $nonuniqueProjectName;

$I->sendPOST('projects/validate', $firstProject);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->seeResponseIsJson();
$I->seeResponseContainsJson($firstProject);

$I->comment('save new project with unique name');
$I->sendPOST('projects', $firstProject);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::CREATED);

$I->comment('validate new project with non-unique name');
$secondProject = $I->getRandomProjectJSON();
$secondProject['name'] = $nonuniqueProjectName;
$I->sendPOST('projects/validate', $secondProject);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::UNPROCESSABLE_ENTITY);
$I->seeResponseContainsJson([
    'field' => 'name',
    'message' => 'A duplicate project with the same name has been found',
]);

$I->comment('save new project with non-unique name');
$I->sendPOST('projects', $secondProject);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::CREATED);