mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
TESTS: Use Pretender in test mode for more flexible server responses
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
/*jshint maxlen:10000000 */
|
||||
Discourse.URL_FIXTURES["/session"] = [ { error: "Incorrect username, email or password" } ];
|
||||
@@ -1,3 +1,3 @@
|
||||
/*jshint maxlen:10000000 */
|
||||
Discourse.SiteSettingsOriginal = {"title":"Discourse Meta","logo_url":"/assets/logo.png","logo_small_url":"/assets/logo-single.png","traditional_markdown_linebreaks":false,"top_menu":"latest|new|unread|read|starred|categories","post_menu":"like|edit|flag|delete|share|bookmark|admin|reply","share_links":"twitter|facebook|google+|email","track_external_right_clicks":false,"must_approve_users":false,"ga_tracking_code":"UA-33736483-2","ga_domain_name":"","enable_long_polling":true,"polling_interval":3000,"anon_polling_interval":30000,"min_post_length":20,"max_post_length":16000,"min_topic_title_length":15,"max_topic_title_length":255,"min_private_message_title_length":2,"allow_uncategorized_topics":true,"min_search_term_length":3,"flush_timings_secs":5,"suppress_reply_directly_below":true,"email_domains_blacklist":"mailinator.com","email_domains_whitelist":null,"version_checks":true,"min_title_similar_length":10,"min_body_similar_length":15,"category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","max_upload_size_kb":1024,"category_featured_topics":6,"favicon_url":"/assets/favicon.ico","dynamic_favicon":false,"uncategorized_name":"uncategorized","uncategorized_color":"AB9364","uncategorized_text_color":"FFFFFF","invite_only":false,"login_required":false,"min_password_length":8,"enable_local_logins":true,"enable_google_logins":false,"enable_google_oauth2_logins":false,"enable_yahoo_logins":false,"enable_twitter_logins":false,"enable_facebook_logins":false,"enable_cas_logins":false,"enable_github_logins":false,"educate_until_posts":2,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"min_private_message_post_length":5,"faq_url":"","tos_url":"","privacy_policy_url":"","authorized_extensions":".jpg|.jpeg|.png|.gif|.txt","relative_date_duration":14,"delete_removed_posts_after":24,"delete_user_max_post_age":7, "default_code_lang": "lang-auto", "suppress_uncategorized_badge": true, "min_username_length": 3, "max_username_length": 20};
|
||||
Discourse.SiteSettingsOriginal = {"title":"Discourse Meta","logo_url":"/assets/logo.png","logo_small_url":"/assets/logo-single.png","mobile_logo_url":"","favicon_url":"//meta.discourse.org/uploads/default/2499/79d53726406d87af.ico","allow_user_locale":false,"suggested_topics":7,"track_external_right_clicks":false,"ga_universal_tracking_code":"","ga_universal_domain_name":"auto","ga_tracking_code":"UA-33736483-2","ga_domain_name":"","top_menu":"latest|new|unread|starred|categories|top","post_menu":"like|share|flag|edit|bookmark|delete|admin|reply","post_menu_hidden_items":"edit|delete|admin","share_links":"twitter|facebook|google+|email","category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","enable_mobile_theme":true,"relative_date_duration":14,"category_featured_topics":4,"fixed_category_positions":false,"show_subcategory_list":false,"posts_per_page":20,"enable_badges":true,"invite_only":false,"login_required":false,"must_approve_users":false,"enable_local_logins":true,"allow_new_registrations":true,"enable_google_logins":true,"enable_google_oauth2_logins":false,"enable_yahoo_logins":true,"enable_twitter_logins":true,"enable_facebook_logins":true,"enable_github_logins":true,"enable_sso":false,"min_username_length":3,"max_username_length":20,"min_password_length":8,"enable_names":true,"invites_shown":30,"delete_user_max_post_age":60,"delete_all_posts_max":15,"min_post_length":20,"min_private_message_post_length":10,"max_post_length":32000,"min_topic_title_length":15,"max_topic_title_length":255,"min_private_message_title_length":2,"allow_uncategorized_topics":true,"min_title_similar_length":10,"min_body_similar_length":15,"edit_history_visible_to_public":true,"delete_removed_posts_after":24,"traditional_markdown_linebreaks":false,"suppress_reply_directly_below":true,"suppress_reply_directly_above":true,"newuser_max_images":0,"newuser_max_attachments":0,"display_name_on_posts":true,"short_progress_text_threshold":10000,"default_code_lang":"lang-auto","autohighlight_all_code":false,"email_in":false,"max_image_size_kb":3072,"max_attachment_size_kb":1024,"authorized_extensions":".jpg|.jpeg|.png|.gif|.svg|.txt|.ico|.yml","max_image_width":690,"max_image_height":500,"allow_profile_backgrounds":true,"allow_uploaded_avatars":true,"allow_animated_avatars":false,"basic_requires_read_posts":30,"enable_long_polling":true,"polling_interval":3000,"anon_polling_interval":30000,"flush_timings_secs":5,"tos_url":"","privacy_policy_url":"","tos_accept_required":false,"faq_url":"","allow_restore":false,"maximum_backups":7,"version_checks":true,"suppress_uncategorized_badge":true,"min_search_term_length":3,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"global_notice":"","show_create_topics_notice":true,"available_locales":"cs|da|de|en|es|fr|he|id|it|ja|ko|nb_NO|nl|pl_PL|pt|pt_BR|ru|sv|uk|zh_CN|zh_TW"};
|
||||
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
||||
|
||||
52
test/javascripts/helpers/create-pretender.js.es6
Normal file
52
test/javascripts/helpers/create-pretender.js.es6
Normal file
@@ -0,0 +1,52 @@
|
||||
/* global console */
|
||||
|
||||
function parsePostData(query) {
|
||||
var result = {};
|
||||
query.split("&").forEach(function(part) {
|
||||
var item = part.split("=");
|
||||
result[item[0]] = decodeURIComponent(item[1]);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function json(code, obj) {
|
||||
if (typeof code === "object") {
|
||||
obj = code;
|
||||
code = 200;
|
||||
}
|
||||
return [code, {"Content-Type": "application/json"}, JSON.stringify(obj)];
|
||||
}
|
||||
|
||||
export default function() {
|
||||
var server = new Pretender(function() {
|
||||
this.post('/session', function(request) {
|
||||
var data = parsePostData(request.requestBody);
|
||||
|
||||
if (data.password === 'correct') {
|
||||
return json({username: 'eviltrout'});
|
||||
}
|
||||
return json(400, {error: 'invalid login'});
|
||||
});
|
||||
|
||||
this.get('/users/hp.json', function() {
|
||||
return json({"value":"32faff1b1ef1ac3","challenge":"61a3de0ccf086fb9604b76e884d75801"});
|
||||
});
|
||||
|
||||
this.get('/users/check_username', function(request) {
|
||||
if (request.queryParams.username === 'taken') {
|
||||
return json({available: false, suggestion: 'nottaken'});
|
||||
}
|
||||
return json({available: true});
|
||||
});
|
||||
|
||||
this.post('/users', function(request) {
|
||||
return json({success: true});
|
||||
});
|
||||
});
|
||||
|
||||
server.unhandledRequest = function(verb, path) {
|
||||
console.error('Unhandled request in test environment: ' + path + ' (' + verb + ')');
|
||||
};
|
||||
|
||||
return server;
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
integration("Header (Anonymous)");
|
||||
|
||||
test("header", function() {
|
||||
expect(14);
|
||||
|
||||
visit("/");
|
||||
andThen(function() {
|
||||
ok(exists("header"), "is rendered");
|
||||
|
||||
@@ -5,8 +5,6 @@ integration("Header (Staff)", {
|
||||
});
|
||||
|
||||
test("header", function() {
|
||||
expect(6);
|
||||
|
||||
visit("/");
|
||||
|
||||
// Notifications
|
||||
@@ -30,5 +28,4 @@ test("header", function() {
|
||||
ok(exists("#user-dropdown:visible"), "is lazily rendered after user opens it");
|
||||
ok(exists("#user-dropdown .user-dropdown-links"), "has showing / hiding user-dropdown links correctly bound");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,17 +1,61 @@
|
||||
integration("Signing In");
|
||||
|
||||
test("sign in with incorrect credentials", function() {
|
||||
test("sign in", function() {
|
||||
visit("/");
|
||||
click("header .login-button");
|
||||
andThen(function() {
|
||||
ok(exists('.login-modal'), "it shows the login modal");
|
||||
});
|
||||
fillIn('#login-account-name', 'eviltrout');
|
||||
fillIn('#login-account-password', 'where da plankton at?');
|
||||
|
||||
// The fixture is set to invalid login
|
||||
// Test invalid password first
|
||||
fillIn('#login-account-name', 'eviltrout');
|
||||
fillIn('#login-account-password', 'incorrect');
|
||||
click('.modal-footer .btn-primary');
|
||||
andThen(function() {
|
||||
// ok(exists('#modal-alert:visible', 'it displays the login error'));
|
||||
ok(exists('#modal-alert:visible', 'it displays the login error'));
|
||||
not(exists('.modal-footer .btn-primary:disabled'), "enables the login button");
|
||||
});
|
||||
|
||||
// Use the correct password
|
||||
fillIn('#login-account-password', 'correct');
|
||||
click('.modal-footer .btn-primary');
|
||||
andThen(function() {
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), "disables the login button");
|
||||
});
|
||||
});
|
||||
|
||||
test("create account", function() {
|
||||
visit("/");
|
||||
click("header .login-button");
|
||||
click('#new-account-link');
|
||||
|
||||
andThen(function() {
|
||||
ok(exists('.create-account'), "it shows the create account modal");
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), 'create account is disabled at first');
|
||||
});
|
||||
|
||||
fillIn('#new-account-name', 'Dr. Good Tuna');
|
||||
fillIn('#new-account-password', 'cool password bro');
|
||||
|
||||
// Check username
|
||||
fillIn('#new-account-email', 'good.tuna@test.com');
|
||||
fillIn('#new-account-username', 'taken');
|
||||
andThen(function() {
|
||||
ok(exists('#username-validation.bad'), 'the username validation is bad');
|
||||
ok(exists('.modal-footer .btn-primary:disabled'), 'create account is still disabled');
|
||||
});
|
||||
|
||||
fillIn('#new-account-username', 'goodtuna');
|
||||
andThen(function() {
|
||||
ok(exists('#username-validation.good'), 'the username validation is good');
|
||||
not(exists('.modal-footer .btn-primary:disabled'), 'create account is enabled');
|
||||
});
|
||||
|
||||
click('.modal-footer .btn-primary');
|
||||
andThen(function() {
|
||||
not(exists('.modal-body'), 'it hides the body when finished');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
/*jshint maxlen:250 */
|
||||
/*global document, sinon, console, QUnit, Logster */
|
||||
/*global document, sinon, QUnit, Logster */
|
||||
|
||||
//= require env
|
||||
|
||||
//= require ../../app/assets/javascripts/preload_store.js
|
||||
//= require ../../app/assets/javascripts/preload_store
|
||||
|
||||
// probe framework first
|
||||
//= require ../../app/assets/javascripts/discourse/lib/probes.js
|
||||
//= require ../../app/assets/javascripts/discourse/lib/probes
|
||||
|
||||
// Externals we need to load first
|
||||
//= require development/jquery-2.1.1.js
|
||||
//= require jquery.ui.widget.js
|
||||
//= require handlebars.js
|
||||
//= require development/ember.js
|
||||
//= require message-bus.js
|
||||
//= require ember-qunit.js
|
||||
//= require development/jquery-2.1.1
|
||||
//= require jquery.ui.widget
|
||||
//= require handlebars
|
||||
//= require development/ember
|
||||
//= require message-bus
|
||||
//= require ember-qunit
|
||||
//= require fake_xml_http_request
|
||||
//= require route-recognizer
|
||||
//= require pretender
|
||||
|
||||
//= require ../../app/assets/javascripts/locales/i18n
|
||||
//= require ../../app/assets/javascripts/discourse/helpers/i18n_helpers
|
||||
@@ -60,16 +63,6 @@ sinon.config = {
|
||||
|
||||
window.assetPath = function() { return null; };
|
||||
|
||||
var oldAjax = $.ajax;
|
||||
$.ajax = function() {
|
||||
try {
|
||||
this.undef();
|
||||
} catch(e) {
|
||||
console.error("Discourse.Ajax called in test environment (" + arguments[0] + ")\n caller: " + e.stack.split("\n").slice(2).join("\n"));
|
||||
}
|
||||
return oldAjax.apply(this, arguments);
|
||||
};
|
||||
|
||||
// Stop the message bus so we don't get ajax calls
|
||||
Discourse.MessageBus.stop();
|
||||
|
||||
@@ -92,8 +85,13 @@ if (window.Logster) {
|
||||
window.Logster = { enabled: false };
|
||||
}
|
||||
|
||||
var origDebounce = Ember.run.debounce;
|
||||
var origDebounce = Ember.run.debounce,
|
||||
createPretendServer = require('helpers/create-pretender', null, null, false).default,
|
||||
server;
|
||||
|
||||
QUnit.testStart(function(ctx) {
|
||||
server = createPretendServer();
|
||||
|
||||
// Allow our tests to change site settings and have them reset before the next test
|
||||
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
||||
Discourse.BaseUri = "/";
|
||||
@@ -118,6 +116,8 @@ QUnit.testDone(function() {
|
||||
|
||||
// Destroy any modals
|
||||
$('.modal-backdrop').remove();
|
||||
|
||||
server.shutdown();
|
||||
});
|
||||
|
||||
// Load ES6 tests
|
||||
|
||||
Reference in New Issue
Block a user