mirror of
https://github.com/discourse/discourse.git
synced 2025-02-22 12:17:12 +00:00
TESTS: Add JSON.stringify
step to prepareBody
where it should be.
This commit is contained in:
parent
c30ab6d428
commit
e63cdc50bb
@ -9,12 +9,12 @@ function parsePostData(query) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function json(code, obj) {
|
function response(code, obj) {
|
||||||
if (typeof code === "object") {
|
if (typeof code === "object") {
|
||||||
obj = code;
|
obj = code;
|
||||||
code = 200;
|
code = 200;
|
||||||
}
|
}
|
||||||
return [code, {"Content-Type": "application/json"}, JSON.stringify(obj)];
|
return [code, {"Content-Type": "application/json"}, obj];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
@ -23,31 +23,38 @@ export default function() {
|
|||||||
var data = parsePostData(request.requestBody);
|
var data = parsePostData(request.requestBody);
|
||||||
|
|
||||||
if (data.password === 'correct') {
|
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() {
|
this.get('/users/hp.json', function() {
|
||||||
return json({"value":"32faff1b1ef1ac3","challenge":"61a3de0ccf086fb9604b76e884d75801"});
|
return response({"value":"32faff1b1ef1ac3","challenge":"61a3de0ccf086fb9604b76e884d75801"});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.get('/session/csrf', function() {
|
this.get('/session/csrf', function() {
|
||||||
return json({"csrf":"mgk906YLagHo2gOgM1ddYjAN4hQolBdJCqlY6jYzAYs="});
|
return response({"csrf":"mgk906YLagHo2gOgM1ddYjAN4hQolBdJCqlY6jYzAYs="});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.get('/users/check_username', function(request) {
|
this.get('/users/check_username', function(request) {
|
||||||
if (request.queryParams.username === 'taken') {
|
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) {
|
this.post('/users', function() {
|
||||||
return json({success: true});
|
return response({success: true});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
server.prepareBody = function(body){
|
||||||
|
if (body && typeof body === "object") {
|
||||||
|
return JSON.stringify(body);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
server.unhandledRequest = function(verb, path) {
|
server.unhandledRequest = function(verb, path) {
|
||||||
console.error('Unhandled request in test environment: ' + path + ' (' + verb + ')');
|
console.error('Unhandled request in test environment: ' + path + ' (' + verb + ')');
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user