This commit is contained in:
78
tests/Integration/AppQuestionnairesTest.php
Normal file
78
tests/Integration/AppQuestionnairesTest.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Integration;
|
||||
|
||||
use Tests\Support\ApiTestCase;
|
||||
use Tests\Support\DatabaseFixture;
|
||||
|
||||
final class AppQuestionnairesTest extends ApiTestCase
|
||||
{
|
||||
public function testListActiveQuestionnaires(): void
|
||||
{
|
||||
$this->loginAs(DatabaseFixture::COACH1_USERNAME);
|
||||
$res = $this->api('GET', 'app_questionnaires');
|
||||
$this->assertOk($res);
|
||||
$this->assertIsArray($res['body']['data']);
|
||||
$ids = array_column($res['body']['data'], 'id');
|
||||
$this->assertContains(DatabaseFixture::QUESTIONNAIRE_ID, $ids);
|
||||
$first = $res['body']['data'][0];
|
||||
$this->assertArrayHasKey('name', $first);
|
||||
$this->assertArrayHasKey('showPoints', $first);
|
||||
$this->assertArrayHasKey('condition', $first);
|
||||
}
|
||||
|
||||
public function testFetchQuestionnaireDetail(): void
|
||||
{
|
||||
$this->loginAs(DatabaseFixture::COACH1_USERNAME);
|
||||
$res = $this->api('GET', 'app_questionnaires', null, null, [
|
||||
'id' => DatabaseFixture::QUESTIONNAIRE_ID,
|
||||
]);
|
||||
$this->assertOk($res);
|
||||
$this->assertSame(DatabaseFixture::QUESTIONNAIRE_ID, $res['body']['data']['meta']['id']);
|
||||
$this->assertNotEmpty($res['body']['data']['questions']);
|
||||
$q = $res['body']['data']['questions'][0];
|
||||
$this->assertSame('q1', $q['id']);
|
||||
$this->assertSame('radio_question', $q['layout']);
|
||||
}
|
||||
|
||||
public function testCoachCannotUploadForOtherCoachesClient(): void
|
||||
{
|
||||
$this->loginAs(DatabaseFixture::COACH1_USERNAME);
|
||||
$res = $this->api('POST', 'app_questionnaires', [
|
||||
'questionnaireID' => DatabaseFixture::QUESTIONNAIRE_ID,
|
||||
'clientCode' => DatabaseFixture::CLIENT_COACH2,
|
||||
'answers' => [
|
||||
['questionID' => 'q1', 'answerOptionKey' => 'consent_signed'],
|
||||
],
|
||||
]);
|
||||
$this->assertError($res, 'NOT_FOUND');
|
||||
}
|
||||
|
||||
public function testUploadAnswersMapsShortQuestionIds(): void
|
||||
{
|
||||
$this->loginAs(DatabaseFixture::COACH1_USERNAME);
|
||||
$res = $this->api('POST', 'app_questionnaires', [
|
||||
'questionnaireID' => DatabaseFixture::QUESTIONNAIRE_ID,
|
||||
'clientCode' => DatabaseFixture::CLIENT_COACH1,
|
||||
'completedAt' => time(),
|
||||
'answers' => [
|
||||
['questionID' => 'q1', 'answerOptionKey' => 'consent_signed', 'answeredAt' => time()],
|
||||
],
|
||||
]);
|
||||
$this->assertOk($res);
|
||||
$this->assertTrue($res['body']['data']['submitted']);
|
||||
$this->assertSame(5, $res['body']['data']['sumPoints']);
|
||||
}
|
||||
|
||||
public function testCoachClientsList(): void
|
||||
{
|
||||
$this->loginAs(DatabaseFixture::COACH1_USERNAME);
|
||||
$res = $this->api('GET', 'app_questionnaires', null, null, ['clients' => '1']);
|
||||
$this->assertOk($res);
|
||||
$codes = array_column($res['body']['data']['clients'], 'clientCode');
|
||||
$this->assertContains(DatabaseFixture::CLIENT_COACH1, $codes);
|
||||
$this->assertNotContains(DatabaseFixture::CLIENT_COACH2, $codes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user