ldc-crm/tests/Unit/CrmClientV2QuestionTest.php
Jérémy Munsch 787ee5a4c5 - tag 2.0.1
- Add Questions segementation
- Fix Customer delete Tests
2021-08-11 17:37:59 +02:00

75 lines
2.4 KiB
PHP

<?php
namespace Tests\Unit;
use Exception;
use LDC\LDCCRM\CrmApiV2;
use LDC\LDCCRM\Models\Answer;
use LDC\LDCCRM\Models\Question;
class CrmClientV2QuestionTest extends CrmClientTester
{
public function testGetAllQuestions()
{
$questions = Question::all();
$this->assertNotEmpty($questions, 'Should have returned some questions');
}
public function testGetAllQuestionsWithCustomerAnswers()
{
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$questions = Question::allWithCustomerAnswers($customer);
$this->assertNotEmpty($questions, 'Should have returned some questions');
}
public function testGetAllCustomerUnAnsweredQuestions()
{
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$questions = Question::unansweredBy($customer);
$this->assertNotEmpty($questions, 'Should have returned some questions');
}
public function testSubmitCustomerAnswer()
{
$questions = Question::all();
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$result = Answer::setQuestionAnswers(
$customer->hashcode,
$questions[0]->id,
[
$questions[0]->answers[0]->id,
$questions[0]->answers[1]->id
]
);
$this->assertTrue($result);
}
public function testGetAllCustomerUnansweredQuestionsShouldNotContainFirst()
{
$this->expectNotToPerformAssertions();
$unWantedQuestion = Question::all()[0];
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$questions = Question::unansweredBy($customer);
foreach ($questions as $question) {
if ($unWantedQuestion->id === $question->id) {
throw new Exception('The question should not appear');
}
}
}
public function testGetAllQuestionsWithCustomerAnswersShouldHaveAnswers()
{
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$questions = Question::allWithCustomerAnswers($customer);
$this->assertNotEmpty($questions[0]['customerAnswers'], 'Should have customer answers');
}
}