Skip to content
This repository has been archived by the owner on Apr 20, 2019. It is now read-only.

Commit

Permalink
Now even "$n" is substituted in url with pattern /some/url/path//some…
Browse files Browse the repository at this point in the history
…thing where "n" can be any positive integer
  • Loading branch information
adisingh007 committed Sep 17, 2018
1 parent 031a769 commit ebaa36c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ module.exports.config = function (settings) {
request.payload.requests.every((req, idx) => {

const requestParts = [];
const result = req.path.replace(internals.requestRegex, (match, p1, p2) => {
const result = req.path.replace(internals.requestRegex, (match, p1, p2, p3) => {

if (!p1) {
requestParts.push({ type: 'text', value: p2 });
requestParts.push({ type: 'text', value: p3 });
return '';
}

if (p1 < idx) {
requestParts.push({ type: 'ref', index: p1, value: p2 });
requestParts.push({ type: 'ref', index: p1, value: p3 });
return '';
}

Expand Down Expand Up @@ -153,7 +153,7 @@ internals.buildPath = function (resultsData, pos, parts) {
break;
}

value = Hoek.reach(ref, part.value);
value = part.value ? Hoek.reach(ref, part.value) : ref;

if (value === null || value === undefined) {
error = new Error('Reference not found');
Expand All @@ -174,7 +174,7 @@ internals.buildPath = function (resultsData, pos, parts) {

internals.payloadRegex = /^\$(\d+)(?:\.([^\s\$]*))?/;

internals.requestRegex = /(?:\/)(?:\$(\d+)\.)?([^\/\$]*)/g;
internals.requestRegex = /(?:\/)(?:\$(\d+))?(\.)?([^\/\$]*)/g;

internals.parsePayload = function (obj) {

Expand Down
8 changes: 8 additions & 0 deletions test/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,12 @@ describe('Batch', () => {
expect(res[11].id).to.equal('10');
expect(res[11].name).to.equal('Item');
});

it('substitutes index in url without any resultPath in url path parameters', async () => {

const res = await Internals.makeRequest(server, '{ "requests": [ {"method": "post", "path": "/returnInputtedInteger", "payload": {"id": 5}}, {"method": "get", "path": "/item/$0"} ] }');

expect(res[0]).to.equal(5);
expect(res[1].id).to.equal('5');
});
});

0 comments on commit ebaa36c

Please sign in to comment.