Last active
September 13, 2017 20:07
-
-
Save nardhar/845c1da9d005aee01dd0301c8e7d78b7 to your computer and use it in GitHub Desktop.
Revisions
-
nardhar revised this gist
Sep 13, 2017 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,4 +39,21 @@ describe('Starting controller testing', () => { }, ); }); it('PUT a record with query and body', () => { requestTest.put( '1', // body of the request { number: 123, name: 'my sample name', }, // response callback (res) => { should(res.status).be.eql(200); should(res.body).have.property('name', 'my sample name'); should(res.body).have.property('number', 123); }, ); }); }); -
nardhar created this gist
Sep 13, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ // Is there something like this? const RequestTest = require('should-request-test'); describe('Starting controller testing', () => { // calling the express app const server = require('src/index'); // controller endpoint const endpoint = '/api/v1/myResource'; const requestTest; before((done) => { const token = getToken(); // send the same header on all petitions requestTest = new RequestTest({ server, endpoint, headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, }); }); // all set up and now I just need to send body and test for the response // done() could be called after the it callback, like a wrapper it('POST a record', () => { requestTest.post( // body of the request { number: 123, name: 'my sample name', }, // response callback (res) => { should(res.status).be.eql(201); should(res.body).have.property('name', 'my sample name'); should(res.body).have.property('number', 123); }, ); }); });