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);