mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-26 16:49:11 -04:00
Add nock test for actual sending
This commit is contained in:
1 parent
4ed1170dd7
commit
c9766e0768
6 files changed
+59
-10
No files matched your search
@@ -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';
|
||||
@@ -113,7 +113,7 @@ class RequestPane extends Component {
|
||||
</Tab>
|
||||
<Tab>
|
||||
<button onClick={e => trackEvent('Request Tab Clicked', {name: 'Params'})}>
|
||||
Params {request.parameters.length ?
|
||||
Query {request.parameters.length ?
|
||||
<span className="txt-sm">({request.parameters.length})</span> : null}
|
||||
</button>
|
||||
</Tab>
|
||||
|
||||
@@ -40,7 +40,7 @@ class ResponseError extends Component {
|
||||
<hr/>
|
||||
<div className="text-center pad">
|
||||
<p className="faint pad-left pad-right">
|
||||
It looks like you encountered a strange error. Here are some suggestions.
|
||||
That error looks strange. Maybe this will help.
|
||||
</p>
|
||||
{msg}
|
||||
|
||||
|
||||
@@ -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});
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user