From de088950929becfbe6ce8390cadaf65c37b6a0a6 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Tue, 10 Oct 2017 19:54:42 +0200 Subject: [PATCH] Support for tag editor dynamic variable args (#512) --- .../__tests__/response-extension.test.js | 5 +- .../extensions/response-extension.js | 10 +- app/templating/utils.js | 1 + app/ui/components/cookie-list.js | 17 ++- app/ui/components/modals/nunjucks-modal.js | 1 + app/ui/components/rendered-text.js | 7 +- app/ui/components/templating/tag-editor.js | 126 +++++++++++++++--- 7 files changed, 131 insertions(+), 36 deletions(-) diff --git a/app/templating/extensions/__tests__/response-extension.test.js b/app/templating/extensions/__tests__/response-extension.test.js index 44d6254de..1cbdb5fc7 100644 --- a/app/templating/extensions/__tests__/response-extension.test.js +++ b/app/templating/extensions/__tests__/response-extension.test.js @@ -27,10 +27,11 @@ describe('ResponseExtension General', async () => { }); it('fails on empty filter', async () => { - await models.response.create({parentId: 'req_test'}, '{"foo": "bar"}'); + const request = await models.request.create({parentId: 'foo'}); + await models.response.create({parentId: request._id, statusCode: 200}, '{"foo": "bar"}'); try { - await templating.render(`{% response "body", "req_test", "" %}`); + await templating.render(`{% response "body", "${request._id}", "" %}`); fail('Should have failed'); } catch (err) { expect(err.message).toContain('No body filter specified'); diff --git a/app/templating/extensions/response-extension.js b/app/templating/extensions/response-extension.js index 21066882f..286513b8a 100644 --- a/app/templating/extensions/response-extension.js +++ b/app/templating/extensions/response-extension.js @@ -49,10 +49,6 @@ export default ({ throw new Error('No request specified'); } - if (field !== 'raw' && !filter) { - throw new Error(`No ${field} filter specified`); - } - const request = await context.util.models.request.getById(id); if (!request) { throw new Error(`Could not find request ${id}`); @@ -65,7 +61,11 @@ export default ({ } if (!response.statusCode) { - throw new Error('No responses for request'); + throw new Error('No successful responses for request'); + } + + if (field !== 'raw' && !filter) { + throw new Error(`No ${field} filter specified`); } const sanitizedFilter = filter.trim(); diff --git a/app/templating/utils.js b/app/templating/utils.js index 7984b1eb1..74b1c0b5c 100644 --- a/app/templating/utils.js +++ b/app/templating/utils.js @@ -3,6 +3,7 @@ export type NunjucksParsedTagArg = { type: 'string' | 'number' | 'boolean' | 'number' | 'variable' | 'expression', value: string | number | boolean, + forceVariable?: boolean, quotedBy?: '"' | "'" }; diff --git a/app/ui/components/cookie-list.js b/app/ui/components/cookie-list.js index 1836b138b..5409bb762 100644 --- a/app/ui/components/cookie-list.js +++ b/app/ui/components/cookie-list.js @@ -67,13 +67,16 @@ class CookieList extends React.PureComponent { return ( - - {cookie.domain} - - - {cookieString} - + + + {cookie.domain} + + + + + {cookieString} + +