diff --git a/api/models/FeedbackForm.php b/api/models/FeedbackForm.php index 1c2ce12..52d899f 100644 --- a/api/models/FeedbackForm.php +++ b/api/models/FeedbackForm.php @@ -3,6 +3,7 @@ namespace api\models; use common\helpers\Error as E; use api\models\base\ApiForm; +use common\models\Account; use Yii; use yii\base\ErrorException; use yii\base\InvalidConfigException; @@ -58,11 +59,13 @@ class FeedbackForm extends ApiForm { return true; } - /** - * @return \common\models\Account|null $account - */ - protected function getAccount() { - return Yii::$app->user->identity; + protected function getAccount(): ?Account { + $identity = Yii::$app->user->identity; + if ($identity === null) { + return null; + } + + return $identity->getAccount(); } } diff --git a/tests/codeception/api/functional/FeedbackCest.php b/tests/codeception/api/functional/FeedbackCest.php new file mode 100644 index 0000000..abcda6e --- /dev/null +++ b/tests/codeception/api/functional/FeedbackCest.php @@ -0,0 +1,37 @@ +sendPOST('/feedback', [ + 'subject' => 'Test', + 'email' => 'email@ely.by', + 'type' => 0, + 'message' => 'Hello world', + ]); + $I->canSeeResponseCodeIs(200); + $I->canSeeResponseIsJson(); + $I->canSeeResponseContainsJson([ + 'success' => true, + ]); + } + + public function testFeedbackWithAuth(FunctionalTester $I) { + $I->amAuthenticated(); + $I->sendPOST('/feedback', [ + 'subject' => 'Test', + 'email' => 'email@ely.by', + 'type' => 0, + 'message' => 'Hello world', + ]); + $I->canSeeResponseCodeIs(200); + $I->canSeeResponseIsJson(); + $I->canSeeResponseContainsJson([ + 'success' => true, + ]); + } + +}