1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/wizard/tests/pretender.js.es6

36 Zeilen
700 B
Text

2022-02-15 07:16:21 +01:00
import Pretender from "pretender";
function response(code, obj) {
if (typeof code === "object") {
obj = code;
code = 200;
}
return [code, { "Content-Type": "application/json" }, obj];
}
2022-03-16 12:33:34 +01:00
export { response };
2022-02-15 07:16:21 +01:00
2022-03-16 12:33:34 +01:00
export default function (cb) {
let server = new Pretender();
2022-02-15 07:16:21 +01:00
2022-03-16 12:33:34 +01:00
if (cb) {
server = cb(server);
}
2022-02-15 07:16:21 +01:00
server.prepareBody = function (body) {
if (body && typeof body === "object") {
return JSON.stringify(body);
}
return body;
};
2022-03-16 12:46:16 +01:00
server.unhandledRequest = function (verb, path) {
2022-02-15 07:16:21 +01:00
const error =
"Unhandled request in test environment: " + path + " (" + verb + ")";
window.console.error(error);
throw error;
};
return server;
}