mardi 15 mars 2016

Hit a route in laravel 5 application using pre request scripts in postman?

So I am using postman to test my API endpoints. I test CRUD for all the resources. But every time I run the tests, the database state changes and which is why the next iteration of tests fail for obvious reasons.

I can see that there are pre request scripts section where I can define scripts to run before execution in postman. Now to come around the database state change issue, I usually reseed the database via the command line using artisan which comes with laravel. I can do the same by code in the application.

My point is that I can define a route which can reseed the database and I can hit that route in the pre request of the first API end point which is authentication. This way every iteration will have the same database state.

So I am trying this in the pre request script of the first endpoint:

$.get('http://{{host}}/api/reseed', function(response){
    postman.setEnvironmentVariable("foo", response);
});

Since I don't have any other way for feedback, I am trying to see the response by saving it in an environment variable. But this doesn't seem to work maybe because it is an async request or maybe some other reason. I don't see the environment variable set.

Does anyone know a better way to do this? Or a solution to the one I am trying to do?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire