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/NotesCept.php
<?php 
$I = new ApiTester($scenario);
$I->wantTo('add notes');

$I->login();

$I->comment('sending wrong data format without time');
$newNote = [
    'reltype_id' => \app\models\enums\NoteRelTypeEnum::PROJECT_NOTE,
    'rel_id' => $I->getRandomId('project'),
    'dt' => $I->fake()->date('d/m/Y'),
    'content' => $I->fake()->text,
];
$I->sendPOST('notes', $newNote);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::UNPROCESSABLE_ENTITY);

$I->comment('sending wrong short data format');
$newNote = [
    'reltype_id' => \app\models\enums\NoteRelTypeEnum::PROJECT_NOTE,
    'rel_id' => $I->getRandomId('project'),
    'dt' => $I->fake()->date('j/n/Y'),
    'content' => $I->fake()->text,
];
$I->sendPOST('notes', $newNote);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::UNPROCESSABLE_ENTITY);

$I->comment('create a new note about company');
$newNote = [
    'reltype_id' => \app\models\enums\NoteRelTypeEnum::COMPANY_NOTE,
    'rel_id' => $I->getRandomId('company'),
    'dt' => $I->fake()->date('d/m/Y H:i:s'),
    'content' => $I->fake()->text,
];
$I->sendPOST('notes', $newNote);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::CREATED);
$I->canSeeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$.id');
$newNote['id'] = json_decode($I->grabResponse())->id;
$I->seeResponseContainsJson($newNote);

$I->comment('get the note using filtering');
$filterJson = json_encode(['reltype_id' => $newNote['reltype_id'], 'rel_id' => $newNote['rel_id']]);
$I->sendGET('notes', ['filter' => $filterJson]);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->canSeeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$[0].id');
$I->seeResponseContainsJson($newNote);

$I->comment('update the note');
$updatedNote = $newNote;
$updatedNote['content'] = $I->fake()->text;
$updatedNote['dt'] = $I->fake()->date('d/m/Y H:i:s');
$I->sendPUT('notes/' . $updatedNote['id'], $updatedNote);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->canSeeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$.id');
$I->seeResponseContainsJson($updatedNote);

$I->comment('can see the note updated');
$I->sendGET('notes/' . $updatedNote['id']);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
$I->canSeeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$.id');
$I->seeResponseContainsJson($updatedNote);

$I->comment('delete the note');
$I->sendDELETE('notes/' . $updatedNote['id']);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::NO_CONTENT);

$I->comment('can`t find the note deleted');
$I->sendGET('notes/' . $updatedNote['id']);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::NOT_FOUND);