bassmaster
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -167,3 +167,3 @@ 'use strict'; | ||
if (!/^[\w:]+$/.test(value)) { | ||
if (!/^([\w:](-?|\.?))+$/.test(value)) { | ||
error = new Error('Reference value includes illegal characters'); | ||
@@ -277,3 +277,3 @@ break; | ||
const batchResult = batchData.result; | ||
const batchResult = internals.parseResult(batchData.result); | ||
@@ -287,3 +287,3 @@ resultsData.results[pos] = batchResult; | ||
const result = data.result; | ||
const result = internals.parseResult(data.result); | ||
resultsData.results[pos] = result; | ||
@@ -295,3 +295,17 @@ resultsData.resultsMap[pos] = result; | ||
internals.parseResult = function (result){ | ||
if (typeof (result) === 'string'){ | ||
try { | ||
return JSON.parse(result); | ||
} | ||
catch (e) { | ||
return result; | ||
} | ||
} | ||
else { | ||
return result; | ||
} | ||
}; | ||
internals.dispatch = function (batchRequest, request, callback) { | ||
@@ -298,0 +312,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"repository": "git://github.com/hapijs/bassmaster", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"main": "lib/index.js", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
@@ -206,2 +206,61 @@ 'use strict'; | ||
it('supports piping Id\'s with "-" (like a uuid) into the next request', (done) => { | ||
Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/interestingIds"}, {"method": "get", "path": "/item/$0.idWithDash"}] }', (res) => { | ||
expect(res.length).to.equal(2); | ||
expect(res[0].idWithDash).to.equal('55cf-687663-55cf687663'); | ||
expect(res[1].id).to.equal('55cf-687663-55cf687663'); | ||
done(); | ||
}); | ||
}); | ||
it('supports piping interesting Ids with "." (like a filename) into the next request', (done) => { | ||
Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/interestingIds"}, {"method": "get", "path": "/item/$0.idLikeFilename"}] }', (res) => { | ||
expect(res.length).to.equal(2); | ||
expect(res[0].idLikeFilename).to.equal('55cf687663.png'); | ||
expect(res[1].id).to.equal('55cf687663.png'); | ||
done(); | ||
}); | ||
}); | ||
it('supports piping interesting Ids with "-" and "." (like a filename) into the next request', (done) => { | ||
Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/interestingIds"}, {"method": "get", "path": "/item/$0.idLikeFileNameWithDash"}] }', (res) => { | ||
expect(res.length).to.equal(2); | ||
expect(res[0].idLikeFileNameWithDash).to.equal('55cf-687663-55cf687663.png'); | ||
expect(res[1].id).to.equal('55cf-687663-55cf687663.png'); | ||
done(); | ||
}); | ||
}); | ||
it('supports piping a deep response into the next request', (done) => { | ||
Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/deepItem"}, {"method": "post", "path": "/echo", "payload": "$0.inner.name"}, {"method": "post", "path": "/echo", "payload": "$0.inner.inner.name"}, {"method": "post", "path": "/echo", "payload": "$0.inner.inner.inner.name"}] }', (res) => { | ||
expect(res.length).to.equal(4); | ||
expect(res[0].id).to.equal('55cf687663'); | ||
expect(res[0].name).to.equal('Deep Item'); | ||
expect(res[1]).to.equal('Level 1'); | ||
expect(res[2]).to.equal('Level 2'); | ||
expect(res[3]).to.equal('Level 3'); | ||
done(); | ||
}); | ||
}); | ||
it('supports piping a deep response into an array in the next request', (done) => { | ||
Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/deepItem"}, {"method": "post", "path": "/echo", "payload": "$0.inner.inner.inner.array.0.name"}] }', (res) => { | ||
expect(res.length).to.equal(2); | ||
expect(res[0].id).to.equal('55cf687663'); | ||
expect(res[0].name).to.equal('Deep Item'); | ||
expect(res[1]).to.equal('Array Item 0'); | ||
done(); | ||
}); | ||
}); | ||
it('supports piping integer response into the next request', (done) => { | ||
@@ -220,2 +279,15 @@ | ||
it('supports the return of strings instead of json', (done) => { | ||
Internals.makeRequest(server, '{ "requests": [ {"method": "get", "path": "/string"}, {"method": "get", "path": "/item/$0.id"}] }', (res) => { | ||
expect(res.length).to.equal(2); | ||
expect(res[0].id).to.equal('55cf687663'); | ||
expect(res[0].name).to.equal('String Item'); | ||
expect(res[1].id).to.equal('55cf687663'); | ||
expect(res[1].name).to.equal('Item'); | ||
done(); | ||
}); | ||
}); | ||
it('supports piping a zero integer response into the next request', (done) => { | ||
@@ -222,0 +294,0 @@ |
@@ -32,2 +32,27 @@ 'use strict'; | ||
const deepItemHandler = function (request, reply) { | ||
return reply({ | ||
'id': '55cf687663', | ||
'name': 'Deep Item', | ||
'inner': { | ||
'name': 'Level 1', | ||
'inner': { | ||
'name': 'Level 2', | ||
'inner': { | ||
'name': 'Level 3', | ||
'array': [ | ||
{ | ||
'name': 'Array Item 0' | ||
}, | ||
{ | ||
'name': 'Array Item 1' | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
const item2Handler = function (request, reply) { | ||
@@ -74,2 +99,10 @@ | ||
const stringItemHandler = function (request, reply) { | ||
return reply('{' + | ||
'"id": "55cf687663",' + | ||
'"name": "String Item"' + | ||
'}'); | ||
}; | ||
const badCharHandler = function (request, reply) { | ||
@@ -94,2 +127,11 @@ | ||
const interestingIdsHandler = function (request, reply) { | ||
return reply({ | ||
'idWithDash': '55cf-687663-55cf687663', | ||
'idLikeFilename': '55cf687663.png', | ||
'idLikeFileNameWithDash': '55cf-687663-55cf687663.png' | ||
}); | ||
}; | ||
const fetch1 = function (request, next) { | ||
@@ -147,2 +189,3 @@ | ||
{ method: 'GET', path: '/item', handler: activeItemHandler }, | ||
{ method: 'GET', path: '/deepItem', handler: deepItemHandler }, | ||
{ method: 'GET', path: '/array', handler: arrayHandler }, | ||
@@ -154,2 +197,4 @@ { method: 'GET', path: '/item/{id}', handler: itemHandler }, | ||
{ method: 'GET', path: '/int/{id}', handler: integerItemHandler }, | ||
{ method: 'GET', path: '/string', handler: stringItemHandler }, | ||
{ method: 'GET', path: '/interestingIds', handler: interestingIdsHandler }, | ||
{ method: 'GET', path: '/error', handler: errorHandler }, | ||
@@ -156,0 +201,0 @@ { method: 'GET', path: '/badchar', handler: badCharHandler }, |
85406
1052