2014-07-31 14:51:10 -04:00
|
|
|
function parsePostData(query) {
|
|
|
|
var result = {};
|
|
|
|
query.split("&").forEach(function(part) {
|
|
|
|
var item = part.split("=");
|
|
|
|
result[item[0]] = decodeURIComponent(item[1]);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-31 17:26:44 -04:00
|
|
|
function response(code, obj) {
|
2014-07-31 14:51:10 -04:00
|
|
|
if (typeof code === "object") {
|
|
|
|
obj = code;
|
|
|
|
code = 200;
|
|
|
|
}
|
2014-07-31 17:26:44 -04:00
|
|
|
return [code, {"Content-Type": "application/json"}, obj];
|
2014-07-31 14:51:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function() {
|
|
|
|
var server = new Pretender(function() {
|
2014-08-01 17:26:43 -04:00
|
|
|
|
|
|
|
// Load any fixtures automatically
|
|
|
|
var self = this;
|
|
|
|
Ember.keys(require._eak_seen).forEach(function(entry) {
|
|
|
|
if (/^fixtures/.test(entry)) {
|
|
|
|
var fixture = require(entry, null, null, true);
|
|
|
|
if (fixture && fixture.default) {
|
|
|
|
var obj = fixture.default;
|
|
|
|
Ember.keys(obj).forEach(function(url) {
|
|
|
|
self.get(url, function() {
|
|
|
|
return response(obj[url]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-09-17 11:18:41 -04:00
|
|
|
this.get("/t/id_for/:slug", function() {
|
|
|
|
return response({id: 280, slug: "internationalization-localization", url: "/t/internationalization-localization/280"});
|
|
|
|
});
|
|
|
|
|
2014-08-01 17:26:43 -04:00
|
|
|
this.get("/404-body", function() {
|
|
|
|
return [200, {"Content-Type": "text/html"}, "<div class='page-not-found'>not found</div>"];
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/draft.json', function() {
|
|
|
|
return response({});
|
|
|
|
});
|
|
|
|
|
2014-07-31 14:51:10 -04:00
|
|
|
this.post('/session', function(request) {
|
|
|
|
var data = parsePostData(request.requestBody);
|
|
|
|
|
|
|
|
if (data.password === 'correct') {
|
2014-07-31 17:26:44 -04:00
|
|
|
return response({username: 'eviltrout'});
|
2014-07-31 14:51:10 -04:00
|
|
|
}
|
2014-07-31 17:26:44 -04:00
|
|
|
return response(400, {error: 'invalid login'});
|
2014-07-31 14:51:10 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
this.get('/users/hp.json', function() {
|
2014-07-31 17:26:44 -04:00
|
|
|
return response({"value":"32faff1b1ef1ac3","challenge":"61a3de0ccf086fb9604b76e884d75801"});
|
2014-07-31 14:51:10 -04:00
|
|
|
});
|
|
|
|
|
2014-07-31 17:06:00 -04:00
|
|
|
this.get('/session/csrf', function() {
|
2014-07-31 17:26:44 -04:00
|
|
|
return response({"csrf":"mgk906YLagHo2gOgM1ddYjAN4hQolBdJCqlY6jYzAYs="});
|
2014-07-31 17:06:00 -04:00
|
|
|
});
|
|
|
|
|
2014-07-31 14:51:10 -04:00
|
|
|
this.get('/users/check_username', function(request) {
|
|
|
|
if (request.queryParams.username === 'taken') {
|
2014-07-31 17:26:44 -04:00
|
|
|
return response({available: false, suggestion: 'nottaken'});
|
2014-07-31 14:51:10 -04:00
|
|
|
}
|
2014-07-31 17:26:44 -04:00
|
|
|
return response({available: true});
|
2014-07-31 14:51:10 -04:00
|
|
|
});
|
|
|
|
|
2014-07-31 17:26:44 -04:00
|
|
|
this.post('/users', function() {
|
|
|
|
return response({success: true});
|
2014-07-31 14:51:10 -04:00
|
|
|
});
|
2014-07-31 17:59:52 -04:00
|
|
|
|
|
|
|
this.get('/login.html', function() {
|
|
|
|
return [200, {}, 'LOGIN PAGE'];
|
|
|
|
});
|
2014-07-31 14:51:10 -04:00
|
|
|
});
|
|
|
|
|
2014-07-31 17:26:44 -04:00
|
|
|
|
|
|
|
server.prepareBody = function(body){
|
|
|
|
if (body && typeof body === "object") {
|
|
|
|
return JSON.stringify(body);
|
|
|
|
}
|
2014-08-01 17:26:43 -04:00
|
|
|
return body;
|
2014-07-31 17:26:44 -04:00
|
|
|
};
|
|
|
|
|
2014-07-31 14:51:10 -04:00
|
|
|
server.unhandledRequest = function(verb, path) {
|
2014-07-31 18:44:32 -04:00
|
|
|
var error = 'Unhandled request in test environment: ' + path + ' (' + verb + ')';
|
|
|
|
window.console.error(error);
|
|
|
|
throw error;
|
2014-07-31 14:51:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return server;
|
|
|
|
}
|