2019-11-13 12:35:19 -05:00
|
|
|
import User from "discourse/models/user";
|
|
|
|
|
2017-01-31 15:42:12 -05:00
|
|
|
export function parsePostData(query) {
|
2015-03-13 12:08:28 -04:00
|
|
|
const result = {};
|
2014-07-31 14:51:10 -04:00
|
|
|
query.split("&").forEach(function(part) {
|
2015-03-13 12:08:28 -04:00
|
|
|
const item = part.split("=");
|
2015-04-09 14:54:17 -04:00
|
|
|
const firstSeg = decodeURIComponent(item[0]);
|
2019-01-03 12:03:01 -05:00
|
|
|
const m = /^([^\[]+)\[(.+)\]/.exec(firstSeg);
|
2015-04-09 14:54:17 -04:00
|
|
|
|
|
|
|
const val = decodeURIComponent(item[1]).replace(/\+/g, " ");
|
|
|
|
if (m) {
|
2019-01-03 12:03:01 -05:00
|
|
|
let key = m[1];
|
|
|
|
result[key] = result[key] || {};
|
|
|
|
result[key][m[2].replace("][", ".")] = val;
|
2015-04-09 14:54:17 -04:00
|
|
|
} else {
|
|
|
|
result[firstSeg] = val;
|
|
|
|
}
|
2014-07-31 14:51:10 -04:00
|
|
|
});
|
|
|
|
return result;
|
2017-01-31 15:42:12 -05:00
|
|
|
}
|
2014-07-31 14:51:10 -04:00
|
|
|
|
2017-09-13 11:54:49 -04:00
|
|
|
export function response(code, obj) {
|
2014-07-31 14:51:10 -04:00
|
|
|
if (typeof code === "object") {
|
|
|
|
obj = code;
|
|
|
|
code = 200;
|
|
|
|
}
|
2014-07-31 17:26:44 -04:00
|
|
|
return [code, { "Content-Type": "application/json" }, obj];
|
2014-07-31 14:51:10 -04:00
|
|
|
}
|
|
|
|
|
2017-09-13 11:54:49 -04:00
|
|
|
export function success() {
|
|
|
|
return response({ success: true });
|
|
|
|
}
|
|
|
|
|
2019-11-13 12:35:19 -05:00
|
|
|
const loggedIn = () => !!User.current();
|
2015-12-01 15:31:15 -05:00
|
|
|
const helpers = { response, success, parsePostData };
|
2014-08-01 17:26:43 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
export let fixturesByUrl;
|
2015-04-01 14:18:46 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
export default new Pretender();
|
2015-04-01 14:18:46 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
export function applyDefaultHandlers(pretender) {
|
|
|
|
// 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(pretender, helpers);
|
|
|
|
if (m[1] === "fixture") {
|
|
|
|
fixturesByUrl = result;
|
2019-05-01 13:24:29 -04:00
|
|
|
}
|
2020-03-02 14:24:31 -05:00
|
|
|
}
|
|
|
|
});
|
2019-05-01 13:24:29 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/plugins", () => response({ plugins: [] }));
|
2019-05-01 13:24:29 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/composer_messages", () =>
|
|
|
|
response({ composer_messages: [] })
|
|
|
|
);
|
2015-04-01 14:18:46 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/latest.json", () => {
|
|
|
|
const json = fixturesByUrl["/latest.json"];
|
2016-11-10 13:33:31 -05:00
|
|
|
|
2020-03-02 14:24:31 -05: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);
|
|
|
|
});
|
2019-05-27 22:40:27 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/c/bug/1/l/latest.json", () => {
|
|
|
|
const json = fixturesByUrl["/c/bug/1/l/latest.json"];
|
2016-11-22 14:02:47 -05:00
|
|
|
|
2020-03-02 14:24:31 -05: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);
|
|
|
|
});
|
2015-05-13 10:42:36 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/tags", () => {
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "application/json" },
|
|
|
|
{
|
|
|
|
tags: [
|
|
|
|
{ id: "eviltrout", count: 1 },
|
|
|
|
{ id: "planned", text: "planned", count: 7, pm_count: 0 },
|
|
|
|
{ id: "private", text: "private", count: 0, pm_count: 7 }
|
|
|
|
],
|
|
|
|
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 }
|
|
|
|
]
|
|
|
|
},
|
2018-07-18 16:37:50 -04:00
|
|
|
{
|
|
|
|
id: 1,
|
2020-03-02 14:24:31 -05:00
|
|
|
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 }
|
|
|
|
]
|
2018-07-18 16:37:50 -04:00
|
|
|
}
|
|
|
|
]
|
2020-03-02 14:24:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
pretender.get("/tags/filter/search", () => {
|
|
|
|
return response({ results: [{ text: "monkey", count: 1 }] });
|
|
|
|
});
|
2016-08-02 13:21:06 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get(`/u/:username/emails.json`, request => {
|
|
|
|
if (request.params.username === "regular2") {
|
2016-11-10 13:33:31 -05:00
|
|
|
return response({
|
2020-03-02 14:24:31 -05:00
|
|
|
email: "regular2@example.com",
|
|
|
|
secondary_emails: [
|
|
|
|
"regular2alt1@example.com",
|
|
|
|
"regular2alt2@example.com"
|
|
|
|
]
|
2016-11-10 13:33:31 -05:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
}
|
|
|
|
return response({ email: "eviltrout@example.com" });
|
|
|
|
});
|
2016-11-10 13:33:31 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/u/eviltrout.json", () => {
|
|
|
|
const json = fixturesByUrl["/u/eviltrout.json"];
|
|
|
|
json.user.can_edit = loggedIn();
|
|
|
|
return response(json);
|
|
|
|
});
|
2016-11-10 13:33:31 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/u/eviltrout/summary.json", () => {
|
|
|
|
return response({
|
|
|
|
user_summary: {
|
|
|
|
topic_ids: [1234],
|
|
|
|
replies: [{ topic_id: 1234 }],
|
|
|
|
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 }],
|
|
|
|
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
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
badges: [{ id: 444, count: 1 }],
|
|
|
|
topics: [{ id: 1234, title: "cool title", url: "/t/1234/cool-title" }]
|
2016-11-10 13:33:31 -05:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2016-11-10 13:33:31 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/u/eviltrout/invited_count.json", () => {
|
|
|
|
return response({
|
|
|
|
counts: { pending: 1, redeemed: 0, total: 0 }
|
2019-05-27 22:40:27 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2019-05-27 22:40:27 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/u/eviltrout/invited.json", () => {
|
|
|
|
return response({ invites: [{ id: 1 }] });
|
|
|
|
});
|
2019-07-19 11:52:50 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/topics/private-messages/eviltrout.json", () => {
|
|
|
|
return response(fixturesByUrl["/topics/private-messages/eviltrout.json"]);
|
|
|
|
});
|
2019-05-27 22:40:27 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/topics/feature_stats.json", () => {
|
|
|
|
return response({
|
|
|
|
pinned_in_category_count: 0,
|
|
|
|
pinned_globally_count: 0,
|
|
|
|
banner_count: 0
|
2019-05-27 22:40:27 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2019-05-27 22:40:27 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.put("/t/34/convert-topic/public", () => {
|
|
|
|
return response({});
|
|
|
|
});
|
2016-06-30 13:55:44 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.put("/t/280/make-banner", () => {
|
|
|
|
return response({});
|
|
|
|
});
|
2016-08-09 12:16:29 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.put("/t/internationalization-localization/280/status", () => {
|
|
|
|
return response({
|
|
|
|
success: "OK",
|
|
|
|
topic_status_update: null
|
2016-08-09 12:16:29 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2016-08-09 12:16:29 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/clicks/track", success);
|
2015-05-13 10:42:36 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/search", request => {
|
|
|
|
if (request.queryParams.q === "posts") {
|
2014-09-17 11:18:41 -04:00
|
|
|
return response({
|
2020-03-02 14:24:31 -05:00
|
|
|
posts: [
|
|
|
|
{
|
|
|
|
id: 1234
|
|
|
|
}
|
|
|
|
]
|
2014-09-17 11:18:41 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
} else if (request.queryParams.q === "evil") {
|
2016-01-04 15:18:09 -05:00
|
|
|
return response({
|
2020-03-02 14:24:31 -05:00
|
|
|
posts: [
|
2016-01-04 15:18:09 -05:00
|
|
|
{
|
2020-03-02 14:24:31 -05:00
|
|
|
id: 1234
|
|
|
|
}
|
|
|
|
],
|
|
|
|
tags: [
|
|
|
|
{
|
|
|
|
id: 6,
|
|
|
|
name: "eviltrout"
|
2016-01-04 15:18:09 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
}
|
2016-01-04 15:18:09 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
return response({});
|
|
|
|
});
|
2016-01-04 15:18:09 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.put("/u/eviltrout.json", () => response({ user: {} }));
|
|
|
|
|
|
|
|
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/280/:post_number.json", () =>
|
|
|
|
response(fixturesByUrl["/t/280/1.json"])
|
|
|
|
);
|
|
|
|
pretender.get("/t/28830.json", () =>
|
|
|
|
response(fixturesByUrl["/t/28830/1.json"])
|
|
|
|
);
|
|
|
|
pretender.get("/t/9.json", () => response(fixturesByUrl["/t/9/1.json"]));
|
|
|
|
pretender.get("/t/12.json", () => response(fixturesByUrl["/t/12/1.json"]));
|
|
|
|
pretender.put("/t/1234/re-pin", success);
|
|
|
|
|
|
|
|
pretender.get("/t/id_for/:slug", () => {
|
|
|
|
return response({
|
|
|
|
id: 280,
|
|
|
|
slug: "internationalization-localization",
|
|
|
|
url: "/t/internationalization-localization/280"
|
2016-01-04 15:18:09 -05:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2016-01-04 15:18:09 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.delete("/t/:id", success);
|
|
|
|
pretender.put("/t/:id/recover", success);
|
|
|
|
pretender.put("/t/:id/publish", success);
|
2016-06-14 14:31:51 -04:00
|
|
|
|
2020-03-05 20:33:25 -05:00
|
|
|
pretender.get("/permalink-check.json", () => {
|
|
|
|
return response({
|
|
|
|
found: false,
|
|
|
|
html: "<div class='page-not-found'>not found</div>"
|
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2016-07-28 11:57:30 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.delete("/draft.json", success);
|
|
|
|
pretender.post("/draft.json", success);
|
2016-07-28 11:57:30 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/u/:username/staff-info.json", () => response({}));
|
2016-07-28 11:57:30 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/post_action_users", () => {
|
|
|
|
return response({
|
|
|
|
post_action_users: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
username: "eviltrout",
|
|
|
|
avatar_template: "/user_avatar/default/eviltrout/{size}/1.png",
|
|
|
|
username_lower: "eviltrout"
|
|
|
|
}
|
|
|
|
]
|
2015-07-02 12:06:24 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2015-07-02 12:06:24 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/post_replies", () => {
|
|
|
|
return response({ post_replies: [{ id: 1234, cooked: "wat" }] });
|
|
|
|
});
|
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 02:34:54 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/post_reply_histories", () => {
|
|
|
|
return response({ post_reply_histories: [{ id: 1234, cooked: "wat" }] });
|
|
|
|
});
|
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 02:34:54 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/category_hashtags/check", () => {
|
|
|
|
return response({ valid: [{ slug: "bug", url: "/c/bugs" }] });
|
|
|
|
});
|
2015-03-13 02:45:55 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/categories_and_latest", () =>
|
|
|
|
response(fixturesByUrl["/categories_and_latest.json"])
|
|
|
|
);
|
2015-04-10 17:00:50 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.put("/categories/:category_id", request => {
|
|
|
|
const category = parsePostData(request.requestBody);
|
|
|
|
category.id = parseInt(request.params.category_id, 10);
|
2015-04-10 17:00:50 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (category.email_in === "duplicate@example.com") {
|
|
|
|
return response(422, { errors: ["duplicate email"] });
|
|
|
|
}
|
2014-07-31 14:51:10 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
return response({ category });
|
|
|
|
});
|
2016-08-05 12:01:16 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/draft.json", request => {
|
|
|
|
if (request.queryParams.draft_key === "new_topic") {
|
|
|
|
return response(fixturesByUrl["/draft.json"]);
|
|
|
|
} else if (request.queryParams.draft_key.startsWith("topic_"))
|
|
|
|
return response(
|
|
|
|
fixturesByUrl[request.url] || {
|
|
|
|
draft: null,
|
|
|
|
draft_sequence: 0
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return response({});
|
|
|
|
});
|
2016-08-05 12:01:16 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/drafts.json", () => response(fixturesByUrl["/drafts.json"]));
|
2017-04-05 16:14:22 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.put("/queued_posts/:queued_post_id", function(request) {
|
|
|
|
return response({ queued_post: { id: request.params.queued_post_id } });
|
|
|
|
});
|
2018-02-20 01:44:51 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/queued_posts", function() {
|
|
|
|
return response({
|
|
|
|
queued_posts: [{ id: 1, raw: "queued post text", can_delete_user: true }]
|
|
|
|
});
|
|
|
|
});
|
2017-12-21 20:18:12 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/session", function(request) {
|
|
|
|
const data = parsePostData(request.requestBody);
|
|
|
|
|
|
|
|
if (data.password === "correct") {
|
|
|
|
return response({ username: "eviltrout" });
|
|
|
|
}
|
|
|
|
|
|
|
|
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>"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
});
|
|
|
|
}
|
2019-10-01 22:08:41 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (data.password === "need-second-factor") {
|
|
|
|
if (data.second_factor_token && data.second_factor_token === "123456") {
|
|
|
|
return response({ username: "eviltrout" });
|
2019-10-01 22:08:41 -04:00
|
|
|
}
|
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
return response({
|
|
|
|
failed: "FAILED",
|
|
|
|
ok: false,
|
|
|
|
error: "Invalid authentication code. Each code can only be used once.",
|
|
|
|
reason: "invalid_second_factor",
|
|
|
|
backup_enabled: true,
|
|
|
|
security_key_enabled: false,
|
|
|
|
totp_enabled: true,
|
|
|
|
multiple_second_factor_methods: false
|
|
|
|
});
|
|
|
|
}
|
2014-07-31 14:51:10 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (data.password === "need-security-key") {
|
|
|
|
if (data.securityKeyCredential) {
|
|
|
|
return response({ username: "eviltrout" });
|
|
|
|
}
|
2016-08-05 12:01:16 -04:00
|
|
|
|
2014-07-31 17:26:44 -04:00
|
|
|
return response({
|
2020-03-02 14:24:31 -05:00
|
|
|
failed: "FAILED",
|
|
|
|
ok: false,
|
|
|
|
error:
|
|
|
|
"The selected second factor method is not enabled for your account.",
|
|
|
|
reason: "not_enabled_second_factor_method",
|
|
|
|
backup_enabled: false,
|
|
|
|
security_key_enabled: true,
|
|
|
|
totp_enabled: false,
|
|
|
|
multiple_second_factor_methods: false,
|
|
|
|
allowed_credential_ids: ["allowed_credential_ids"],
|
|
|
|
challenge: "challenge"
|
2014-07-31 17:26:44 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
}
|
2014-07-31 14:51:10 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
return response(400, { error: "invalid login" });
|
|
|
|
});
|
2014-07-31 17:06:00 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/u/action/send_activation_email", success);
|
|
|
|
pretender.put("/u/update-activation-email", success);
|
2018-07-31 23:21:46 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/u/hp.json", function() {
|
|
|
|
return response({
|
|
|
|
value: "32faff1b1ef1ac3",
|
|
|
|
challenge: "61a3de0ccf086fb9604b76e884d75801"
|
2014-07-31 14:51:10 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
pretender.get("/session/csrf", function() {
|
|
|
|
return response({ csrf: "mgk906YLagHo2gOgM1ddYjAN4hQolBdJCqlY6jYzAYs=" });
|
|
|
|
});
|
2014-07-31 14:51:10 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/groups/check-name", () => {
|
|
|
|
return response({ available: true });
|
|
|
|
});
|
2014-07-31 17:59:52 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/u/check_username", function(request) {
|
|
|
|
if (request.queryParams.username === "taken") {
|
|
|
|
return response({ available: false, suggestion: "nottaken" });
|
|
|
|
}
|
|
|
|
return response({ available: true });
|
|
|
|
});
|
2014-10-07 16:03:51 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/u", () => response({ success: true }));
|
2015-03-06 12:37:24 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/login.html", () => [200, {}, "LOGIN PAGE"]);
|
2015-04-01 14:18:46 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.delete("/posts/:post_id", success);
|
|
|
|
pretender.put("/posts/:post_id/recover", success);
|
|
|
|
pretender.get("/posts/:post_id/expand-embed", success);
|
2015-05-27 13:53:49 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.put("/posts/:post_id", request => {
|
|
|
|
const data = parsePostData(request.requestBody);
|
|
|
|
if (data.post.raw === "this will 409") {
|
|
|
|
return [
|
|
|
|
409,
|
|
|
|
{ "Content-Type": "application/json" },
|
|
|
|
{ errors: ["edit conflict"] }
|
|
|
|
];
|
|
|
|
}
|
|
|
|
data.post.id = request.params.post_id;
|
|
|
|
data.post.version = 2;
|
|
|
|
return response(200, data.post);
|
|
|
|
});
|
2019-12-09 13:55:08 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/t/403.json", () => response(403, {}));
|
|
|
|
pretender.get("/t/404.json", () => response(404, "not found"));
|
|
|
|
pretender.get("/t/500.json", () => response(502, {}));
|
2015-04-01 14:18:46 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.put("/t/:slug/:id", request => {
|
|
|
|
const isJSON = request.requestHeaders["Content-Type"].includes(
|
|
|
|
"application/json"
|
|
|
|
);
|
2016-12-14 04:26:16 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
const data = isJSON
|
|
|
|
? JSON.parse(request.requestBody)
|
|
|
|
: parsePostData(request.requestBody);
|
2015-04-01 14:18:46 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
return response(200, {
|
|
|
|
basic_topic: {
|
|
|
|
id: request.params.id,
|
|
|
|
title: data.title,
|
|
|
|
fancy_title: data.title,
|
|
|
|
slug: request.params.slug
|
|
|
|
}
|
2018-10-11 09:20:17 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2018-10-11 09:20:17 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("groups", () => {
|
|
|
|
return response(200, fixturesByUrl["/groups.json"]);
|
|
|
|
});
|
2017-09-12 17:07:42 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/groups.json", () => {
|
|
|
|
return response(200, fixturesByUrl["/groups.json?username=eviltrout"]);
|
|
|
|
});
|
2016-04-11 13:16:37 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("groups/search.json", () => {
|
|
|
|
return response(200, []);
|
|
|
|
});
|
2016-04-11 13:16:37 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/topics/groups/discourse.json", () => {
|
|
|
|
return response(200, fixturesByUrl["/topics/groups/discourse.json"]);
|
|
|
|
});
|
2016-04-11 13:16:37 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/groups/discourse/mentions.json", () => {
|
|
|
|
return response(200, fixturesByUrl["/groups/discourse/posts.json"]);
|
|
|
|
});
|
2018-04-05 04:31:09 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/groups/discourse/messages.json", () => {
|
|
|
|
return response(200, fixturesByUrl["/groups/discourse/posts.json"]);
|
|
|
|
});
|
2018-07-11 03:41:26 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/groups/moderators/members.json", () => {
|
|
|
|
return response(200, fixturesByUrl["/groups/discourse/members.json"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
pretender.get("/t/:topic_id/posts.json", request => {
|
|
|
|
const postIds = request.queryParams.post_ids;
|
|
|
|
const postNumber = parseInt(request.queryParams.post_number, 10);
|
|
|
|
let posts;
|
|
|
|
|
|
|
|
if (postIds) {
|
|
|
|
posts = postIds.map(p => ({
|
|
|
|
id: parseInt(p, 10),
|
|
|
|
post_number: parseInt(p, 10)
|
|
|
|
}));
|
|
|
|
} else if (postNumber && request.queryParams.asc === "true") {
|
|
|
|
posts = _.range(postNumber + 1, postNumber + 6).map(p => ({
|
|
|
|
id: parseInt(p, 10),
|
|
|
|
post_number: parseInt(p, 10)
|
|
|
|
}));
|
|
|
|
} else if (postNumber && request.queryParams.asc === "false") {
|
|
|
|
posts = _.range(postNumber - 5, postNumber)
|
|
|
|
.reverse()
|
|
|
|
.map(p => ({
|
2019-11-12 04:47:42 -05:00
|
|
|
id: parseInt(p, 10),
|
|
|
|
post_number: parseInt(p, 10)
|
2018-07-11 03:41:26 -04:00
|
|
|
}));
|
2020-03-02 14:24:31 -05:00
|
|
|
}
|
2018-07-11 03:41:26 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
return response(200, { post_stream: { posts } });
|
|
|
|
});
|
2015-12-01 16:04:13 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/posts/:post_id/reply-history.json", () => {
|
|
|
|
return response(200, [{ id: 2222, post_number: 2222 }]);
|
|
|
|
});
|
2015-12-01 16:04:13 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/posts/:post_id/reply-ids.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
direct_reply_ids: [45],
|
|
|
|
all_reply_ids: [45, 100]
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2017-12-13 16:12:06 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/user_badges", () =>
|
|
|
|
response(200, fixturesByUrl["/user_badges"])
|
|
|
|
);
|
|
|
|
pretender.delete("/user_badges/:badge_id", success);
|
2015-04-09 18:33:37 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/posts", function(request) {
|
|
|
|
const data = parsePostData(request.requestBody);
|
2015-04-09 18:33:37 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (data.title === "this title triggers an error") {
|
|
|
|
return response(422, { errors: ["That title has already been taken"] });
|
|
|
|
}
|
2019-11-29 09:30:54 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (data.raw === "enqueue this content please") {
|
2015-04-09 18:33:37 -04:00
|
|
|
return response(200, {
|
|
|
|
success: true,
|
2020-03-02 14:24:31 -05:00
|
|
|
action: "enqueued",
|
|
|
|
pending_post: {
|
|
|
|
id: 1234,
|
|
|
|
raw: data.raw
|
2015-04-09 18:33:37 -04:00
|
|
|
}
|
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
}
|
2019-03-21 05:16:58 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (data.raw === "custom message") {
|
|
|
|
return response(200, {
|
|
|
|
success: true,
|
|
|
|
action: "custom",
|
|
|
|
message: "This is a custom response",
|
|
|
|
route_to: "/faq"
|
|
|
|
});
|
|
|
|
}
|
2019-03-21 06:04:19 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
return response(200, {
|
|
|
|
success: true,
|
|
|
|
action: "create_post",
|
|
|
|
post: {
|
|
|
|
id: 12345,
|
|
|
|
topic_id: 280,
|
|
|
|
topic_slug: "internationalization-localization"
|
2019-03-21 05:16:58 -04:00
|
|
|
}
|
2016-08-05 12:01:16 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2016-08-05 12:01:16 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/topics/timings", () => response(200, {}));
|
|
|
|
|
|
|
|
const siteText = { id: "site.test", value: "Test McTest" };
|
|
|
|
const overridden = {
|
|
|
|
id: "site.overridden",
|
|
|
|
value: "Overridden",
|
|
|
|
overridden: true
|
|
|
|
};
|
2019-02-26 04:43:24 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/users/list/active.json", request => {
|
|
|
|
let store = [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
username: "eviltrout",
|
|
|
|
email: "<small>eviltrout@example.com</small>"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
username: "discobot",
|
|
|
|
email: "<small>discobot_email</small>"
|
2015-11-30 15:22:58 -05:00
|
|
|
}
|
2020-03-02 14:24:31 -05:00
|
|
|
];
|
2015-11-30 15:22:58 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
const showEmails = request.queryParams.show_emails;
|
2015-11-23 16:45:05 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (showEmails === "false") {
|
|
|
|
store = store.map(item => {
|
|
|
|
delete item.email;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
2016-07-05 14:58:58 -04:00
|
|
|
|
2020-05-14 22:10:59 -04:00
|
|
|
const asc = request.queryParams.asc;
|
2020-03-02 14:24:31 -05:00
|
|
|
const order = request.queryParams.order;
|
2017-09-12 17:07:42 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (order) {
|
|
|
|
store = store.sort(function(a, b) {
|
|
|
|
return a[order] - b[order];
|
2017-09-12 17:07:42 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
}
|
2017-09-12 17:07:42 -04:00
|
|
|
|
2020-05-14 22:10:59 -04:00
|
|
|
if (asc) {
|
2020-03-02 14:24:31 -05:00
|
|
|
store = store.reverse();
|
|
|
|
}
|
2019-03-22 07:46:36 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
return response(200, store);
|
|
|
|
});
|
|
|
|
|
2020-03-10 07:56:42 -04:00
|
|
|
pretender.get("/admin/users/list/new.json", () => {
|
2020-03-02 14:24:31 -05:00
|
|
|
return response(200, [
|
|
|
|
{
|
2017-09-14 14:10:39 -04:00
|
|
|
id: 2,
|
|
|
|
username: "sam",
|
2020-03-02 14:24:31 -05:00
|
|
|
email: "<small>sam@example.com</small>"
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
});
|
2017-09-14 14:10:39 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/customize/site_texts", request => {
|
|
|
|
if (request.queryParams.overridden) {
|
|
|
|
return response(200, { site_texts: [overridden] });
|
|
|
|
} else {
|
|
|
|
return response(200, { site_texts: [siteText, overridden] });
|
|
|
|
}
|
|
|
|
});
|
2016-12-08 16:08:44 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/customize/site_texts/:key", () =>
|
|
|
|
response(200, { site_text: siteText })
|
|
|
|
);
|
|
|
|
pretender.delete("/admin/customize/site_texts/:key", () =>
|
|
|
|
response(200, { site_text: siteText })
|
|
|
|
);
|
|
|
|
|
|
|
|
pretender.put("/admin/customize/site_texts/:key", request => {
|
|
|
|
const result = parsePostData(request.requestBody);
|
|
|
|
result.id = request.params.key;
|
|
|
|
result.can_revert = true;
|
|
|
|
return response(200, { site_text: result });
|
|
|
|
});
|
|
|
|
|
|
|
|
pretender.get("/tag_groups", () => response(200, { tag_groups: [] }));
|
2019-01-10 05:06:01 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/users/1.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
id: 1,
|
|
|
|
username: "eviltrout",
|
|
|
|
email: "eviltrout@example.com",
|
|
|
|
admin: true
|
2017-06-28 16:56:44 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2017-06-28 16:56:44 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/users/2.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
id: 2,
|
|
|
|
username: "sam",
|
|
|
|
admin: true
|
2017-06-28 16:56:44 -04:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2017-06-28 16:56:44 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/users/3.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
id: 3,
|
|
|
|
username: "markvanlan",
|
|
|
|
email: "markvanlan@example.com",
|
|
|
|
secondary_emails: ["markvanlan1@example.com", "markvanlan2@example.com"]
|
2017-11-14 19:13:50 -05:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2017-11-14 19:13:50 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/users/1234.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
id: 1234,
|
|
|
|
username: "regular"
|
2017-12-19 21:41:31 -05:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2017-12-19 21:41:31 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/users/1235.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
id: 1235,
|
|
|
|
username: "regular2"
|
2019-02-20 21:13:37 -05:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2019-02-20 21:13:37 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.delete("/admin/users/:user_id.json", () =>
|
|
|
|
response(200, { deleted: true })
|
|
|
|
);
|
|
|
|
pretender.post("/admin/badges", success);
|
|
|
|
pretender.delete("/admin/badges/:id", success);
|
|
|
|
|
|
|
|
pretender.get("/admin/logs/staff_action_logs.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
staff_action_logs: [],
|
|
|
|
extras: { user_history_actions: [] }
|
2018-11-27 03:00:31 -05:00
|
|
|
});
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2018-11-27 03:00:31 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/logs/watched_words", () => {
|
|
|
|
return response(200, fixturesByUrl["/admin/logs/watched_words.json"]);
|
|
|
|
});
|
|
|
|
pretender.delete("/admin/logs/watched_words/:id.json", success);
|
2016-12-08 16:08:44 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/admin/logs/watched_words.json", request => {
|
|
|
|
const result = parsePostData(request.requestBody);
|
|
|
|
result.id = new Date().getTime();
|
|
|
|
return response(200, result);
|
|
|
|
});
|
2016-12-08 16:08:44 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.get("/admin/logs/search_logs.json", () => {
|
|
|
|
return response(200, [
|
|
|
|
{ term: "foobar", searches: 35, click_through: 6, unique: 16 }
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
pretender.get("/admin/logs/search_logs/term.json", () => {
|
|
|
|
return response(200, {
|
|
|
|
term: {
|
|
|
|
type: "search_log_term",
|
|
|
|
title: "Search Count",
|
|
|
|
term: "ruby",
|
|
|
|
data: [{ x: "2017-07-20", y: 2 }]
|
2017-02-08 15:34:42 -05:00
|
|
|
}
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
|
|
|
});
|
2017-02-08 15:34:42 -05:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.post("/uploads/lookup-metadata", () => {
|
|
|
|
return response(200, {
|
|
|
|
imageFilename: "somefile.png",
|
|
|
|
imageFilesize: "10 KB",
|
|
|
|
imageWidth: "1",
|
|
|
|
imageHeight: "1"
|
2016-12-08 16:08:44 -05:00
|
|
|
});
|
2015-04-01 14:18:46 -04:00
|
|
|
});
|
2014-07-31 17:26:44 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.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"}]}'
|
|
|
|
];
|
2014-07-31 17:26:44 -04:00
|
|
|
}
|
2020-03-02 14:24:31 -05:00
|
|
|
});
|
2014-07-31 17:26:44 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
pretender.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"
|
|
|
|
) {
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "application/html" },
|
|
|
|
'<aside class="onebox"><article class="onebox-body"><h3><a href="http://www.example.com/article.html">An interesting article</a></h3></article></aside>'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (request.queryParams.url === "http://www.example.com/no-title.html") {
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "application/html" },
|
|
|
|
'<aside class="onebox"><article class="onebox-body"><p>No title</p></article></aside>'
|
|
|
|
];
|
|
|
|
}
|
2014-07-31 14:51:10 -04:00
|
|
|
|
2020-03-02 14:24:31 -05:00
|
|
|
if (request.queryParams.url.indexOf("/internal-page.html") > -1) {
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "application/html" },
|
|
|
|
'<aside class="onebox"><article class="onebox-body"><h3><a href="/internal-page.html">Internal Page 4 U</a></h3></article></aside>'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
if (request.queryParams.url === "http://somegoodurl.com/") {
|
|
|
|
return [
|
|
|
|
200,
|
|
|
|
{ "Content-Type": "application/html" },
|
|
|
|
`
|
|
|
|
<aside class="onebox whitelistedgeneric">
|
|
|
|
<header class="source">
|
|
|
|
<a href="http://test.com/somepage" target="_blank">test.com</a>
|
|
|
|
</header>
|
|
|
|
<article class="onebox-body">
|
|
|
|
<div class="aspect-image" style="--aspect-ratio:690/362;"><img src="https://test.com/image.png" class="thumbnail"></div>
|
|
|
|
<h3><a href="http://test.com/somepage" target="_blank">Test Page</a></h3>
|
|
|
|
<p>Yet another collaboration tool</p>
|
|
|
|
</article>
|
|
|
|
<div class="onebox-metadata"></div>
|
|
|
|
<div style="clear: both"></div>
|
|
|
|
</aside>
|
|
|
|
`
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return [404, { "Content-Type": "application/html" }, ""];
|
|
|
|
});
|
2017-09-11 13:14:22 -04:00
|
|
|
}
|