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