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/CompanyCreateCept.php
<?php

$I = new ApiTester($scenario);

$I->wantTo('create companies and see result');

$I->login();

$I->comment('creating a new company successfully');
$faker = \Faker\Factory::create();
$companyTypes = array_map('intval', $I->grabColumnFromDatabase('company_type', 'id'));
$owners = array_map('intval', $I->grabColumnFromDatabase('user', 'id'));
$companyData = [
    'name' => $faker->company,
    'company_type_id' => $faker->randomElement($companyTypes),
    'owner_id' => $faker->randomElement($owners),
    'website' => $faker->url,
    'phone' => $faker->phoneNumber,
    'address_1' => $faker->city,
    'address_2' => $faker->streetAddress,
    'address_3' => $faker->address,
    'postal_town' => $faker->city,
    'post_code' => $faker->postcode,
    'next_action_at' => $faker->date('d/m/Y'),
    'notes' => $faker->text,
    'location' => $faker->address,
    'longitude' => $faker->longitude,
    'latitude' => $faker->latitude,
];
$I->sendPOST('companies', $companyData);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::CREATED);
$I->seeResponseIsJson();
$I->seeResponseContainsJson($companyData);
$I->seeResponseJsonMatchesJsonPath('$.id');
unset($companyData['next_action_at']); /** @todo fix this */
$I->seeInDatabase('company', $companyData);

$I->comment('validating new company');
$companyData = [
    'name' => $faker->company,
];
$I->sendPOST('companies', $companyData);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::UNPROCESSABLE_ENTITY);