QuestionServiceApiTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Tests\Unit\Services;
  3. use App\Services\QuestionServiceApi;
  4. use Illuminate\Support\Facades\Http;
  5. use Tests\TestCase;
  6. class QuestionServiceApiTest extends TestCase
  7. {
  8. public function test_list_questions_passes_filters_correctly()
  9. {
  10. Http::fake([
  11. '*/questions*' => Http::response(['data' => [], 'meta' => []], 200),
  12. ]);
  13. $service = new QuestionServiceApi();
  14. $filters = [
  15. 'kp_code' => 'KP1001',
  16. 'difficulty' => '0.5',
  17. 'type' => 'CHOICE', // New filter
  18. 'search' => 'test',
  19. ];
  20. $service->listQuestions(1, 10, $filters);
  21. Http::assertSent(function ($request) {
  22. return isset($request['kp_code']) && $request['kp_code'] === 'KP1001' &&
  23. isset($request['difficulty']) && $request['difficulty'] === '0.5' &&
  24. isset($request['type']) && $request['type'] === 'CHOICE' &&
  25. isset($request['search']) && $request['search'] === 'test';
  26. });
  27. }
  28. public function test_generate_questions_passes_new_parameters()
  29. {
  30. Http::fake([
  31. '*/questions/generate*' => Http::response(['success' => true], 200),
  32. ]);
  33. $service = new QuestionServiceApi();
  34. $params = [
  35. 'kp_code' => 'KP1001',
  36. 'count' => 5,
  37. 'difficulty' => '0.8', // New param
  38. 'type' => 'CALCULATION', // New param
  39. ];
  40. $service->generateQuestions($params);
  41. Http::assertSent(function ($request) {
  42. return $request['difficulty'] === '0.8' &&
  43. $request['type'] === 'CALCULATION';
  44. });
  45. }
  46. }