I am trying to make tests for a CRUD app. So after testing if a record has been created, I want to test how it is displayed and then test if it can be deleted succesfully.
In the create record function I get the id (using PostgreSql's RETURNING) and a 'OK' through JSON.
I can test those values using this test:
$t->post_ok('/users' => form => {alias => 'TESTING USER ALIAS'})
->status_is(200)
->header_is('content-type' => 'application/json')
->json_has( 'result' => 'OK' )
->json_like( 'last_id' => qr/\d/ )
;
Now I want to make the tests for the display and the deletion, something like:
$t->get_ok('/users/15')
->status_is(200)
->content_like(qr /TESTING USER ALIAS/)
;
But I need the last_id value that returns (15, in my example), a variable that I can somehow chain from a test to the next.
Any suggestions?
Regards:
Nacho B