Reputation: 276
my question is how to send parameter to my endpoint.
test
public function test_upgrade()
{
$billingChange3 = factory(Plan::class)->create([
'user_id' => 1,
'previous_price' => 150,
'current_price' => 100,
]);
$url = route(
'users.filters'
);
$response = $this->actingAs($this->admin)->getJson($url,['search'=>'upgrade']);
$response->assertStatus(200);
//till here correct
//but here it should return 2 since I have upgrade count 2 as correct it gives error
my api response is wrapped within data, so i have used data below
$response->assertJsonCount(2,'data');
}
my seach keyword can be any thing such as upgrade,downgradeetc. upgrade is when
current_price>previous_price``` and I have logic for that in controller
My vue dev tool shows url as below:
first:"https://localhost:800/users/plan?filter=upgrade&page=1"
In test I have passed params as getJson($url,['search'=>'upgrade']
Is that the correct way to pass paramters?
Upvotes: 0
Views: 476
Reputation: 2957
Not correct. See function signature - you pass headers:
public function getJson($uri, array $headers = [])
{
return $this->json('GET', $uri, [], $headers);
}
Correct way:
$response = $this
->actingAs($this->admin)
->getJson(route('users.filters', ['search'=>'upgrade']));
Upvotes: 1