How can i send auth header, when test codeception rest api?
What i have now:
- Yii2 project
"codeception/module-yii2": "^1.0.0""codeception/module-rest": "^1.3"- Generated test class by command
codecept generate:cest api TestName
My class with test
class CreateWorkspaceCest
{
public function _before(ApiTester $I)
{
}
public function successCreate(ApiTester $I)
{
$title = 'create test';
$description = 'test description';
$I->sendPost('/workspace/create', [
'title' => $title,
'description' => $description,
]);
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseContainsJson([
'title' => $title,
'description' => $description,
'status' => 'active',
]);
}
}
Now it fails with 403 code, because backend expects header JWT-Key: <TOKEN>
How can i send auth header in sendPost
And where it is better to store auth token in one place to avoid code duplication, during writing tests?