sboulahr's avatar

Unit test orWhereHas,whereHas Conditions using fakers

Should i test the orWhereHas,whereHas Conditions using fakers ?

Thank you

0 likes
3 replies
bugsysha's avatar

You do not test orWhereHas and whereHas. You test the response.

  1. Seed the database with specific data
  2. Make the request
  3. Assert that the request contains correct data

You can make few tests for this or cover everything with single test.

1 like
sboulahr's avatar

Thank you for your reply , I tried to write this test for the first condition , since I don't need to test other conditions with : orWhereHas and whereHas , But I got " Expected status code 200 but received 500 "

function test_search_order()
      {
        Sanctum::actingAs($this->user, ['*']);
         var_dump($this->order);
           $response = $this->json('GET', 'api/order/search'.$this->order->id, ['f_only_orders' => 'true'],  $this->headers);
/*               print_r($response->json());
 */               echo ($this->order->type);
               $response -> assertStatus(200)
               ->assertJsonFragment(['type' => 'order']);
      }
bugsysha's avatar

You can add $this->withoutExceptionHandling() in your test method and see what is it complaining about. From what I see your URL seems bit strange. I guess instead of api/order/search you should have api/order/search/. Missing slash at the end.

Please or to participate in this conversation.