diff --git a/app/__mocks__/node-uuid.js b/app/__mocks__/node-uuid.js index b4eb939435..40986fa55f 100644 --- a/app/__mocks__/node-uuid.js +++ b/app/__mocks__/node-uuid.js @@ -1,5 +1,6 @@ -export default { - v4 () { - return 'b5c2f089-2c0c-46b6-a6f1-8d5b86cbc603' - } -}; + +// Mock uuid() +module.exports = () => 'f9348692-2c92-4af6-9906-7a6e0cadba06'; + +// Mock uuid.v4() +module.exports.v4 = () => 'b5c2f089-2c0c-46b6-a6f1-8d5b86cbc603'; diff --git a/app/components/RequestPane.js b/app/components/RequestPane.js index e510c8ddb0..99bf05d8a3 100644 --- a/app/components/RequestPane.js +++ b/app/components/RequestPane.js @@ -113,7 +113,7 @@ class RequestPane extends Component { diff --git a/app/components/viewers/ResponseError.js b/app/components/viewers/ResponseError.js index 909a0b248f..e650a8d6db 100644 --- a/app/components/viewers/ResponseError.js +++ b/app/components/viewers/ResponseError.js @@ -40,7 +40,7 @@ class ResponseError extends Component {

- It looks like you encountered a strange error. Here are some suggestions. + That error looks strange. Maybe this will help.

{msg}    diff --git a/app/database/index.js b/app/database/index.js index 7a7f044a21..a015701c88 100644 --- a/app/database/index.js +++ b/app/database/index.js @@ -538,7 +538,7 @@ export function requestGroupDuplicate (requestGroup) { export function responseCreate (patch = {}) { if (!patch.parentId) { - throw new Error('New Requests missing `parentId`', patch); + throw new Error('New Response missing `parentId`'); } removeBulkSilently(TYPE_RESPONSE, {parentId: patch.parentId}); diff --git a/app/lib/__tests__/network.test.js b/app/lib/__tests__/network.test.js index aa458fd7e2..a29e4b3532 100644 --- a/app/lib/__tests__/network.test.js +++ b/app/lib/__tests__/network.test.js @@ -1,5 +1,6 @@ import * as networkUtils from '../network'; import * as db from '../../database'; +import nock from 'nock'; import {getRenderedRequest} from '../render'; describe('buildRequestConfig()', () => { @@ -38,7 +39,7 @@ describe('buildRequestConfig()', () => { parameters: [{name: 'foo bar', value: 'hello&world'}], method: 'POST', body: 'foo=bar', - url: 'http://foo.com?bar=baz', + url: 'http://foo.com/★/foo%20bar?bar=baz', authentication: { username: 'user', password: 'pass' @@ -61,9 +62,55 @@ describe('buildRequestConfig()', () => { rejectUnauthorized: true, time: true, timeout: 0, - url: 'http://foo.com/?bar=baz&foo%20bar=hello%26world' + url: 'http://foo.com/%E2%98%85/foo%2520bar?bar=baz&foo%20bar=hello%26world' }); }); }) }); }); + +describe('actuallySend()', () => { + beforeEach(() => db.initDB({inMemoryOnly: true}, true)); + + it('does something', () => { + let settings, mock; + + return Promise.all([ + db.workspaceCreate(), + db.settingsCreate() + ]).then(([workspace, newSettings]) => { + settings = newSettings; + + mock = nock('http://foo.com') + .matchHeader('Content-Type', 'application/json') + .matchHeader('Authorization', 'Basic dXNlcjpwYXNz') + .post('/') + .query({'foo bar': 'hello&world'}) + .reply(200, 'response body') + .log(console.log); + + const request = Object.assign(db.MODEL_DEFAULTS[db.TYPE_REQUEST](), { + _id: 'req_123', + parentId: workspace._id, + headers: [{name: 'Content-Type', value: 'application/json'}], + parameters: [{name: 'foo bar', value: 'hello&world'}], + method: 'POST', + body: 'foo=bar', + url: 'http://foo.com', + authentication: { + username: 'user', + password: 'pass' + } + }); + + return getRenderedRequest(request); + }).then(renderedRequest => { + return networkUtils._actuallySend(renderedRequest, settings); + }).then(response => { + expect(mock.basePath).toBe('http://foo.com:80'); + expect(response.url).toBe('http://foo.com/?foo%20bar=hello%26world'); + expect(response.body).toBe('response body'); + expect(response.statusCode).toBe(200); + }); + }); +}); diff --git a/package.json b/package.json index 65d5ed7d33..8ecfd151d8 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "json-loader": "^0.5.4", "less": "^2.7.1", "less-loader": "^2.2.3", + "nock": "^8.0.0", "react-addons-perf": "^15.3.0", "react-addons-test-utils": "^15.1.0", "react-hot-loader": "^1.3.0",