DEV: Fix pretenders leaking across acceptance test.

This commit is contained in:
Guo Xiang Tan 2019-05-28 10:40:27 +08:00
parent c780d36ddc
commit c80ab08e48
6 changed files with 38 additions and 34 deletions

View File

@ -4,10 +4,6 @@ acceptance("Tag Hashtag", {
loggedIn: true,
settings: { tagging_enabled: true },
pretend(server, helper) {
server.get("/tags/filter/search", () => {
return helper.response({ results: [{ text: "monkey", count: 1 }] });
});
server.get("/tags/check", () => {
return helper.response({
valid: [{ value: "monkey", url: "/tags/monkey" }]

View File

@ -14,13 +14,6 @@ acceptance("Topic - Edit timer", {
category_id: null
})
);
server.put("/t/internationalization-localization/280/status", () =>
helper.response({
success: "OK",
topic_status_update: null
})
);
}
});

View File

@ -7,18 +7,6 @@ acceptance("Topic", {
server.put("/posts/398/wiki", () => {
return helper.response({});
});
server.get("/topics/feature_stats.json", () => {
return helper.response({
pinned_in_category_count: 0,
pinned_globally_count: 0,
banner_count: 0
});
});
server.put("/t/280/make-banner", () => {
return helper.response({});
});
}
});

View File

@ -85,6 +85,10 @@ export default function() {
});
});
this.get("/tags/filter/search", () => {
return response({ results: [{ text: "monkey", count: 1 }] });
});
this.get(`/u/:username/emails.json`, () => {
return response({ email: "eviltrout@example.com" });
});
@ -138,6 +142,25 @@ export default function() {
return response({ topic_list: { topics: [] } });
});
this.get("/topics/feature_stats.json", () => {
return response({
pinned_in_category_count: 0,
pinned_globally_count: 0,
banner_count: 0
});
});
this.put("/t/280/make-banner", () => {
return response({});
});
this.put("/t/internationalization-localization/280/status", () => {
return response({
success: "OK",
topic_status_update: null
});
});
this.post("/clicks/track", success);
this.get("/search", request => {

View File

@ -57,17 +57,18 @@ function AcceptanceModal(option, _relatedTarget) {
window.bootbox.$body = $("#ember-testing");
$.fn.modal = AcceptanceModal;
let _pretenderCallbacks = [];
let _pretenderCallbacks = {};
export function applyPretender(server, helper) {
_pretenderCallbacks.forEach(cb => cb(server, helper));
export function applyPretender(name, server, helper) {
const cb = _pretenderCallbacks[name];
if (cb) cb(server, helper);
}
export function acceptance(name, options) {
options = options || {};
if (options.pretend) {
_pretenderCallbacks.push(options.pretend);
_pretenderCallbacks[name] = options.pretend;
}
QUnit.module("Acceptance: " + name, {

View File

@ -88,7 +88,8 @@ var origDebounce = Ember.run.debounce,
_DiscourseURL = require("discourse/lib/url", null, null, false).default,
applyPretender = require("helpers/qunit-helpers", null, null, false)
.applyPretender,
server;
server,
acceptanceModulePrefix = "Acceptance: ";
function dup(obj) {
return jQuery.extend(true, {}, obj);
@ -105,13 +106,15 @@ function resetSite(siteSettings, extras) {
QUnit.testStart(function(ctx) {
server = pretender.default();
var helper = {
parsePostData: pretender.parsePostData,
response: pretender.response,
success: pretender.success
};
if (ctx.module.startsWith(acceptanceModulePrefix)) {
var helper = {
parsePostData: pretender.parsePostData,
response: pretender.response,
success: pretender.success
};
applyPretender(server, helper);
applyPretender(ctx.module.replace(acceptanceModulePrefix, ""), server, helper);
}
// Allow our tests to change site settings and have them reset before the next test
Discourse.SiteSettings = dup(Discourse.SiteSettingsOriginal);