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/ProjectCompaniesCept.php
<?php
/**
 * @var \Codeception\Scenario $scenario
 */

$I = new ApiTester($scenario);
$I->wantTo('change architect and contractors within the project bindings');

$I->login();

$I->comment('creating a new project');
$newProject = $I->getRandomProjectJSON();

$I->sendPOST('projects', $newProject);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::CREATED);
$I->seeResponseJsonMatchesJsonPath('$.id');
$projectId = json_decode($I->grabResponse())->id;

$I->comment('bind a new architect');
$architect = [
    'reltype_id' => 3,
    'company_type_id' => 3,
    'name' => $I->fake()->company,
    'specification' => $I->fake()->boolean,
    'location' => $I->fake()->address,
];
$I->sendPUT('projects/' . $projectId, ['relatedCompanies' => [$architect]]);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->sendGET('projects/' . $projectId . '?expand=companyProjects.company');
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$companyProject = [
    'reltype_id' => $architect['reltype_id'],
    'project_id' => $projectId,
    'location' => $architect['location'],
    'company' => [
        'company_type_id' => $architect['company_type_id'],
        'name' => $architect['name'],
        'location' => $architect['location'],
    ],
];
$I->seeResponseContainsJson(['companyProjects' => $companyProject]);

$I->comment('bind an existing main contractor');
$newCompany = [
    'name' => $I->fake()->company,
    'company_type_id' => 4,
    'owner_id' => $I->getRandomId('user'),
    'location' => $I->fake()->address,
];
$I->sendPOST('companies', $newCompany);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::CREATED);
$I->seeResponseJsonMatchesJsonPath('$.id');
$mainContractorId = json_decode($I->grabResponse())->id;

$mainContractor = [
    'reltype_id' => 4,
    'id' => $mainContractorId,
    'specification' => $I->fake()->boolean,
    'location' => $I->fake()->address,
];
$I->sendPUT('projects/' . $projectId, ['relatedCompanies' => [$mainContractor]]);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->sendGET('projects/' . $projectId . '?expand=companyProjects.company');
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$mainContractorInProject = [
    'reltype_id' => $mainContractor['reltype_id'],
    'project_id' => $projectId,
    'location' => $mainContractor['location'],
    'company' => [
        'company_type_id' => $newCompany['company_type_id'],
        'name' => $newCompany['name'],
        'location' => $newCompany['location'],
    ],
];
$I->seeResponseContainsJson(['companyProjects' => $mainContractorInProject]);