SuiteCRM-Core/tests/api/V8/CreateRelationShipCest.php
Dillon-Brown 8e4cc94994 Squashed 'public/legacy/' content from commit 817a12dc0
git-subtree-dir: public/legacy
git-subtree-split: 817a12dc0c30c189f56d5cb1f7dc37a9631bdbe3
2021-03-31 15:37:32 +01:00

57 lines
1.4 KiB
PHP

<?php
namespace Test\Api\V8;
use ApiTester;
class CreateRelationShipCest
{
/**
* @param ApiTester $I
*
* @throws \Codeception\Exception\ModuleException
*/
public function _before(ApiTester $I)
{
$I->login();
}
/**
* @param ApiTester $I
*
* @throws \Exception
*/
public function shouldWork(ApiTester $I)
{
$accountId = $I->createAccount();
$contactId = $I->createContact();
$endpoint = $I->getInstanceURL() . '/Api/V8/module/Accounts/{id}/relationships';
$endpoint = str_replace('{id}', $accountId, $endpoint);
$payload = [
'data' => [
'type' => 'Contacts',
'id' => '{id}',
]
];
$payload['data']['id'] = str_replace('{id}', $contactId, $payload['data']['id']);
$I->sendPOST($endpoint, $payload);
$I->seeResponseCodeIs(201);
$I->seeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$.meta.message');
$I->seeResponseContainsJson(
[
'message' => sprintf(
'Contact with id %s has been added to Account with id %s',
$contactId,
$accountId
)
]
);
$I->deleteBean('accounts', $accountId);
$I->deleteBean('contacts', $contactId);
}
}