I am testing an API endpoint returned Laravel resource with pagination
public function test_showing_all_plans(): void
{
$plans = Plan::where('is_active', true)
->paginate(10);
$resource = PlansResource::collection($plans);
$this->withHeaders([
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'AppKey' => 5,
])
->json('GET', '/api/customer/plans')
->assertStatus(200)
->assertExactJson([
$resource->response()->getData(true),
]);
}
so my problem is the returned result is not the same because of the path of the endpoint is not equal to the returned of the resource.
This is the result returned from the endpoint:
"links": {
"first": "http://www.site.local/api/customer/plans?page=1",
"last": "http://www.site.local/api/customer/plans?page=3",
"next": "http://www.site.local/api/customer/plans?page=2",
"prev": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 3,
"path": "http://www.site.local/api/customer/plans",
"per_page": 10,
"to": 10,
"total": 24
}
This is the code returned from the resource ' $resource->response()->getData(true)
'
"links": {
"first": "http://www.site.local?page=1",
"last": "http://www.site.local?page=3",
"next": "http://www.site.local?page=2",
"prev": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 3,
"path": "http://www.site.local",
"per_page": 10,
"to": 10,
}
so how can I pass the endpoint to my code or how can I make them equal, and is there is a proper way to test Laravel resource?