I am not able to understand how can i write unit test for my get api. my url => /api/admin/agents?roleId=3
This is reponse when i am passing correct role id:
{
"message": null,
"data": {
"items": [
{
"id": 4,
"firstName": "Himanshu",
"lastName": "Sharma",
"phone": null,
}
],
"page": 1,
"total": 3,
"pages": 1,
"perpage": 15
},
"type": null
}
this is when i am passing any invalid role id
{
"message": null,
"data": {
"items": [],
"page": 1,
"total": 0,
"pages": 1,
"perpage": 15
},
"type": null
}
mycode
public function test_get_api_for_agent()
{
$admin_login_response=$this->json('POST','/api/authenticate',['email'=>'abc@luezoid.com', 'password' => 'password']);
$token= [
'authorization' => 'Bearer '.$admin_login_response['data']['token']
];
$seller_block_patch_reponse = $this->withHeaders($token)->json('GET','api/admin/agents?roleId=3');
$seller_block_patch_reponse
->assertStatus(200)
->assertJson([
'data' => ''
]);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire