krakenjs / generator-swaggerize

Yeoman generator for design-driven apis with swagger 2.0 and krakenjs/swaggerize tools.
Other
70 stars 34 forks source link

switch to API BlackBox Functional Testing #99

Open gaboesquivel opened 7 years ago

gaboesquivel commented 7 years ago

I love tests being generated along with the handlers with mocked responses. However I think that a BlackBox approach to the API functional testing works better for this project. The main advantage is that it allows you to swap API framework and change the internal implementation of the API and the tests will work as we would only test input output over http based on the swagger definition.

implementation Eg.

t.test('GET: /items', (tt) => {
    api
      .get('/items')
      .set(defaultHeaders)
      .expect('Content-Type', /json/)
      .expect(200)
      .end((err, res) => { 
        tt.error(err, 'valid respose code and content type');
        const response = res.body;
        const validate = validator(apiDef.paths['/items']['get']['responses']['200']['schema']);
        tt.ok(validate(response), 'valid response format');
        // having ditched the mocked responses you can add fixtures to the db and then 
        // tt.deepEqual(response.results, expectedResults);
        tt.end();
      });
  });