mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
Use response helper
These tests were using a much more verbose API. `response` is much simpler.
This commit is contained in:
parent
c9515ede2e
commit
f2a17feb3a
@ -282,14 +282,13 @@ acceptance("Avatar selector when selectable avatars is enabled", function (
|
|||||||
) {
|
) {
|
||||||
needs.user();
|
needs.user();
|
||||||
needs.settings({ selectable_avatars_enabled: true });
|
needs.settings({ selectable_avatars_enabled: true });
|
||||||
needs.pretender((server) => {
|
needs.pretender((server, helper) => {
|
||||||
server.get("/site/selectable-avatars.json", () => {
|
server.get("/site/selectable-avatars.json", () =>
|
||||||
return [
|
helper.response([
|
||||||
200,
|
"https://www.discourse.org",
|
||||||
{ "Content-Type": "application/json" },
|
"https://meta.discourse.org",
|
||||||
["https://www.discourse.org", "https://meta.discourse.org"],
|
])
|
||||||
];
|
);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("selectable avatars", async (assert) => {
|
test("selectable avatars", async (assert) => {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import { visit } from "@ember/test-helpers";
|
import { visit } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import pretender from "discourse/tests/helpers/create-pretender";
|
|
||||||
|
|
||||||
acceptance("User Routes", function (needs) {
|
acceptance("User Routes", function (needs) {
|
||||||
needs.user();
|
needs.user();
|
||||||
|
|
||||||
|
needs.pretender((server, helper) => {
|
||||||
|
server.get("/u/eviltrout%2F..%2F..%2F.json", () =>
|
||||||
|
helper.response(400, {})
|
||||||
|
);
|
||||||
|
});
|
||||||
test("Invalid usernames", async (assert) => {
|
test("Invalid usernames", async (assert) => {
|
||||||
pretender.get("/u/eviltrout%2F..%2F..%2F.json", () => {
|
|
||||||
return [400, { "Content-Type": "application/json" }, {}];
|
|
||||||
});
|
|
||||||
|
|
||||||
await visit("/u/eviltrout%2F..%2F..%2F/summary");
|
await visit("/u/eviltrout%2F..%2F..%2F/summary");
|
||||||
|
|
||||||
assert.equal(currentPath(), "exception-unknown");
|
assert.equal(currentPath(), "exception-unknown");
|
||||||
|
@ -88,45 +88,41 @@ export function applyDefaultHandlers(pretender) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
pretender.get("/tags", () => {
|
pretender.get("/tags", () => {
|
||||||
return [
|
return response({
|
||||||
200,
|
tags: [
|
||||||
{ "Content-Type": "application/json" },
|
{ id: "eviltrout", count: 1 },
|
||||||
{
|
{ id: "planned", text: "planned", count: 7, pm_count: 0 },
|
||||||
tags: [
|
{ id: "private", text: "private", count: 0, pm_count: 7 },
|
||||||
{ id: "eviltrout", count: 1 },
|
],
|
||||||
{ id: "planned", text: "planned", count: 7, pm_count: 0 },
|
extras: {
|
||||||
{ id: "private", text: "private", count: 0, pm_count: 7 },
|
tag_groups: [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "Ford Cars",
|
||||||
|
tags: [
|
||||||
|
{ id: "Escort", text: "Escort", count: 1, pm_count: 0 },
|
||||||
|
{ id: "focus", text: "focus", count: 3, pm_count: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "Honda Cars",
|
||||||
|
tags: [
|
||||||
|
{ id: "civic", text: "civic", count: 4, pm_count: 0 },
|
||||||
|
{ id: "accord", text: "accord", count: 2, pm_count: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "Makes",
|
||||||
|
tags: [
|
||||||
|
{ id: "ford", text: "ford", count: 5, pm_count: 0 },
|
||||||
|
{ id: "honda", text: "honda", count: 6, pm_count: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
extras: {
|
|
||||||
tag_groups: [
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "Ford Cars",
|
|
||||||
tags: [
|
|
||||||
{ id: "Escort", text: "Escort", count: 1, pm_count: 0 },
|
|
||||||
{ id: "focus", text: "focus", count: 3, pm_count: 0 },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "Honda Cars",
|
|
||||||
tags: [
|
|
||||||
{ id: "civic", text: "civic", count: 4, pm_count: 0 },
|
|
||||||
{ id: "accord", text: "accord", count: 2, pm_count: 0 },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "Makes",
|
|
||||||
tags: [
|
|
||||||
{ id: "ford", text: "ford", count: 5, pm_count: 0 },
|
|
||||||
{ id: "honda", text: "honda", count: 6, pm_count: 0 },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pretender.delete("/bookmarks/:id", () => response({}));
|
pretender.delete("/bookmarks/:id", () => response({}));
|
||||||
@ -467,11 +463,7 @@ export function applyDefaultHandlers(pretender) {
|
|||||||
pretender.put("/posts/:post_id", (request) => {
|
pretender.put("/posts/:post_id", (request) => {
|
||||||
const data = parsePostData(request.requestBody);
|
const data = parsePostData(request.requestBody);
|
||||||
if (data.post.raw === "this will 409") {
|
if (data.post.raw === "this will 409") {
|
||||||
return [
|
return response(409, { errors: ["edit conflict"] });
|
||||||
409,
|
|
||||||
{ "Content-Type": "application/json" },
|
|
||||||
{ errors: ["edit conflict"] },
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
data.post.id = request.params.post_id;
|
data.post.id = request.params.post_id;
|
||||||
data.post.version = 2;
|
data.post.version = 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user