2017-02-01 04:42:12 +08:00
|
|
|
export function parsePostData(query) {
|
2015-03-14 00:08:28 +08:00
|
|
|
const result = {};
|
2014-08-01 02:51:10 +08:00
|
|
|
query.split("&").forEach(function(part) {
|
2015-03-14 00:08:28 +08:00
|
|
|
const item = part.split("=");
|
2015-04-10 02:54:17 +08:00
|
|
|
const firstSeg = decodeURIComponent(item[0]);
|
2019-01-04 01:03:01 +08:00
|
|
|
const m = /^([^\[]+)\[(.+)\]/.exec(firstSeg);
|
2015-04-10 02:54:17 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
const val = decodeURIComponent(item[1]).replace(/\+/g, " ");
|
2015-04-10 02:54:17 +08:00
|
|
|
if (m) {
|
2019-01-04 01:03:01 +08:00
|
|
|
let key = m[1];
|
|
|
|
result[key] = result[key] || {};
|
|
|
|
result[key][m[2].replace("][", ".")] = val;
|
2015-04-10 02:54:17 +08:00
|
|
|
} else {
|
|
|
|
result[firstSeg] = val;
|
|
|
|
}
|
2014-08-01 02:51:10 +08:00
|
|
|
});
|
|
|
|
return result;
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2014-08-01 02:51:10 +08:00
|
|
|
|
2017-09-13 23:54:49 +08:00
|
|
|
export function response(code, obj) {
|
2014-08-01 02:51:10 +08:00
|
|
|
if (typeof code === "object") {
|
|
|
|
obj = code;
|
|
|
|
code = 200;
|
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
return [code, { "Content-Type": "application/json" }, obj];
|
2014-08-01 02:51:10 +08:00
|
|
|
}
|
|
|
|
|
2017-09-13 23:54:49 +08:00
|
|
|
export function success() {
|
|
|
|
return response({ success: true });
|
|
|
|
}
|
|
|
|
|
2015-12-02 04:31:15 +08:00
|
|
|
const loggedIn = () => !!Discourse.User.current();
|
|
|
|
const helpers = { response, success, parsePostData };
|
2018-08-20 15:46:02 +08:00
|
|
|
export let fixturesByUrl;
|
2015-04-02 02:18:46 +08:00
|
|
|
|
2014-08-01 02:51:10 +08:00
|
|
|
export default function() {
|
2015-03-14 00:08:28 +08:00
|
|
|
const server = new Pretender(function() {
|
2019-01-04 01:03:01 +08:00
|
|
|
// Autoload any `*-pretender` files
|
|
|
|
Object.keys(requirejs.entries).forEach(e => {
|
|
|
|
let m = e.match(/^helpers\/([a-z]+)\-pretender$/);
|
|
|
|
if (m && m[1] !== "create") {
|
|
|
|
let result = requirejs(e).default.call(this, helpers);
|
|
|
|
if (m[1] === "fixture") {
|
|
|
|
fixturesByUrl = result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-08-02 05:26:43 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/admin/plugins", () => response({ plugins: [] }));
|
2015-08-28 04:59:36 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/composer_messages", () => response({ composer_messages: [] }));
|
2015-04-02 02:18:46 +08:00
|
|
|
|
|
|
|
this.get("/latest.json", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
const json = fixturesByUrl["/latest.json"];
|
2015-04-02 02:18:46 +08:00
|
|
|
|
2019-05-02 01:24:29 +08:00
|
|
|
if (loggedIn()) {
|
|
|
|
// Stuff to let us post
|
|
|
|
json.topic_list.can_create_topic = true;
|
|
|
|
json.topic_list.draft_key = "new_topic";
|
|
|
|
json.topic_list.draft_sequence = 1;
|
|
|
|
}
|
|
|
|
return response(json);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get("/c/bug/l/latest.json", () => {
|
|
|
|
const json = fixturesByUrl["/c/bug/l/latest.json"];
|
|
|
|
|
2015-04-02 02:18:46 +08:00
|
|
|
if (loggedIn()) {
|
|
|
|
// Stuff to let us post
|
|
|
|
json.topic_list.can_create_topic = true;
|
|
|
|
json.topic_list.draft_key = "new_topic";
|
|
|
|
json.topic_list.draft_sequence = 1;
|
|
|
|
}
|
|
|
|
return response(json);
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/tags", () => {
|
|
|
|
return response({
|
|
|
|
tags: [
|
|
|
|
{
|
|
|
|
id: "eviltrout",
|
|
|
|
count: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
2016-11-11 02:33:31 +08:00
|
|
|
});
|
|
|
|
|
2019-05-28 10:40:27 +08:00
|
|
|
this.get("/tags/filter/search", () => {
|
|
|
|
return response({ results: [{ text: "monkey", count: 1 }] });
|
|
|
|
});
|
|
|
|
|
2017-09-11 22:31:38 +08:00
|
|
|
this.get(`/u/:username/emails.json`, () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response({ email: "eviltrout@example.com" });
|
2016-11-23 03:02:47 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/u/eviltrout.json", () => {
|
|
|
|
const json = fixturesByUrl["/u/eviltrout.json"];
|
2016-11-11 03:35:53 +08:00
|
|
|
json.user.can_edit = loggedIn();
|
2015-05-13 22:42:36 +08:00
|
|
|
return response(json);
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/u/eviltrout/summary.json", () => {
|
2016-08-03 01:21:06 +08:00
|
|
|
return response({
|
|
|
|
user_summary: {
|
2017-10-14 03:20:42 +08:00
|
|
|
topic_ids: [1234],
|
|
|
|
replies: [{ topic_id: 1234 }],
|
2018-06-15 23:03:24 +08:00
|
|
|
links: [{ topic_id: 1234, url: "https://eviltrout.com" }],
|
|
|
|
most_replied_to_users: [{ id: 333 }],
|
|
|
|
most_liked_by_users: [{ id: 333 }],
|
|
|
|
most_liked_users: [{ id: 333 }],
|
2018-07-19 04:37:50 +08:00
|
|
|
badges: [{ badge_id: 444 }],
|
|
|
|
top_categories: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
name: "bug",
|
|
|
|
color: "e9dd00",
|
|
|
|
text_color: "000000",
|
|
|
|
slug: "bug",
|
|
|
|
read_restricted: false,
|
|
|
|
parent_category_id: null,
|
|
|
|
topic_count: 1,
|
|
|
|
post_count: 1
|
|
|
|
}
|
|
|
|
]
|
2016-08-03 01:21:06 +08:00
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
badges: [{ id: 444, count: 1 }],
|
|
|
|
topics: [{ id: 1234, title: "cool title", url: "/t/1234/cool-title" }]
|
2016-08-03 01:21:06 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/u/eviltrout/invited_count.json", () => {
|
2016-11-11 02:33:31 +08:00
|
|
|
return response({
|
2018-06-15 23:03:24 +08:00
|
|
|
counts: { pending: 1, redeemed: 0, total: 0 }
|
2016-11-11 02:33:31 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/u/eviltrout/invited.json", () => {
|
|
|
|
return response({ invites: [{ id: 1 }] });
|
2016-11-11 02:33:31 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/topics/private-messages/eviltrout.json", () => {
|
2019-09-09 23:03:57 +08:00
|
|
|
return response(fixturesByUrl["/topics/private-messages/eviltrout.json"]);
|
2016-11-11 02:33:31 +08:00
|
|
|
});
|
|
|
|
|
2019-05-28 10:40:27 +08:00
|
|
|
this.get("/topics/feature_stats.json", () => {
|
|
|
|
return response({
|
|
|
|
pinned_in_category_count: 0,
|
|
|
|
pinned_globally_count: 0,
|
|
|
|
banner_count: 0
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-19 23:52:50 +08:00
|
|
|
this.put("/t/34/convert-topic/public", () => {
|
|
|
|
return response({});
|
|
|
|
});
|
|
|
|
|
2019-05-28 10:40:27 +08:00
|
|
|
this.put("/t/280/make-banner", () => {
|
|
|
|
return response({});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.put("/t/internationalization-localization/280/status", () => {
|
|
|
|
return response({
|
|
|
|
success: "OK",
|
|
|
|
topic_status_update: null
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-07 18:53:45 +08:00
|
|
|
this.post("/clicks/track", success);
|
2016-07-01 01:55:44 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/search", request => {
|
|
|
|
if (request.queryParams.q === "posts") {
|
2016-08-10 00:16:29 +08:00
|
|
|
return response({
|
2018-06-15 23:03:24 +08:00
|
|
|
posts: [
|
|
|
|
{
|
|
|
|
id: 1234
|
|
|
|
}
|
|
|
|
]
|
2016-08-10 00:16:29 +08:00
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
} else if (request.queryParams.q === "evil") {
|
2017-08-25 23:52:18 +08:00
|
|
|
return response({
|
2018-06-15 23:03:24 +08:00
|
|
|
posts: [
|
|
|
|
{
|
|
|
|
id: 1234
|
|
|
|
}
|
|
|
|
],
|
|
|
|
tags: [
|
|
|
|
{
|
|
|
|
id: 6,
|
|
|
|
name: "eviltrout"
|
|
|
|
}
|
|
|
|
]
|
2017-08-25 23:52:18 +08:00
|
|
|
});
|
2016-08-10 00:16:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return response({});
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.put("/u/eviltrout.json", () => response({ user: {} }));
|
2015-05-13 22:42:36 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/t/280.json", () => response(fixturesByUrl["/t/280/1.json"]));
|
2019-04-02 12:54:53 +08:00
|
|
|
this.get("/t/34.json", () => response(fixturesByUrl["/t/34/1.json"]));
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/t/280/20.json", () => response(fixturesByUrl["/t/280/1.json"]));
|
|
|
|
this.get("/t/28830.json", () => response(fixturesByUrl["/t/28830/1.json"]));
|
|
|
|
this.get("/t/9.json", () => response(fixturesByUrl["/t/9/1.json"]));
|
|
|
|
this.get("/t/12.json", () => response(fixturesByUrl["/t/12/1.json"]));
|
2017-09-12 01:14:22 +08:00
|
|
|
this.put("/t/1234/re-pin", success);
|
2015-08-14 00:49:13 +08:00
|
|
|
|
2015-11-24 05:45:05 +08:00
|
|
|
this.get("/t/id_for/:slug", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response({
|
|
|
|
id: 280,
|
|
|
|
slug: "internationalization-localization",
|
|
|
|
url: "/t/internationalization-localization/280"
|
|
|
|
});
|
2014-09-17 23:18:41 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.delete("/t/:id", success);
|
|
|
|
this.put("/t/:id/recover", success);
|
|
|
|
this.put("/t/:id/publish", success);
|
2016-07-01 01:55:44 +08:00
|
|
|
|
2015-11-24 05:45:05 +08:00
|
|
|
this.get("/404-body", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "text/html" },
|
|
|
|
"<div class='page-not-found'>not found</div>"
|
|
|
|
];
|
2014-08-02 05:26:43 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.delete("/draft.json", success);
|
|
|
|
this.post("/draft.json", success);
|
2015-04-10 06:33:37 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/u/:username/staff-info.json", () => response({}));
|
2015-04-22 02:36:46 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/post_action_users", () => {
|
2016-01-05 04:18:09 +08:00
|
|
|
return response({
|
|
|
|
post_action_users: [
|
2018-06-15 23:03:24 +08:00
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
username: "eviltrout",
|
|
|
|
avatar_template: "/user_avatar/default/eviltrout/{size}/1.png",
|
|
|
|
username_lower: "eviltrout"
|
|
|
|
}
|
|
|
|
]
|
2016-01-05 04:18:09 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/post_replies", () => {
|
|
|
|
return response({ post_replies: [{ id: 1234, cooked: "wat" }] });
|
2016-01-05 04:18:09 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/post_reply_histories", () => {
|
|
|
|
return response({ post_reply_histories: [{ id: 1234, cooked: "wat" }] });
|
2016-01-05 04:18:09 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/category_hashtags/check", () => {
|
|
|
|
return response({ valid: [{ slug: "bug", url: "/c/bugs" }] });
|
2016-06-15 02:31:51 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/categories_and_latest", () =>
|
|
|
|
response(fixturesByUrl["/categories_and_latest.json"])
|
|
|
|
);
|
2016-07-28 23:57:30 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.put("/categories/:category_id", request => {
|
2015-07-03 00:06:24 +08:00
|
|
|
const category = parsePostData(request.requestBody);
|
2016-07-28 23:57:30 +08:00
|
|
|
|
|
|
|
if (category.email_in === "duplicate@example.com") {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(422, { errors: ["duplicate email"] });
|
2016-07-28 23:57:30 +08:00
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
return response({ category });
|
2015-07-03 00:06:24 +08:00
|
|
|
});
|
|
|
|
|
FEATURE: Drafts view in user profile
* add drafts.json endpoint, user profile tab with drafts stream
* improve drafts stream display in user profile
* truncate excerpts in drafts list, better handling for resume draft action
* improve draft stream SQL query, add rspec tests
* if composer is open, quietly close it when user opens another draft from drafts stream; load PM draft only when user is in /u/username/messages (instead of /u/username)
* cleanup
* linting fixes
* apply prettier styling to modified files
* add client tests for drafts, includes a fixture for drafts.json
* improvements to code following review
* refresh drafts route when user deletes a draft open in the composer while being in the drafts route; minor prettier scss fix
* added more spec tests, deleted an acceptance test for removing drafts that was too finicky, formatting and code style fixes, added appEvent for draft:destroyed
* prettier, eslint fixes
* use "username_lower" from users table, added error handling for rejected promises
* adds guardian spec for can_see_drafts, adds improvements following code review
* move DraftsController spec to its own file
* fix failing drafts qunit test, use getOwner instead of deprecated this.container
* limit test fixture for draft.json testing to new_topic request only
2018-08-01 14:34:54 +08:00
|
|
|
this.get("/draft.json", request => {
|
|
|
|
if (request.queryParams.draft_key === "new_topic") {
|
|
|
|
return response(fixturesByUrl["/draft.json"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response({});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.get("/drafts.json", () => response(fixturesByUrl["/drafts.json"]));
|
2015-03-13 14:45:55 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.put("/queued_posts/:queued_post_id", function(request) {
|
|
|
|
return response({ queued_post: { id: request.params.queued_post_id } });
|
2015-04-11 05:00:50 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/queued_posts", function() {
|
2015-04-11 05:00:50 +08:00
|
|
|
return response({
|
2018-06-15 23:03:24 +08:00
|
|
|
queued_posts: [
|
|
|
|
{ id: 1, raw: "queued post text", can_delete_user: true }
|
|
|
|
]
|
2015-04-11 05:00:50 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.post("/session", function(request) {
|
2015-03-14 00:08:28 +08:00
|
|
|
const data = parsePostData(request.requestBody);
|
2014-08-01 02:51:10 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (data.password === "correct") {
|
|
|
|
return response({ username: "eviltrout" });
|
2014-08-01 02:51:10 +08:00
|
|
|
}
|
2016-08-06 00:01:16 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (data.password === "not-activated") {
|
|
|
|
return response({
|
|
|
|
error: "not active",
|
|
|
|
reason: "not_activated",
|
|
|
|
sent_to_email: "<small>eviltrout@example.com</small>",
|
|
|
|
current_email: "<small>current@example.com</small>"
|
|
|
|
});
|
2016-08-06 00:01:16 +08:00
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (data.password === "not-activated-edit") {
|
|
|
|
return response({
|
|
|
|
error: "not active",
|
|
|
|
reason: "not_activated",
|
|
|
|
sent_to_email: "eviltrout@example.com",
|
|
|
|
current_email: "current@example.com"
|
|
|
|
});
|
2017-04-06 04:14:22 +08:00
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (data.password === "need-second-factor") {
|
2018-06-28 16:12:32 +08:00
|
|
|
if (data.second_factor_token && data.second_factor_token === "123456") {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response({ username: "eviltrout" });
|
2017-12-22 09:18:12 +08:00
|
|
|
}
|
2018-02-20 14:44:51 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
return response({
|
|
|
|
error: "Invalid Second Factor",
|
|
|
|
reason: "invalid_second_factor",
|
2018-06-28 16:12:32 +08:00
|
|
|
backup_enabled: true,
|
2018-06-15 23:03:24 +08:00
|
|
|
sent_to_email: "eviltrout@example.com",
|
|
|
|
current_email: "current@example.com"
|
|
|
|
});
|
2017-12-22 09:18:12 +08:00
|
|
|
}
|
|
|
|
|
2019-10-02 10:08:41 +08:00
|
|
|
if (data.password === "need-security-key") {
|
|
|
|
if (data.securityKeyCredential) {
|
|
|
|
return response({ username: "eviltrout" });
|
|
|
|
}
|
|
|
|
|
|
|
|
return response({
|
|
|
|
error: "Invalid Security Key",
|
|
|
|
reason: "invalid_security_key",
|
|
|
|
backup_enabled: true,
|
|
|
|
sent_to_email: "eviltrout@example.com",
|
|
|
|
current_email: "current@example.com"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(400, { error: "invalid login" });
|
2014-08-01 02:51:10 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.post("/u/action/send_activation_email", success);
|
|
|
|
this.put("/u/update-activation-email", success);
|
2016-08-06 00:01:16 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/u/hp.json", function() {
|
|
|
|
return response({
|
|
|
|
value: "32faff1b1ef1ac3",
|
|
|
|
challenge: "61a3de0ccf086fb9604b76e884d75801"
|
|
|
|
});
|
2014-08-01 02:51:10 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/session/csrf", function() {
|
|
|
|
return response({ csrf: "mgk906YLagHo2gOgM1ddYjAN4hQolBdJCqlY6jYzAYs=" });
|
2014-08-01 05:06:00 +08:00
|
|
|
});
|
|
|
|
|
2018-08-01 11:21:46 +08:00
|
|
|
this.get("/groups/check-name", () => {
|
|
|
|
return response({ available: true });
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/u/check_username", function(request) {
|
|
|
|
if (request.queryParams.username === "taken") {
|
|
|
|
return response({ available: false, suggestion: "nottaken" });
|
2014-08-01 02:51:10 +08:00
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
return response({ available: true });
|
2014-08-01 02:51:10 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.post("/u", () => response({ success: true }));
|
2014-08-01 05:59:52 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/login.html", () => [200, {}, "LOGIN PAGE"]);
|
2014-10-08 04:03:51 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.delete("/posts/:post_id", success);
|
|
|
|
this.put("/posts/:post_id/recover", success);
|
|
|
|
this.get("/posts/:post_id/expand-embed", success);
|
2015-03-07 01:37:24 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.put("/posts/:post_id", request => {
|
2015-04-10 02:54:17 +08:00
|
|
|
const data = parsePostData(request.requestBody);
|
|
|
|
data.post.id = request.params.post_id;
|
|
|
|
data.post.version = 2;
|
|
|
|
return response(200, data.post);
|
2015-04-02 02:18:46 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/t/403.json", () => response(403, {}));
|
|
|
|
this.get("/t/404.json", () => response(404, "not found"));
|
|
|
|
this.get("/t/500.json", () => response(502, {}));
|
2015-05-28 01:53:49 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.put("/t/:slug/:id", request => {
|
2015-04-02 02:18:46 +08:00
|
|
|
const data = parsePostData(request.requestBody);
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, {
|
|
|
|
basic_topic: {
|
|
|
|
id: request.params.id,
|
|
|
|
title: data.title,
|
|
|
|
fancy_title: data.title,
|
|
|
|
slug: request.params.slug
|
|
|
|
}
|
|
|
|
});
|
2015-04-02 02:18:46 +08:00
|
|
|
});
|
2016-12-14 17:26:16 +08:00
|
|
|
|
|
|
|
this.get("groups", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, fixturesByUrl["/groups.json"]);
|
2016-12-14 17:26:16 +08:00
|
|
|
});
|
2015-04-02 02:18:46 +08:00
|
|
|
|
2018-10-11 21:20:17 +08:00
|
|
|
this.get("/groups.json", () => {
|
|
|
|
return response(200, fixturesByUrl["/groups.json?username=eviltrout"]);
|
|
|
|
});
|
|
|
|
|
2017-09-13 05:07:42 +08:00
|
|
|
this.get("groups/search.json", () => {
|
|
|
|
return response(200, []);
|
|
|
|
});
|
|
|
|
|
2018-03-14 19:40:28 +08:00
|
|
|
this.get("/topics/groups/discourse.json", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, fixturesByUrl["/topics/groups/discourse.json"]);
|
2016-04-12 01:16:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.get("/groups/discourse/mentions.json", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, fixturesByUrl["/groups/discourse/posts.json"]);
|
2016-04-12 01:16:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.get("/groups/discourse/messages.json", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, fixturesByUrl["/groups/discourse/posts.json"]);
|
2016-04-12 01:16:37 +08:00
|
|
|
});
|
|
|
|
|
2018-04-05 16:31:09 +08:00
|
|
|
this.get("/groups/moderators/members.json", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, fixturesByUrl["/groups/discourse/members.json"]);
|
2018-04-05 16:31:09 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/t/:topic_id/posts.json", request => {
|
2015-12-02 05:04:13 +08:00
|
|
|
const postIds = request.queryParams.post_ids;
|
2018-07-11 15:41:26 +08:00
|
|
|
const postNumber = parseInt(request.queryParams.post_number);
|
|
|
|
let posts;
|
|
|
|
|
|
|
|
if (postIds) {
|
|
|
|
posts = postIds.map(p => ({
|
|
|
|
id: parseInt(p),
|
|
|
|
post_number: parseInt(p)
|
|
|
|
}));
|
|
|
|
} else if (postNumber && request.queryParams.asc === "true") {
|
|
|
|
posts = _.range(postNumber + 1, postNumber + 6).map(p => ({
|
|
|
|
id: parseInt(p),
|
|
|
|
post_number: parseInt(p)
|
|
|
|
}));
|
|
|
|
} else if (postNumber && request.queryParams.asc === "false") {
|
|
|
|
posts = _.range(postNumber - 5, postNumber)
|
|
|
|
.reverse()
|
|
|
|
.map(p => ({
|
|
|
|
id: parseInt(p),
|
|
|
|
post_number: parseInt(p)
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2015-12-02 05:04:13 +08:00
|
|
|
return response(200, { post_stream: { posts } });
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/posts/:post_id/reply-history.json", () => {
|
|
|
|
return response(200, [{ id: 2222, post_number: 2222 }]);
|
2015-12-02 05:04:13 +08:00
|
|
|
});
|
|
|
|
|
2017-12-14 05:12:06 +08:00
|
|
|
this.get("/posts/:post_id/reply-ids.json", () => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, {
|
|
|
|
direct_reply_ids: [45],
|
|
|
|
all_reply_ids: [45, 100]
|
|
|
|
});
|
2017-12-14 05:12:06 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.post("/user_badges", () =>
|
|
|
|
response(200, fixturesByUrl["/user_badges"])
|
|
|
|
);
|
|
|
|
this.delete("/user_badges/:badge_id", success);
|
2016-07-01 01:55:44 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.post("/posts", function(request) {
|
2015-04-02 02:18:46 +08:00
|
|
|
const data = parsePostData(request.requestBody);
|
|
|
|
|
|
|
|
if (data.title === "this title triggers an error") {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(422, { errors: ["That title has already been taken"] });
|
2015-04-02 02:18:46 +08:00
|
|
|
}
|
2015-04-10 06:33:37 +08:00
|
|
|
|
|
|
|
if (data.raw === "enqueue this content please") {
|
2019-04-12 21:55:27 +08:00
|
|
|
return response(200, {
|
|
|
|
success: true,
|
|
|
|
action: "enqueued",
|
|
|
|
pending_post: {
|
|
|
|
id: 1234,
|
|
|
|
raw: data.raw
|
|
|
|
}
|
|
|
|
});
|
2015-04-10 06:33:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return response(200, {
|
|
|
|
success: true,
|
2018-06-15 23:03:24 +08:00
|
|
|
action: "create_post",
|
|
|
|
post: {
|
|
|
|
id: 12345,
|
|
|
|
topic_id: 280,
|
|
|
|
topic_slug: "internationalization-localization"
|
|
|
|
}
|
2015-04-10 06:33:37 +08:00
|
|
|
});
|
2015-04-02 02:18:46 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.post("/topics/timings", () => response(200, {}));
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
const siteText = { id: "site.test", value: "Test McTest" };
|
|
|
|
const overridden = {
|
|
|
|
id: "site.overridden",
|
|
|
|
value: "Overridden",
|
|
|
|
overridden: true
|
|
|
|
};
|
2016-08-06 00:01:16 +08:00
|
|
|
|
2019-03-21 17:16:58 +08:00
|
|
|
this.get("/admin/users/list/active.json", request => {
|
|
|
|
let store = [
|
2018-06-15 23:03:24 +08:00
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
username: "eviltrout",
|
|
|
|
email: "<small>eviltrout@example.com</small>"
|
2019-03-21 17:16:58 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
username: "discobot",
|
|
|
|
email: "<small>discobot_email</small>"
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2019-03-21 17:16:58 +08:00
|
|
|
];
|
2019-03-21 18:04:19 +08:00
|
|
|
|
|
|
|
const showEmails = request.queryParams.show_emails;
|
|
|
|
|
|
|
|
if (showEmails === "false") {
|
|
|
|
store = store.map(item => {
|
|
|
|
delete item.email;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-21 17:16:58 +08:00
|
|
|
const ascending = request.queryParams.ascending;
|
|
|
|
const order = request.queryParams.order;
|
|
|
|
|
|
|
|
if (order) {
|
|
|
|
store = store.sort(function(a, b) {
|
|
|
|
return a[order] - b[order];
|
|
|
|
});
|
|
|
|
}
|
2019-03-21 18:04:19 +08:00
|
|
|
|
2019-03-21 17:16:58 +08:00
|
|
|
if (ascending) {
|
|
|
|
store = store.reverse();
|
|
|
|
}
|
|
|
|
|
|
|
|
return response(200, store);
|
2016-08-06 00:01:16 +08:00
|
|
|
});
|
|
|
|
|
2019-02-26 17:43:24 +08:00
|
|
|
this.get("/admin/users/list/suspect.json", () => {
|
|
|
|
return response(200, [
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
username: "sam",
|
|
|
|
email: "<small>sam@example.com</small>"
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/admin/customize/site_texts", request => {
|
2015-12-01 04:22:58 +08:00
|
|
|
if (request.queryParams.overridden) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, { site_texts: [overridden] });
|
2015-12-01 04:22:58 +08:00
|
|
|
} else {
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, { site_texts: [siteText, overridden] });
|
2015-12-01 04:22:58 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/admin/customize/site_texts/:key", () =>
|
|
|
|
response(200, { site_text: siteText })
|
|
|
|
);
|
|
|
|
this.delete("/admin/customize/site_texts/:key", () =>
|
|
|
|
response(200, { site_text: siteText })
|
|
|
|
);
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.put("/admin/customize/site_texts/:key", request => {
|
2015-11-24 05:45:05 +08:00
|
|
|
const result = parsePostData(request.requestBody);
|
|
|
|
result.id = request.params.key;
|
|
|
|
result.can_revert = true;
|
2018-06-15 23:03:24 +08:00
|
|
|
return response(200, { site_text: result });
|
2015-04-02 02:18:46 +08:00
|
|
|
});
|
2016-07-06 02:58:58 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/tag_groups", () => response(200, { tag_groups: [] }));
|
2017-09-13 05:07:42 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/admin/users/1234.json", () => {
|
2017-09-13 05:07:42 +08:00
|
|
|
return response(200, {
|
|
|
|
id: 1234,
|
2018-06-15 23:03:24 +08:00
|
|
|
username: "regular"
|
2017-09-13 05:07:42 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-22 19:46:36 +08:00
|
|
|
this.get("/admin/users/1.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
id: 1,
|
|
|
|
username: "eviltrout",
|
|
|
|
admin: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/admin/users/2.json", () => {
|
2017-09-15 02:10:39 +08:00
|
|
|
return response(200, {
|
|
|
|
id: 2,
|
2018-06-15 23:03:24 +08:00
|
|
|
username: "sam",
|
2017-09-15 02:10:39 +08:00
|
|
|
admin: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.post("/admin/users/:user_id/generate_api_key", success);
|
|
|
|
this.delete("/admin/users/:user_id/revoke_api_key", success);
|
|
|
|
this.delete("/admin/users/:user_id.json", () =>
|
|
|
|
response(200, { deleted: true })
|
|
|
|
);
|
|
|
|
this.post("/admin/badges", success);
|
|
|
|
this.delete("/admin/badges/:id", success);
|
2016-12-09 05:08:44 +08:00
|
|
|
|
2019-01-10 18:06:01 +08:00
|
|
|
this.get("/admin/logs/staff_action_logs.json", () => {
|
2019-08-14 01:55:05 +08:00
|
|
|
return response(200, {
|
|
|
|
staff_action_logs: [],
|
|
|
|
extras: { user_history_actions: [] }
|
|
|
|
});
|
2019-01-10 18:06:01 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/admin/logs/watched_words", () => {
|
|
|
|
return response(200, fixturesByUrl["/admin/logs/watched_words.json"]);
|
2017-06-29 04:56:44 +08:00
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
this.delete("/admin/logs/watched_words/:id.json", success);
|
2017-06-29 04:56:44 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.post("/admin/logs/watched_words.json", request => {
|
2017-06-29 04:56:44 +08:00
|
|
|
const result = parsePostData(request.requestBody);
|
|
|
|
result.id = new Date().getTime();
|
|
|
|
return response(200, result);
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/admin/logs/search_logs.json", () => {
|
2017-11-15 08:13:50 +08:00
|
|
|
return response(200, [
|
2018-06-15 23:03:24 +08:00
|
|
|
{ term: "foobar", searches: 35, click_through: 6, unique: 16 }
|
2017-11-15 08:13:50 +08:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2019-03-29 09:48:20 +08:00
|
|
|
this.get("/admin/logs/search_logs/term.json", () => {
|
2017-12-20 10:41:31 +08:00
|
|
|
return response(200, {
|
2018-06-15 23:03:24 +08:00
|
|
|
term: {
|
|
|
|
type: "search_log_term",
|
|
|
|
title: "Search Count",
|
2019-03-29 09:48:20 +08:00
|
|
|
term: "ruby",
|
2018-06-15 23:03:24 +08:00
|
|
|
data: [{ x: "2017-07-20", y: 2 }]
|
|
|
|
}
|
2017-12-20 10:41:31 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-21 10:13:37 +08:00
|
|
|
this.post("/uploads/lookup-metadata", () => {
|
|
|
|
return response(200, {
|
|
|
|
imageFilename: "somefile.png",
|
|
|
|
imageFilesize: "10 KB",
|
|
|
|
imageWidth: "1",
|
|
|
|
imageHeight: "1"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-11-27 16:00:31 +08:00
|
|
|
this.get("/inline-onebox", request => {
|
|
|
|
if (
|
|
|
|
request.queryParams.urls.includes(
|
|
|
|
"http://www.example.com/has-title.html"
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "application/html" },
|
|
|
|
'{"inline-oneboxes":[{"url":"http://www.example.com/has-title.html","title":"This is a great title"}]}'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("/onebox", request => {
|
|
|
|
if (
|
|
|
|
request.queryParams.url === "http://www.example.com/has-title.html" ||
|
|
|
|
request.queryParams.url ===
|
|
|
|
"http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html"
|
|
|
|
) {
|
2016-12-09 05:08:44 +08:00
|
|
|
return [
|
|
|
|
200,
|
2018-06-15 23:03:24 +08:00
|
|
|
{ "Content-Type": "application/html" },
|
2016-12-09 05:08:44 +08:00
|
|
|
'<aside class="onebox"><article class="onebox-body"><h3><a href="http://www.example.com/article.html">An interesting article</a></h3></article></aside>'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (request.queryParams.url === "http://www.example.com/no-title.html") {
|
2016-12-09 05:08:44 +08:00
|
|
|
return [
|
|
|
|
200,
|
2018-06-15 23:03:24 +08:00
|
|
|
{ "Content-Type": "application/html" },
|
2016-12-09 05:08:44 +08:00
|
|
|
'<aside class="onebox"><article class="onebox-body"><p>No title</p></article></aside>'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (request.queryParams.url.indexOf("/internal-page.html") > -1) {
|
2017-02-09 04:34:42 +08:00
|
|
|
return [
|
|
|
|
200,
|
2018-06-15 23:03:24 +08:00
|
|
|
{ "Content-Type": "application/html" },
|
2017-02-09 04:34:42 +08:00
|
|
|
'<aside class="onebox"><article class="onebox-body"><h3><a href="/internal-page.html">Internal Page 4 U</a></h3></article></aside>'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
return [404, { "Content-Type": "application/html" }, ""];
|
2016-12-09 05:08:44 +08:00
|
|
|
});
|
2015-04-02 02:18:46 +08:00
|
|
|
});
|
2014-08-01 05:26:44 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
server.prepareBody = function(body) {
|
2014-08-01 05:26:44 +08:00
|
|
|
if (body && typeof body === "object") {
|
|
|
|
return JSON.stringify(body);
|
|
|
|
}
|
2014-08-02 05:26:43 +08:00
|
|
|
return body;
|
2014-08-01 05:26:44 +08:00
|
|
|
};
|
|
|
|
|
2014-08-01 02:51:10 +08:00
|
|
|
server.unhandledRequest = function(verb, path) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const error =
|
|
|
|
"Unhandled request in test environment: " + path + " (" + verb + ")";
|
2014-08-01 06:44:32 +08:00
|
|
|
window.console.error(error);
|
|
|
|
throw error;
|
2014-08-01 02:51:10 +08:00
|
|
|
};
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
server.checkPassthrough = request =>
|
|
|
|
request.requestHeaders["Discourse-Script"];
|
2014-08-01 02:51:10 +08:00
|
|
|
return server;
|
2017-09-12 01:14:22 +08:00
|
|
|
}
|