72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\ApiV2;
|
|
|
|
use App\Enums\ApiStatus;
|
|
use App\Models\Question;
|
|
|
|
class QuestionTest extends ApiBase
|
|
{
|
|
|
|
/**
|
|
* route: apiV2.questions.index
|
|
*/
|
|
public function testQuestionIndex()
|
|
{
|
|
extract($this->getCustomer());
|
|
|
|
$response = $this->callApiWithToken($service, 'get', route('apiV2.questions.index'));
|
|
$json = $response->decodeResponseJson();
|
|
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
|
|
}
|
|
|
|
/**
|
|
* route: apiV2.questions.indexWithResponse
|
|
*/
|
|
public function testQuestionIndexWithAnswers()
|
|
{
|
|
extract($this->getCustomer(true, false));
|
|
$service = $brand->services()->firstOrFail();
|
|
$response = $this->callApiWithToken($service, 'get', route(
|
|
'apiV2.questions.indexWithResponse',
|
|
['customer' => $info->hashcode]
|
|
));
|
|
$json = $response->decodeResponseJson();
|
|
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
|
|
}
|
|
|
|
/**
|
|
* route: apiV2.questions.unAnsweredBy
|
|
*/
|
|
public function testCustomerUnAnsweredIndex()
|
|
{
|
|
extract($this->getCustomer());
|
|
$service = $brand->services()->firstOrFail();
|
|
$response = $this->callApiWithToken($service, 'get', route(
|
|
'apiV2.questions.unAnsweredBy',
|
|
['customer' => $info->hashcode]
|
|
));
|
|
$json = $response->decodeResponseJson();
|
|
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
|
|
}
|
|
|
|
/**
|
|
* route: apiV2.customers.answers.store
|
|
*/
|
|
public function testQuestionSetAnswer()
|
|
{
|
|
extract($this->getCustomer(true, false));
|
|
$question = Question::whereHas('brand', function ($q) use ($brand) {
|
|
$q->whereId($brand->id);
|
|
})->inRandomOrder()->firstOrFail();
|
|
$answer = $question->answers->first();
|
|
$response = $this->callApiWithToken($service, 'post', route('apiV2.customers.answers.store', [
|
|
'customer' => $info->hashcode
|
|
]), [
|
|
'question' => $question->id,
|
|
'answers' => [$answer->id]
|
|
]);
|
|
$json = $response->decodeResponseJson();
|
|
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
|
|
}
|
|
}
|