mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 23:00:30 +00:00
549ce23ce8
* All projects into monorepo * Update CI * More CI updates * Extracted a bunch of things into packages * Publish - insomnia-plugin-base64@1.0.1 - insomnia-plugin-default-headers@1.0.2 - insomnia-plugin-file@1.0.1 - insomnia-plugin-hash@1.0.1 - insomnia-plugin-now@1.0.1 - insomnia-plugin-request@1.0.1 - insomnia-plugin-response@1.0.1 - insomnia-plugin-uuid@1.0.1 - insomnia-cookies@0.0.2 - insomnia-importers@1.5.2 - insomnia-prettify@0.0.3 - insomnia-url@0.0.2 - insomnia-xpath@0.0.2 * A bunch of small fixes * Improved build script * Fixed * Merge dangling files * Usability refactor * Handle duplicate plugin names
100 lines
2.9 KiB
JavaScript
100 lines
2.9 KiB
JavaScript
const {jarFromCookies, cookiesFromJar} = require('insomnia-cookies');
|
|
const tag = require('..').templateTags[0];
|
|
|
|
describe('plugin', () => {
|
|
describe('RequestExtension cookie', async () => {
|
|
it('should get cookie by name', async () => {
|
|
const jar = jarFromCookies([]);
|
|
jar.setCookieSync([
|
|
'foo=bar',
|
|
'path=/',
|
|
'domain=.insomnia.rest',
|
|
'HttpOnly Cache-Control: public, no-cache'
|
|
].join('; '), 'https://insomnia.rest');
|
|
|
|
const cookies = await cookiesFromJar(jar);
|
|
const requests = [{_id: 'req_1', parameters: [], url: 'https://insomnia.rest/foo/bar'}];
|
|
const jars = [{_id: 'jar_1', parentId: 'wrk_1', cookies}];
|
|
const context = _getTestContext([{_id: 'wrk_1'}], requests, jars);
|
|
const result = await tag.run(context, 'cookie', 'foo');
|
|
|
|
expect(result).toBe('bar');
|
|
});
|
|
});
|
|
|
|
describe('RequestExtension url', async () => {
|
|
it('should get url', async () => {
|
|
const requests = [{
|
|
_id: 'req_1',
|
|
parameters: [{name: 'foo', value: 'bar'}],
|
|
url: 'https://insomnia.rest/foo/bar'
|
|
}];
|
|
const context = _getTestContext([{_id: 'wrk_1'}], requests);
|
|
const result = await tag.run(context, 'url');
|
|
|
|
expect(result).toBe('https://insomnia.rest/foo/bar?foo=bar');
|
|
});
|
|
|
|
it('should get rendered url', async () => {
|
|
const requests = [{
|
|
_id: 'req_1',
|
|
parameters: [{name: 'foo', value: '{{ foo }}'}],
|
|
url: 'https://insomnia.rest/foo/bar'
|
|
}];
|
|
const context = _getTestContext([{_id: 'wrk_1'}], requests);
|
|
const result = await tag.run(context, 'url');
|
|
|
|
expect(result).toBe('https://insomnia.rest/foo/bar?foo=bar');
|
|
});
|
|
});
|
|
|
|
describe('RequestExtension header', async () => {
|
|
it('should get url', async () => {
|
|
const requests = [{
|
|
_id: 'req_1',
|
|
headers: [{name: 'foo', value: '{{ foo }}'}],
|
|
url: 'https://insomnia.rest/foo/bar'
|
|
}];
|
|
const context = _getTestContext([{_id: 'wrk_1'}], requests);
|
|
const result = await tag.run(context, 'header', 'foo');
|
|
|
|
expect(result).toBe('bar');
|
|
});
|
|
});
|
|
});
|
|
|
|
function _getTestContext (workspaces, requests, jars) {
|
|
jars = jars || [];
|
|
return {
|
|
meta: {
|
|
requestId: requests[0]._id,
|
|
workspaceId: workspaces[0]._id
|
|
},
|
|
util: {
|
|
render (str) {
|
|
return str.replace(/{{ foo }}/g, 'bar');
|
|
},
|
|
models: {
|
|
request: {
|
|
getById (id) {
|
|
return requests.find(r => r._id === id);
|
|
}
|
|
},
|
|
workspace: {
|
|
getById (id) {
|
|
return workspaces.find(w => w._id === id);
|
|
}
|
|
},
|
|
cookieJar: {
|
|
getOrCreateForWorkspace (workspace) {
|
|
return jars.find(j => j.parentId === workspace._id) || {
|
|
parentId: workspace._id,
|
|
cookies: []
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|