From e63cdc50bb6b52ca3c0bd19faa2c9774033e96c2 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 31 Jul 2014 17:26:44 -0400 Subject: [PATCH] TESTS: Add `JSON.stringify` step to `prepareBody` where it should be. --- .../helpers/create-pretender.js.es6 | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6 index bbb7150be75..74dfcc33197 100644 --- a/test/javascripts/helpers/create-pretender.js.es6 +++ b/test/javascripts/helpers/create-pretender.js.es6 @@ -9,12 +9,12 @@ function parsePostData(query) { return result; } -function json(code, obj) { +function response(code, obj) { if (typeof code === "object") { obj = code; code = 200; } - return [code, {"Content-Type": "application/json"}, JSON.stringify(obj)]; + return [code, {"Content-Type": "application/json"}, obj]; } export default function() { @@ -23,31 +23,38 @@ export default function() { var data = parsePostData(request.requestBody); if (data.password === 'correct') { - return json({username: 'eviltrout'}); + return response({username: 'eviltrout'}); } - return json(400, {error: 'invalid login'}); + return response(400, {error: 'invalid login'}); }); this.get('/users/hp.json', function() { - return json({"value":"32faff1b1ef1ac3","challenge":"61a3de0ccf086fb9604b76e884d75801"}); + return response({"value":"32faff1b1ef1ac3","challenge":"61a3de0ccf086fb9604b76e884d75801"}); }); this.get('/session/csrf', function() { - return json({"csrf":"mgk906YLagHo2gOgM1ddYjAN4hQolBdJCqlY6jYzAYs="}); + return response({"csrf":"mgk906YLagHo2gOgM1ddYjAN4hQolBdJCqlY6jYzAYs="}); }); this.get('/users/check_username', function(request) { if (request.queryParams.username === 'taken') { - return json({available: false, suggestion: 'nottaken'}); + return response({available: false, suggestion: 'nottaken'}); } - return json({available: true}); + return response({available: true}); }); - this.post('/users', function(request) { - return json({success: true}); + this.post('/users', function() { + return response({success: true}); }); }); + + server.prepareBody = function(body){ + if (body && typeof body === "object") { + return JSON.stringify(body); + } + }; + server.unhandledRequest = function(verb, path) { console.error('Unhandled request in test environment: ' + path + ' (' + verb + ')'); };