FIX: Pretender errors were being swallowed

Lots of test were broken and needed fixes.
This commit is contained in:
Robin Ward 2020-08-05 15:07:41 -04:00
parent b0564205d9
commit f1b6b1bd0e
4 changed files with 29 additions and 21 deletions

View File

@ -119,9 +119,14 @@ export function ajax() {
args.error = (xhr, textStatus, errorThrown) => {
// 0 represents the `UNSENT` state
if (xhr.readyState === 0 && !isTesting()) {
if (xhr.readyState === 0) {
// Make sure we log pretender errors in test mode
if (isTesting()) {
throw errorThrown;
}
return;
}
handleLogoff(xhr);
// note: for bad CSRF we don't loop an extra request right away.

View File

@ -859,10 +859,6 @@ QUnit.test("can reply to a private message", async assert => {
return [200, { "Content-Type": "application/json" }, {}];
});
// a bit messy but we need a fake here cause we issue a route transition
// to the new post
server.get("/t/34/4.json", () => server.get("/t/34.json"));
await visit("/t/34");
await click(".topic-post:eq(0) button.reply");
await fillIn(".d-editor-input", "this is the *content* of the reply");

View File

@ -2,20 +2,22 @@ import User from "discourse/models/user";
export function parsePostData(query) {
const result = {};
query.split("&").forEach(function(part) {
const item = part.split("=");
const firstSeg = decodeURIComponent(item[0]);
const m = /^([^\[]+)\[(.+)\]/.exec(firstSeg);
if (query) {
query.split("&").forEach(function(part) {
const item = part.split("=");
const firstSeg = decodeURIComponent(item[0]);
const m = /^([^\[]+)\[(.+)\]/.exec(firstSeg);
const val = decodeURIComponent(item[1]).replace(/\+/g, " ");
if (m) {
let key = m[1];
result[key] = result[key] || {};
result[key][m[2].replace("][", ".")] = val;
} else {
result[firstSeg] = val;
}
});
const val = decodeURIComponent(item[1]).replace(/\+/g, " ");
if (m) {
let key = m[1];
result[key] = result[key] || {};
result[key][m[2].replace("][", ".")] = val;
} else {
result[firstSeg] = val;
}
});
}
return result;
}
@ -245,6 +247,7 @@ export function applyDefaultHandlers(pretender) {
pretender.get("/t/280.json", () => response(fixturesByUrl["/t/280/1.json"]));
pretender.get("/t/34.json", () => response(fixturesByUrl["/t/34/1.json"]));
pretender.get("/t/34/4.json", () => response(fixturesByUrl["/t/34/1.json"]));
pretender.get("/t/280/:post_number.json", () =>
response(fixturesByUrl["/t/280/1.json"])
);
@ -255,7 +258,9 @@ export function applyDefaultHandlers(pretender) {
pretender.get("/t/12.json", () => response(fixturesByUrl["/t/12/1.json"]));
pretender.put("/t/1234/re-pin", success);
pretender.get("/t/2480.json", () => response(fixturesByUrl["/t/2480/1.json"]));
pretender.get("/t/2480.json", () =>
response(fixturesByUrl["/t/2480/1.json"])
);
pretender.get("/t/id_for/:slug", () => {
return response({

View File

@ -4,7 +4,9 @@ import badgeFixtures from "fixtures/user-badges";
QUnit.module("model:user-badge");
QUnit.test("createFromJson single", assert => {
const userBadge = UserBadge.createFromJson(badgeFixtures["/user_badges"]);
const userBadge = UserBadge.createFromJson(
JSON.parse(JSON.stringify(badgeFixtures["/user_badges"]))
);
assert.ok(!Array.isArray(userBadge), "does not return an array");
assert.equal(
userBadge.get("badge.name"),
@ -25,7 +27,7 @@ QUnit.test("createFromJson single", assert => {
QUnit.test("createFromJson array", assert => {
const userBadges = UserBadge.createFromJson(
badgeFixtures["/user-badges/:username"]
JSON.parse(JSON.stringify(badgeFixtures["/user-badges/:username"]))
);
assert.ok(Array.isArray(userBadges), "returns an array");
assert.equal(