Last active
August 20, 2017 21:18
-
-
Save ericwooley/6fdd41eadd5b2f0cf4c65cd2aab71c85 to your computer and use it in GitHub Desktop.
Revisions
-
ericwooley revised this gist
Aug 20, 2017 . 1 changed file with 6 additions and 3 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 @@ -9,7 +9,8 @@ const api = process.env.API_URL || 'http://localhost:3200' * These functions make our actual tests much shorter and readable ************************************************************************/ // this accepts request options, // and returns a function that makes a request with those options // which tests the result against a snapshot const testEndpointSnapshot = (requestOptions, options = {}) => // returns function, so you can pass it right into a test @@ -42,9 +43,11 @@ const testGetEndpoint = (endpoint, options = {}) => // Describe the /products route describe('/products', () => { // remember that `testGetEndpoint('/products/')` returns a function, // which will be run as the test. it('should list all products', testGetEndpoint('/products/')) // remember that `testEndpointSnapshot({...})` returns a function, // which will be run as the test. it( 'should create a new product', testEndpointSnapshot({ -
ericwooley revised this gist
Aug 20, 2017 . 1 changed file with 1 addition and 2 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 @@ -9,7 +9,6 @@ const api = process.env.API_URL || 'http://localhost:3200' * These functions make our actual tests much shorter and readable ************************************************************************/ // this accepts request options, and returns a function that makes a request with those options // which tests the result against a snapshot const testEndpointSnapshot = (requestOptions, options = {}) => @@ -38,7 +37,7 @@ const testGetEndpoint = (endpoint, options = {}) => /************************************************************************ * Actual Tests * Where the actual tests are being described and run ************************************************************************/ // Describe the /products route -
ericwooley revised this gist
Aug 20, 2017 . 1 changed file with 13 additions and 1 deletion.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 @@ -4,6 +4,12 @@ const requestPromise = require('request-promise') // in case you want to mess with where the integration test happens const api = process.env.API_URL || 'http://localhost:3200' /************************************************************************ * Test Setup Functions * These functions make our actual tests much shorter and readable ************************************************************************/ // this accepts request options, and returns a function that makes a request with those options // which tests the result against a snapshot const testEndpointSnapshot = (requestOptions, options = {}) => @@ -30,6 +36,12 @@ const testGetEndpoint = (endpoint, options = {}) => options ) /************************************************************************ * Actual Tests * These functions make our actual tests much shorter and readable ************************************************************************/ // Describe the /products route describe('/products', () => { // remember that `testGetEndpoint('/products/')` returns a function, which will be run as the test. it('should list all products', testGetEndpoint('/products/')) @@ -47,4 +59,4 @@ describe('/products', () => { } }) ) }) -
ericwooley revised this gist
Aug 20, 2017 . 1 changed file with 6 additions and 1 deletion.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 @@ -12,7 +12,12 @@ const testEndpointSnapshot = (requestOptions, options = {}) => // Makes a request with those options requestPromise(requestOptions).then(result => // expect the result to match a snapshot named after the uri expect(result).toMatchSnapshot( requestOptions.method + ' ' + requestOptions.uri + (options.snapShotName || '') ) ) // short cut for get requests, so all that you need to pass in is the uri -
ericwooley created this gist
Aug 20, 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,45 @@ // see https://github.com/request/request-promise const requestPromise = require('request-promise') // in case you want to mess with where the integration test happens const api = process.env.API_URL || 'http://localhost:3200' // this accepts request options, and returns a function that makes a request with those options // which tests the result against a snapshot const testEndpointSnapshot = (requestOptions, options = {}) => // returns function, so you can pass it right into a test () => // Makes a request with those options requestPromise(requestOptions).then(result => // expect the result to match a snapshot named after the uri expect(result).toMatchSnapshot(requestOptions.uri + options.snapShotName) ) // short cut for get requests, so all that you need to pass in is the uri const testGetEndpoint = (endpoint, options = {}) => testEndpointSnapshot( { method: 'GET', uri: api + endpoint }, options ) describe('/products', () => { // remember that `testGetEndpoint('/products/')` returns a function, which will be run as the test. it('should list all products', testGetEndpoint('/products/')) // remember that `testEndpointSnapshot({...})` returns a function, which will be run as the test. it( 'should create a new product', testEndpointSnapshot({ json: true, method: 'POST', uri: api + '/products/', body: { name: 'some product', description: 'shoes', price: 12.25 } }) ) })