2016-11-10 07:34:26 +00:00
|
|
|
import * as harUtils from '../har';
|
2016-11-19 07:11:10 +00:00
|
|
|
import * as render from '../render';
|
2016-11-10 05:56:23 +00:00
|
|
|
import * as models from '../../models';
|
2017-03-23 22:10:42 +00:00
|
|
|
import {AUTH_BASIC} from '../constants';
|
2017-07-20 03:36:44 +00:00
|
|
|
import {globalBeforeEach} from '../../__jest__/before-each';
|
2016-10-05 16:34:13 +00:00
|
|
|
|
|
|
|
describe('exportHarWithRequest()', () => {
|
2017-07-20 03:36:44 +00:00
|
|
|
beforeEach(globalBeforeEach);
|
2016-10-05 16:34:13 +00:00
|
|
|
it('renders does it correctly', async () => {
|
2016-11-10 01:15:27 +00:00
|
|
|
const workspace = await models.workspace.create();
|
2016-10-05 16:34:13 +00:00
|
|
|
const cookies = [{
|
|
|
|
creation: new Date('2016-10-05T04:40:49.505Z'),
|
|
|
|
key: 'foo',
|
|
|
|
value: 'barrrrr',
|
|
|
|
expires: new Date('2096-10-12T04:40:49.000Z'),
|
|
|
|
domain: 'google.com',
|
|
|
|
path: '/',
|
|
|
|
hostOnly: true,
|
|
|
|
lastAccessed: new Date('2096-10-05T04:40:49.505Z')
|
|
|
|
}];
|
|
|
|
|
2017-09-13 06:11:49 +00:00
|
|
|
const cookieJar = await models.cookieJar.getOrCreateForParentId(workspace._id);
|
|
|
|
await models.cookieJar.update(cookieJar, {
|
2016-10-05 16:34:13 +00:00
|
|
|
parentId: workspace._id,
|
|
|
|
cookies
|
|
|
|
});
|
|
|
|
|
2016-11-10 01:15:27 +00:00
|
|
|
const request = Object.assign(models.request.init(), {
|
2016-10-05 16:34:13 +00:00
|
|
|
_id: 'req_123',
|
|
|
|
parentId: workspace._id,
|
|
|
|
headers: [{name: 'Content-Type', value: 'application/json'}],
|
|
|
|
parameters: [{name: 'foo bar', value: 'hello&world'}],
|
|
|
|
method: 'POST',
|
2016-11-22 19:42:10 +00:00
|
|
|
body: {
|
|
|
|
text: 'foo bar'
|
|
|
|
},
|
2016-10-05 16:34:13 +00:00
|
|
|
url: 'http://google.com',
|
|
|
|
authentication: {
|
2017-03-23 22:10:42 +00:00
|
|
|
type: AUTH_BASIC,
|
2016-10-05 16:34:13 +00:00
|
|
|
username: 'user',
|
|
|
|
password: 'pass'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const renderedRequest = await render.getRenderedRequest(request);
|
2017-03-23 22:10:42 +00:00
|
|
|
const har = await harUtils.exportHarWithRequest(renderedRequest);
|
2016-10-05 16:34:13 +00:00
|
|
|
|
|
|
|
expect(har.cookies.length).toBe(1);
|
|
|
|
expect(har).toEqual({
|
|
|
|
bodySize: -1,
|
|
|
|
cookies: [{
|
|
|
|
creation: '2016-10-05T04:40:49.505Z',
|
|
|
|
domain: 'google.com',
|
|
|
|
expires: '2096-10-12T04:40:49.000Z',
|
|
|
|
hostOnly: true,
|
|
|
|
key: 'foo',
|
|
|
|
name: 'foo',
|
|
|
|
path: '/',
|
|
|
|
value: 'barrrrr',
|
|
|
|
// lastAccessed is updated, so lets hack the assertion
|
|
|
|
lastAccessed: har.cookies[0].lastAccessed
|
|
|
|
}],
|
|
|
|
headers: [
|
|
|
|
{name: 'Content-Type', value: 'application/json'},
|
|
|
|
{name: 'Authorization', value: 'Basic dXNlcjpwYXNz'}
|
|
|
|
],
|
|
|
|
headersSize: -1,
|
|
|
|
httpVersion: 'HTTP/1.1',
|
|
|
|
method: 'POST',
|
2016-11-22 19:42:10 +00:00
|
|
|
postData: {
|
|
|
|
text: 'foo bar'
|
|
|
|
},
|
2016-10-05 16:34:13 +00:00
|
|
|
queryString: [{name: 'foo bar', value: 'hello&world'}],
|
|
|
|
url: 'http://google.com/'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|