Last active
December 9, 2015 18:43
-
-
Save designeng/5af79b921ec5965a3924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('../../server/app.js'); | |
var model = require('../../model.js'); | |
var request = require('supertest'); | |
var apitest = request(app); | |
describe('integration', function () { | |
it('model.json post should throw 500 error without args', function (done) { | |
apitest.post('/model.json') | |
.expect(500, done); | |
}); | |
it('model.json should accept post request', function (done) { | |
apitest.post('/model.json') | |
.send({ | |
method : 'call', | |
callPath : ['names','add'], | |
arguments : ['1234567'] | |
}) | |
.expect(200, done); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var url = require("url"); | |
var parseArgs = { | |
"jsonGraph": true, | |
"callPath": true, | |
"arguments": true, | |
"pathSuffixes": true, | |
"paths": true | |
}; | |
module.exports = function requestToContext(req) { | |
var queryMap = req.method === "POST" ? req.body : url.parse(req.url, true).query; | |
var context = {}; | |
if (queryMap) { | |
Object.keys(queryMap).forEach(function(key) { | |
var arg = queryMap[key]; | |
if (parseArgs[key] && arg != null && Object.prototype.toString.call(arg) !== "[object Array]") { | |
context[key] = JSON.parse(arg); | |
} else { | |
context[key] = arg; | |
} | |
}); | |
} | |
return context; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment