vendredi 8 janvier 2016

REST API endpoint test (request / response code)

I m actually building a REST API that I need to test.

Actually, I have many unit tests to check each method behaviour and now I need to test if I get the expected result when requesting an endpoint, like checking the HTTP response code.

I m working with nodejs and it seems to be a good idea to use supertest module to send HTTP request and to check response codes.

The fact is that if I send request on my real REST API endpoints, I can have many bad data managed in database (when testing PUT / POST / PATCH methods).

But in the other hand, I don't have (in my mind) any way to "mock" or simulate my business job inside of the tests :

(Mocha syntax with ES6)

  describe('get /v1/clients ', function() {
    it('Should get 200 ', function(done) {
      request.get('/v1/clients')
        .query('access_token=' + token + '').expect(200, done);
    });
  });

So you've probably got it :

  • I want to test each API endpoint to be sure that I get what I should get
  • I want to use a standard access_token, not one my database (like a fake one)
  • I want to "simulate" by API, without using real data.

Is that possible ? If yes, How ?

Is this a better choice to check on my real data or not ?

Aucun commentaire:

Enregistrer un commentaire