DEV: Consistently use `response` helper (#17627)
This commit is contained in:
parent
20462cf2b5
commit
b179fb98b1
|
@ -7,15 +7,15 @@ import {
|
|||
} from "discourse/tests/helpers/qunit-helpers";
|
||||
import I18n from "I18n";
|
||||
import { test } from "qunit";
|
||||
import pretender from "../helpers/create-pretender";
|
||||
import pretender, { response } from "../helpers/create-pretender";
|
||||
|
||||
acceptance("Dismiss notification confirmation", function (needs) {
|
||||
needs.user();
|
||||
|
||||
test("does not show modal when no high priority notifications", async function (assert) {
|
||||
pretender.put("/notifications/mark-read", () => {
|
||||
return [200, { "Content-Type": "application/json" }, { success: true }];
|
||||
});
|
||||
pretender.put("/notifications/mark-read", () =>
|
||||
response({ success: true })
|
||||
);
|
||||
|
||||
await visit("/");
|
||||
await click(".current-user");
|
||||
|
@ -50,9 +50,9 @@ acceptance("Dismiss notification confirmation", function (needs) {
|
|||
query(".dismiss-notification-confirmation-modal .btn-primary").innerText,
|
||||
I18n.t("notifications.dismiss_confirmation.dismiss")
|
||||
);
|
||||
pretender.put("/notifications/mark-read", () => {
|
||||
return [200, { "Content-Type": "application/json" }, { success: true }];
|
||||
});
|
||||
pretender.put("/notifications/mark-read", () =>
|
||||
response({ success: true })
|
||||
);
|
||||
|
||||
await click(".dismiss-notification-confirmation-modal .btn-primary");
|
||||
|
||||
|
|
|
@ -60,48 +60,36 @@ let callbackCount = 0;
|
|||
|
||||
acceptance("Second Factor Auth Page", function (needs) {
|
||||
needs.user();
|
||||
needs.pretender((server, helpers) => {
|
||||
needs.pretender((server, { parsePostData, response }) => {
|
||||
server.get("/session/2fa.json", (request) => {
|
||||
const response = { ...RESPONSES[request.queryParams.nonce] };
|
||||
const status = response.status || 200;
|
||||
delete response.status;
|
||||
return [status, { "Content-Type": "application/json" }, response];
|
||||
const responseBody = { ...RESPONSES[request.queryParams.nonce] };
|
||||
const status = responseBody.status || 200;
|
||||
delete responseBody.status;
|
||||
return response(status, responseBody);
|
||||
});
|
||||
|
||||
server.post("/session/2fa", (request) => {
|
||||
const params = helpers.parsePostData(request.requestBody);
|
||||
const params = parsePostData(request.requestBody);
|
||||
if (params.second_factor_token === WRONG_TOTP) {
|
||||
return [
|
||||
401,
|
||||
{ "Content-Type": "application/json" },
|
||||
{
|
||||
error: "invalid token man",
|
||||
ok: false,
|
||||
},
|
||||
];
|
||||
return response(401, {
|
||||
error: "invalid token man",
|
||||
ok: false,
|
||||
});
|
||||
} else {
|
||||
return [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{
|
||||
ok: true,
|
||||
callback_method: "PUT",
|
||||
callback_path: "/callback-path",
|
||||
redirect_url: "/",
|
||||
},
|
||||
];
|
||||
return response({
|
||||
ok: true,
|
||||
callback_method: "PUT",
|
||||
callback_path: "/callback-path",
|
||||
redirect_url: "/",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
server.put("/callback-path", () => {
|
||||
callbackCount++;
|
||||
return [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{
|
||||
whatever: true,
|
||||
},
|
||||
];
|
||||
return response(200, {
|
||||
whatever: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|||
import { click, render } from "@ember/test-helpers";
|
||||
import { count, exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
|
||||
module("Integration | Component | admin-report", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
@ -124,19 +124,15 @@ module("Integration | Component | admin-report", function (hooks) {
|
|||
});
|
||||
|
||||
test("rate limited", async function (assert) {
|
||||
pretender.get("/admin/reports/bulk", () => {
|
||||
return [
|
||||
429,
|
||||
{ "Content-Type": "application/json" },
|
||||
{
|
||||
errors: [
|
||||
"You’ve performed this action too many times. Please wait 10 seconds before trying again.",
|
||||
],
|
||||
error_type: "rate_limit",
|
||||
extras: { wait_seconds: 10 },
|
||||
},
|
||||
];
|
||||
});
|
||||
pretender.get("/admin/reports/bulk", () =>
|
||||
response(429, {
|
||||
errors: [
|
||||
"You’ve performed this action too many times. Please wait 10 seconds before trying again.",
|
||||
],
|
||||
error_type: "rate_limit",
|
||||
extras: { wait_seconds: 10 },
|
||||
})
|
||||
);
|
||||
|
||||
await render(hbs`<AdminReport @dataSourceName="signups_rate_limited" />`);
|
||||
|
||||
|
|
|
@ -3,15 +3,13 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|||
import { render } from "@ember/test-helpers";
|
||||
import { createFile } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
|
||||
module("Integration | Component | avatar-uploader", function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
pretender.post("/uploads.json", () => {
|
||||
return [200, { "Content-Type": "application/json" }, {}];
|
||||
});
|
||||
pretender.post("/uploads.json", () => response({}));
|
||||
});
|
||||
|
||||
test("default", async function (assert) {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { module, test } from "qunit";
|
|||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { click, render } from "@ember/test-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import EmberObject from "@ember/object";
|
||||
|
||||
|
@ -23,11 +23,7 @@ module("Integration | Component | badge-title", function (hooks) {
|
|||
}),
|
||||
]);
|
||||
|
||||
pretender.put("/u/eviltrout/preferences/badge_title", () => [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{},
|
||||
]);
|
||||
pretender.put("/u/eviltrout/preferences/badge_title", () => response({}));
|
||||
|
||||
await render(hbs`
|
||||
<BadgeTitle @selectableUserBadges={{this.selectableUserBadges}} />
|
||||
|
|
|
@ -3,7 +3,7 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|||
import { render } from "@ember/test-helpers";
|
||||
import { query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import { resetCache } from "pretty-text/upload-short-url";
|
||||
|
||||
module("Integration | Component | cook-text", function (hooks) {
|
||||
|
@ -21,19 +21,15 @@ module("Integration | Component | cook-text", function (hooks) {
|
|||
});
|
||||
|
||||
test("resolves short URLs", async function (assert) {
|
||||
pretender.post("/uploads/lookup-urls", () => {
|
||||
return [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
[
|
||||
{
|
||||
short_url: "upload://a.png",
|
||||
url: "/images/avatar.png",
|
||||
short_path: "/images/d-logo-sketch.png",
|
||||
},
|
||||
],
|
||||
];
|
||||
});
|
||||
pretender.post("/uploads/lookup-urls", () =>
|
||||
response([
|
||||
{
|
||||
short_url: "upload://a.png",
|
||||
url: "/images/avatar.png",
|
||||
short_path: "/images/d-logo-sketch.png",
|
||||
},
|
||||
])
|
||||
);
|
||||
|
||||
await render(
|
||||
hbs`<CookText @rawText="![an image](upload://a.png)" @class="post-body" />`
|
||||
|
|
|
@ -3,7 +3,7 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|||
import { click, render } from "@ember/test-helpers";
|
||||
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
|
@ -11,19 +11,13 @@ module("Integration | Component | invite-panel", function (hooks) {
|
|||
setupRenderingTest(hooks);
|
||||
|
||||
test("shows the invite link after it is generated", async function (assert) {
|
||||
pretender.get("/u/search/users", () => {
|
||||
return [200, { "Content-Type": "application/json" }, { users: [] }];
|
||||
});
|
||||
pretender.get("/u/search/users", () => response({ users: [] }));
|
||||
|
||||
pretender.post("/invites", () => {
|
||||
return [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{
|
||||
link: "http://example.com/invites/92c297e886a0ca03089a109ccd6be155",
|
||||
},
|
||||
];
|
||||
});
|
||||
pretender.post("/invites", () =>
|
||||
response({
|
||||
link: "http://example.com/invites/92c297e886a0ca03089a109ccd6be155",
|
||||
})
|
||||
);
|
||||
|
||||
this.currentUser.set("details", { can_invite_via_email: true });
|
||||
this.set("panel", {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { module, test } from "qunit";
|
|||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||
import { click, render } from "@ember/test-helpers";
|
||||
import { count, exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
|
||||
module("Integration | Component | site-header", function (hooks) {
|
||||
|
@ -43,7 +43,7 @@ module("Integration | Component | site-header", function (hooks) {
|
|||
|
||||
pretender.get("/notifications", () => {
|
||||
assert.ok(false, "it should not try to refresh notifications");
|
||||
return [403, { "Content-Type": "application/json" }, {}];
|
||||
return response(403, {});
|
||||
});
|
||||
|
||||
// Click anywhere
|
||||
|
|
|
@ -5,7 +5,7 @@ import { render } from "@ember/test-helpers";
|
|||
import { cloneJSON } from "discourse-common/lib/object";
|
||||
import NotificationFixtures from "discourse/tests/fixtures/notification-fixtures";
|
||||
import { hbs } from "ember-cli-htmlbars";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import I18n from "I18n";
|
||||
|
||||
function getNotificationsData() {
|
||||
|
@ -22,16 +22,12 @@ module(
|
|||
hooks.beforeEach(() => {
|
||||
pretender.get("/notifications", (request) => {
|
||||
queryParams = request.queryParams;
|
||||
return [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{ notifications: notificationsData },
|
||||
];
|
||||
return response({ notifications: notificationsData });
|
||||
});
|
||||
|
||||
pretender.put("/notifications/mark-read", () => {
|
||||
return [200, { "Content-Type": "application/json" }, { success: true }];
|
||||
});
|
||||
pretender.put("/notifications/mark-read", () =>
|
||||
response({ success: true })
|
||||
);
|
||||
});
|
||||
|
||||
hooks.afterEach(() => {
|
||||
|
|
|
@ -5,7 +5,7 @@ import Topic from "discourse/models/topic";
|
|||
import User from "discourse/models/user";
|
||||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { next } from "@ember/runloop";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import { settled } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
|
||||
|
@ -594,13 +594,9 @@ discourseModule("Unit | Controller | topic", function (hooks) {
|
|||
});
|
||||
|
||||
test("selectReplies", async function (assert) {
|
||||
pretender.get("/posts/1/reply-ids.json", () => {
|
||||
return [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
[{ id: 2, level: 1 }],
|
||||
];
|
||||
});
|
||||
pretender.get("/posts/1/reply-ids.json", () =>
|
||||
response([{ id: 2, level: 1 }])
|
||||
);
|
||||
|
||||
let model = topicWithStream({
|
||||
posts: [{ id: 1 }, { id: 2 }],
|
||||
|
@ -656,9 +652,7 @@ discourseModule("Unit | Controller | topic", function (hooks) {
|
|||
});
|
||||
|
||||
test("deletePost - no modal is shown if post does not have replies", function (assert) {
|
||||
pretender.get("/posts/2/reply-ids.json", () => {
|
||||
return [200, { "Content-Type": "application/json" }, []];
|
||||
});
|
||||
pretender.get("/posts/2/reply-ids.json", () => response([]));
|
||||
|
||||
let destroyed;
|
||||
const post = EmberObject.create({
|
||||
|
|
|
@ -3,15 +3,13 @@ import {
|
|||
linkSeenMentions,
|
||||
} from "discourse/lib/link-mentions";
|
||||
import { module, test } from "qunit";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import domFromString from "discourse-common/lib/dom-from-string";
|
||||
|
||||
module("Unit | Utility | link-mentions", function () {
|
||||
test("linkSeenMentions replaces users and groups", async function (assert) {
|
||||
pretender.get("/u/is_local_username", () => [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{
|
||||
pretender.get("/u/is_local_username", () =>
|
||||
response({
|
||||
valid: ["valid_user"],
|
||||
valid_groups: ["valid_group"],
|
||||
mentionable_groups: [
|
||||
|
@ -22,8 +20,8 @@ module("Unit | Utility | link-mentions", function () {
|
|||
],
|
||||
cannot_see: [],
|
||||
max_users_notified_per_group_mention: 100,
|
||||
},
|
||||
]);
|
||||
})
|
||||
);
|
||||
|
||||
await fetchUnseenMentions([
|
||||
"valid_user",
|
||||
|
|
|
@ -5,7 +5,7 @@ import Post from "discourse/models/post";
|
|||
import { Promise } from "rsvp";
|
||||
import User from "discourse/models/user";
|
||||
import createStore from "discourse/tests/helpers/create-store";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import sinon from "sinon";
|
||||
|
||||
function buildStream(id, stream) {
|
||||
|
@ -873,10 +873,6 @@ module("Unit | Model | post-stream", function () {
|
|||
);
|
||||
});
|
||||
|
||||
const response = (object) => {
|
||||
return [200, { "Content-Type": "application/json" }, object];
|
||||
};
|
||||
|
||||
pretender.get("/posts/4", () => {
|
||||
return response({ id: 4, post_number: 4 });
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { test } from "qunit";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import {
|
||||
discourseModule,
|
||||
publishToMessageBus,
|
||||
|
@ -10,19 +10,15 @@ import User from "discourse/models/user";
|
|||
|
||||
function setupPretender() {
|
||||
pretender.get(`/u/test/private-message-topic-tracking-state`, () => {
|
||||
return [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
[
|
||||
{
|
||||
topic_id: 123,
|
||||
highest_post_number: 12,
|
||||
last_read_post_number: 12,
|
||||
notification_level: 3,
|
||||
group_ids: [],
|
||||
},
|
||||
],
|
||||
];
|
||||
return response([
|
||||
{
|
||||
topic_id: 123,
|
||||
highest_post_number: 12,
|
||||
last_read_post_number: 12,
|
||||
notification_level: 3,
|
||||
group_ids: [],
|
||||
},
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|||
import { click, render } from "@ember/test-helpers";
|
||||
import { count, exists, query } from "discourse/tests/helpers/qunit-helpers";
|
||||
import hbs from "htmlbars-inline-precompile";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import EmberObject from "@ember/object";
|
||||
import I18n from "I18n";
|
||||
|
||||
|
@ -15,33 +15,29 @@ module("Integration | Component | Widget | discourse-poll", function (hooks) {
|
|||
hooks.beforeEach(function () {
|
||||
pretender.put("/polls/vote", () => {
|
||||
++requests;
|
||||
return [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{
|
||||
poll: {
|
||||
name: "poll",
|
||||
type: "regular",
|
||||
status: "open",
|
||||
results: "always",
|
||||
options: [
|
||||
{
|
||||
id: "1f972d1df351de3ce35a787c89faad29",
|
||||
html: "yes",
|
||||
votes: 1,
|
||||
},
|
||||
{
|
||||
id: "d7ebc3a9beea2e680815a1e4f57d6db6",
|
||||
html: "no",
|
||||
votes: 0,
|
||||
},
|
||||
],
|
||||
voters: 1,
|
||||
chart_type: "bar",
|
||||
},
|
||||
vote: ["1f972d1df351de3ce35a787c89faad29"],
|
||||
return response({
|
||||
poll: {
|
||||
name: "poll",
|
||||
type: "regular",
|
||||
status: "open",
|
||||
results: "always",
|
||||
options: [
|
||||
{
|
||||
id: "1f972d1df351de3ce35a787c89faad29",
|
||||
html: "yes",
|
||||
votes: 1,
|
||||
},
|
||||
{
|
||||
id: "d7ebc3a9beea2e680815a1e4f57d6db6",
|
||||
html: "no",
|
||||
votes: 0,
|
||||
},
|
||||
],
|
||||
voters: 1,
|
||||
chart_type: "bar",
|
||||
},
|
||||
];
|
||||
vote: ["1f972d1df351de3ce35a787c89faad29"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue