Comparing version 0.3.3 to 0.3.4
var assert = require('assert'); | ||
var req = require('request'); | ||
var request = require('supertest'); | ||
var spawn = require('child_process').spawn; | ||
@@ -15,2 +15,7 @@ module.exports = function() { | ||
}; | ||
var requestBody = { | ||
"method": "POST", | ||
"uri": "/user/:username", | ||
"response": profile | ||
}; | ||
@@ -21,4 +26,4 @@ this.hooks = require('../support/mock-service-hooks'); | ||
this.Given(/^I have valid user credentials$/, function(callback) { | ||
user = {}; | ||
credentials = { | ||
@@ -29,15 +34,7 @@ username: 'foo', | ||
var child = spawn('curl', ['-X', 'POST', | ||
'-d', '\'{"method":"POST", "uri":"/user/:username", "response":{"bar":"baz"}}\'', | ||
'http://localhost:3001/api', | ||
'--header', '"Content-Type:application/json"']); | ||
child.on('error', function(error) { | ||
assert.fail(false, true, error); | ||
callback(); | ||
}); | ||
child.on('exit', function(code) { | ||
console.log('posted: ' + code); | ||
callback(); | ||
}); | ||
req({ | ||
method: 'POST', | ||
uri: 'http://localhost:3001/api', | ||
json: requestBody | ||
}, callback); | ||
@@ -47,3 +44,2 @@ }); | ||
this.When(/^I submit my username and password$/, function(callback) { | ||
console.log('check'); | ||
request('http://localhost:3001') | ||
@@ -50,0 +46,0 @@ .post('/user/' + credentials.username) |
@@ -12,6 +12,6 @@ 'use strict'; | ||
this.After(function(callback) { | ||
// spawn('caddis', ['stop']) | ||
// .on('exit', callback); | ||
spawn('caddis', ['stop']) | ||
.on('exit', callback); | ||
}); | ||
}; |
@@ -7,2 +7,7 @@ 'use strict'; | ||
var isValidInt = function(value) { | ||
var n = parseInt(value, 10); | ||
return !isNaN(n) && value % 1 === 0; | ||
}; | ||
// ## CORS middleware | ||
@@ -34,3 +39,8 @@ // see: http://stackoverflow.com/questions/7067966/how-to-allow-cors-in-express-nodejs | ||
app[config.method.toLowerCase()](config.uri, function(request, response) { | ||
response.json(config.response); | ||
if(config.status && isValidInt(config.status)) { | ||
response.status(parseInt(config.status, 10)).json(config.response); | ||
} | ||
else { | ||
response.json(config.response); | ||
} | ||
}); | ||
@@ -37,0 +47,0 @@ res.json({result:true}); |
{ | ||
"name": "caddis", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -39,3 +39,3 @@ Caddis | ||
_There's wit in there somewhere._ | ||
_It may be a stretch, but there's wit in there somewhere..._ | ||
@@ -57,3 +57,3 @@ Why? | ||
As such, [caddis](https://github.com/bustardcelly/caddis) as born. | ||
As such, [caddis](https://github.com/bustardcelly/caddis) was born. | ||
@@ -88,2 +88,10 @@ How | ||
## Post Data | ||
The post body data that is sent to [caddis](https://github.com/bustardcelly/caddis) has the following properties: | ||
* method: The REST method | ||
* uri: The endpoint of the service to hit (requires prepended '/') | ||
* response: The JSON object to return on request | ||
* statusCode: [Optional] Status code to return. Defaults to 200 | ||
Tests | ||
@@ -90,0 +98,0 @@ --- |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21623
31
358
125
2