2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2024-11-13 07:05:32 +01:00
|
|
|
const {mock_jquery, mock_esm, set_global, zrequire} = require("./lib/namespace.cjs");
|
|
|
|
const {run_test} = require("./lib/test.cjs");
|
|
|
|
const blueslip = require("./lib/zblueslip.cjs");
|
|
|
|
const {page_params} = require("./lib/zpage_params.cjs");
|
2018-08-01 21:17:03 +02:00
|
|
|
|
2021-09-28 12:20:14 +02:00
|
|
|
const xhr_401 = {
|
|
|
|
status: 401,
|
2023-07-18 20:14:56 +02:00
|
|
|
responseJSON: {msg: "Use cannot access XYZ"},
|
2021-09-28 12:20:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let login_to_access_shown = false;
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/spectators", {
|
2022-11-17 23:33:43 +01:00
|
|
|
login_to_access() {
|
2021-09-28 12:20:14 +02:00
|
|
|
login_to_access_shown = true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global("window", {
|
|
|
|
location: {
|
2022-11-17 23:33:43 +01:00
|
|
|
replace() {},
|
2023-05-10 21:53:54 +02:00
|
|
|
href: "http://example.com",
|
2021-09-28 12:20:14 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-03-10 02:39:50 +01:00
|
|
|
const reload_state = zrequire("reload_state");
|
2021-02-10 04:53:22 +01:00
|
|
|
const channel = zrequire("channel");
|
2018-08-01 21:17:03 +02:00
|
|
|
|
2021-10-05 03:01:45 +02:00
|
|
|
const default_stub_xhr = {"default-stub-xhr": 0};
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-06-16 15:58:34 +02:00
|
|
|
const $ = mock_jquery({});
|
2021-02-22 12:18:39 +01:00
|
|
|
|
2017-06-28 00:48:48 +02:00
|
|
|
function test_with_mock_ajax(test_params) {
|
2020-07-15 00:34:28 +02:00
|
|
|
const {xhr = default_stub_xhr, run_code, check_ajax_options} = test_params;
|
2018-04-18 22:48:22 +02:00
|
|
|
|
|
|
|
let ajax_called;
|
|
|
|
let ajax_options;
|
2021-02-23 14:37:26 +01:00
|
|
|
$.ajax = (options) => {
|
2017-06-28 00:48:48 +02:00
|
|
|
$.ajax = undefined;
|
|
|
|
ajax_called = true;
|
|
|
|
ajax_options = options;
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
options.simulate_success = (data, text_status) => {
|
2017-06-28 00:48:48 +02:00
|
|
|
options.success(data, text_status, xhr);
|
|
|
|
};
|
|
|
|
|
2021-02-23 14:37:26 +01:00
|
|
|
options.simulate_error = () => {
|
2017-06-28 00:48:48 +02:00
|
|
|
options.error(xhr);
|
|
|
|
};
|
|
|
|
|
|
|
|
return xhr;
|
|
|
|
};
|
|
|
|
|
2018-04-18 22:48:22 +02:00
|
|
|
run_code();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(ajax_called);
|
2018-04-18 22:48:22 +02:00
|
|
|
check_ajax_options(ajax_options);
|
2017-06-28 00:48:48 +02:00
|
|
|
}
|
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
function test(label, f) {
|
2021-06-16 14:38:37 +02:00
|
|
|
run_test(label, ({override}) => {
|
2021-03-20 15:23:44 +01:00
|
|
|
reload_state.clear_for_testing();
|
2021-06-16 14:38:37 +02:00
|
|
|
f({override});
|
2021-03-20 15:23:44 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test("post", () => {
|
2017-06-28 00:48:48 +02:00
|
|
|
test_with_mock_ajax({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.post({url: "/json/endpoint"});
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(options.type, "POST");
|
|
|
|
assert.equal(options.dataType, "json");
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
// Just make sure these don't explode.
|
|
|
|
options.simulate_success();
|
|
|
|
options.simulate_error();
|
|
|
|
},
|
|
|
|
});
|
2021-02-22 12:04:22 +01:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("patch", () => {
|
2017-06-28 00:48:48 +02:00
|
|
|
test_with_mock_ajax({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.patch({url: "/json/endpoint"});
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(options.type, "POST");
|
|
|
|
assert.equal(options.data.method, "PATCH");
|
|
|
|
assert.equal(options.dataType, "json");
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
// Just make sure these don't explode.
|
|
|
|
options.simulate_success();
|
|
|
|
options.simulate_error();
|
|
|
|
},
|
|
|
|
});
|
2021-02-22 12:04:22 +01:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("put", () => {
|
2017-06-28 00:48:48 +02:00
|
|
|
test_with_mock_ajax({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.put({url: "/json/endpoint"});
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(options.type, "PUT");
|
|
|
|
assert.equal(options.dataType, "json");
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
// Just make sure these don't explode.
|
|
|
|
options.simulate_success();
|
|
|
|
options.simulate_error();
|
|
|
|
},
|
|
|
|
});
|
2021-02-22 12:04:22 +01:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("delete", () => {
|
2017-06-28 00:48:48 +02:00
|
|
|
test_with_mock_ajax({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.del({url: "/json/endpoint"});
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(options.type, "DELETE");
|
|
|
|
assert.equal(options.dataType, "json");
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
// Just make sure these don't explode.
|
|
|
|
options.simulate_success();
|
|
|
|
options.simulate_error();
|
|
|
|
},
|
|
|
|
});
|
2021-02-22 12:04:22 +01:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("get", () => {
|
2017-06-28 00:48:48 +02:00
|
|
|
test_with_mock_ajax({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.get({url: "/json/endpoint"});
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(options.type, "GET");
|
|
|
|
assert.equal(options.dataType, "json");
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
// Just make sure these don't explode.
|
|
|
|
options.simulate_success();
|
|
|
|
options.simulate_error();
|
|
|
|
},
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("normal_post", () => {
|
2018-04-18 22:48:22 +02:00
|
|
|
const data = {
|
2020-07-15 01:29:15 +02:00
|
|
|
s: "some_string",
|
2017-06-28 00:48:48 +02:00
|
|
|
num: 7,
|
|
|
|
lst: [1, 2, 4, 8],
|
|
|
|
};
|
|
|
|
|
2018-04-18 22:48:22 +02:00
|
|
|
let orig_success_called;
|
|
|
|
let orig_error_called;
|
2021-10-05 03:01:45 +02:00
|
|
|
const stub_xhr = {"stub-xhr-normal-post": 0};
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
test_with_mock_ajax({
|
|
|
|
xhr: stub_xhr,
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2017-06-28 00:48:48 +02:00
|
|
|
channel.post({
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
2020-07-15 01:29:15 +02:00
|
|
|
url: "/json/endpoint",
|
2020-07-20 22:18:43 +02:00
|
|
|
success(data, text_status, xhr) {
|
2017-06-28 00:48:48 +02:00
|
|
|
orig_success_called = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(data, "response data");
|
|
|
|
assert.equal(text_status, "success");
|
2017-06-28 00:48:48 +02:00
|
|
|
assert.equal(xhr, stub_xhr);
|
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error() {
|
2017-06-28 00:48:48 +02:00
|
|
|
orig_error_called = true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(options.type, "POST");
|
|
|
|
assert.equal(options.dataType, "json");
|
2017-06-28 00:48:48 +02:00
|
|
|
assert.deepEqual(options.data, data);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(options.url, "/json/endpoint");
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
options.simulate_success("response data", "success");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(orig_success_called);
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
options.simulate_error();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(orig_error_called);
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("patch_with_form_data", () => {
|
2018-04-18 22:48:22 +02:00
|
|
|
let appended;
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2018-04-18 22:48:22 +02:00
|
|
|
const data = {
|
2020-07-20 22:18:43 +02:00
|
|
|
append(k, v) {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(k, "method");
|
|
|
|
assert.equal(v, "PATCH");
|
2017-06-28 00:48:48 +02:00
|
|
|
appended = true;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
test_with_mock_ajax({
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2017-06-28 00:48:48 +02:00
|
|
|
channel.patch({
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
2023-05-10 21:53:54 +02:00
|
|
|
url: "/json/endpoint",
|
2017-06-28 00:48:48 +02:00
|
|
|
processData: false,
|
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(appended);
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(options.type, "POST");
|
|
|
|
assert.equal(options.dataType, "json");
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
// Just make sure these don't explode.
|
|
|
|
options.simulate_success();
|
|
|
|
options.simulate_error();
|
|
|
|
},
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-09-28 12:20:14 +02:00
|
|
|
test("authentication_error_401_is_spectator", () => {
|
|
|
|
test_with_mock_ajax({
|
|
|
|
xhr: xhr_401,
|
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.post({url: "/json/endpoint"});
|
2021-09-28 12:20:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// is_spectator = true
|
|
|
|
check_ajax_options(options) {
|
2024-02-28 02:02:40 +01:00
|
|
|
page_params.page_type = "home";
|
2021-09-28 12:20:14 +02:00
|
|
|
page_params.is_spectator = true;
|
|
|
|
|
|
|
|
options.simulate_error();
|
|
|
|
assert.ok(login_to_access_shown);
|
|
|
|
|
|
|
|
login_to_access_shown = false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("authentication_error_401_password_change_in_progress", () => {
|
|
|
|
test_with_mock_ajax({
|
|
|
|
xhr: xhr_401,
|
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.post({url: "/json/endpoint"});
|
2021-09-28 12:20:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// is_spectator = true
|
|
|
|
// password_change_in_progress = true
|
|
|
|
check_ajax_options(options) {
|
2024-02-28 02:02:40 +01:00
|
|
|
page_params.page_type = "home";
|
2021-09-28 12:20:14 +02:00
|
|
|
page_params.is_spectator = true;
|
2021-10-05 03:01:45 +02:00
|
|
|
channel.set_password_change_in_progress(true);
|
2021-09-28 12:20:14 +02:00
|
|
|
|
|
|
|
options.simulate_error();
|
|
|
|
assert.ok(!login_to_access_shown);
|
|
|
|
|
2021-10-05 03:01:45 +02:00
|
|
|
channel.set_password_change_in_progress(false);
|
2021-09-28 12:20:14 +02:00
|
|
|
page_params.is_spectator = false;
|
|
|
|
login_to_access_shown = false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("authentication_error_401_not_spectator", () => {
|
|
|
|
test_with_mock_ajax({
|
|
|
|
xhr: xhr_401,
|
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.post({url: "/json/endpoint"});
|
2021-09-28 12:20:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// is_spectator = false
|
|
|
|
check_ajax_options(options) {
|
2024-02-28 02:02:40 +01:00
|
|
|
page_params.page_type = "home";
|
2021-09-28 12:20:14 +02:00
|
|
|
page_params.is_spectator = false;
|
|
|
|
|
|
|
|
options.simulate_error();
|
|
|
|
assert.ok(!login_to_access_shown);
|
|
|
|
|
|
|
|
login_to_access_shown = false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("reload_on_403_error", () => {
|
2017-06-28 00:48:48 +02:00
|
|
|
test_with_mock_ajax({
|
|
|
|
xhr: {
|
|
|
|
status: 403,
|
2023-07-18 20:14:56 +02:00
|
|
|
responseJSON: {msg: "CSRF Fehler: etwas", code: "CSRF_FAILED"},
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.post({url: "/json/endpoint"});
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2021-03-10 02:39:50 +01:00
|
|
|
let handler_called = false;
|
|
|
|
reload_state.set_csrf_failed_handler(() => {
|
|
|
|
handler_called = true;
|
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
options.simulate_error();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(handler_called);
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("unexpected_403_response", () => {
|
2017-06-28 00:48:48 +02:00
|
|
|
test_with_mock_ajax({
|
|
|
|
xhr: {
|
|
|
|
status: 403,
|
2023-07-18 20:14:56 +02:00
|
|
|
responseJSON: undefined,
|
2020-07-15 01:29:15 +02:00
|
|
|
responseText: "unexpected",
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
run_code() {
|
2023-05-10 21:53:54 +02:00
|
|
|
channel.post({url: "/json/endpoint"});
|
2017-06-28 00:48:48 +02:00
|
|
|
},
|
|
|
|
|
2020-07-20 22:18:43 +02:00
|
|
|
check_ajax_options(options) {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Unexpected 403 response from server");
|
2017-06-28 00:48:48 +02:00
|
|
|
options.simulate_error();
|
|
|
|
},
|
|
|
|
});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-28 00:48:48 +02:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("xhr_error_message", () => {
|
2018-04-18 22:48:22 +02:00
|
|
|
let xhr = {
|
2020-07-15 01:29:15 +02:00
|
|
|
status: "200",
|
2023-07-18 20:14:56 +02:00
|
|
|
responseJSON: undefined,
|
2020-07-15 01:29:15 +02:00
|
|
|
responseText: "does not matter",
|
2017-06-28 00:48:48 +02:00
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
let msg = "data added";
|
|
|
|
assert.equal(channel.xhr_error_message(msg, xhr), "data added");
|
2017-06-28 00:48:48 +02:00
|
|
|
|
|
|
|
xhr = {
|
2020-07-15 01:29:15 +02:00
|
|
|
status: "404",
|
2023-07-18 20:14:56 +02:00
|
|
|
responseJSON: {msg: "file not found"},
|
2017-06-28 00:48:48 +02:00
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
msg = "some message";
|
|
|
|
assert.equal(channel.xhr_error_message(msg, xhr), "some message: file not found");
|
2023-05-04 04:20:28 +02:00
|
|
|
|
2023-08-30 12:08:32 +02:00
|
|
|
msg = "";
|
2023-05-04 04:20:28 +02:00
|
|
|
assert.equal(channel.xhr_error_message(msg, xhr), "file not found");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2021-03-18 12:56:06 +01:00
|
|
|
|
2021-03-20 15:23:44 +01:00
|
|
|
test("while_reloading", () => {
|
2021-03-18 12:56:06 +01:00
|
|
|
reload_state.set_state_to_in_progress();
|
|
|
|
|
|
|
|
assert.equal(channel.get({ignore_reload: false}), undefined);
|
|
|
|
|
|
|
|
test_with_mock_ajax({
|
|
|
|
run_code() {
|
|
|
|
channel.del({
|
|
|
|
url: "/json/endpoint",
|
|
|
|
ignore_reload: true,
|
2022-04-09 23:44:38 +02:00
|
|
|
/* istanbul ignore next */
|
2021-03-18 12:56:06 +01:00
|
|
|
success() {
|
2022-04-09 23:44:38 +02:00
|
|
|
throw new Error("unexpected success");
|
2021-03-18 12:56:06 +01:00
|
|
|
},
|
2022-04-09 23:44:38 +02:00
|
|
|
/* istanbul ignore next */
|
2021-03-18 12:56:06 +01:00
|
|
|
error() {
|
2022-04-09 23:44:38 +02:00
|
|
|
throw new Error("unexpected error");
|
2021-03-18 12:56:06 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
check_ajax_options(options) {
|
|
|
|
blueslip.expect("log", "Ignoring DELETE /json/endpoint response while reloading");
|
|
|
|
options.simulate_success();
|
|
|
|
|
|
|
|
blueslip.expect("log", "Ignoring DELETE /json/endpoint error response while reloading");
|
|
|
|
options.simulate_error();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2023-04-12 20:06:44 +02:00
|
|
|
|
|
|
|
test("error in callback", () => {
|
|
|
|
let success_called = false;
|
|
|
|
let error_called = false;
|
|
|
|
let raised_error = false;
|
|
|
|
test_with_mock_ajax({
|
|
|
|
run_code() {
|
|
|
|
channel.get({
|
|
|
|
url: "/json/endpoint",
|
|
|
|
success() {
|
|
|
|
success_called = true;
|
|
|
|
throw new Error("success");
|
|
|
|
},
|
|
|
|
error() {
|
|
|
|
error_called = true;
|
|
|
|
throw new Error("failure");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
check_ajax_options(options) {
|
|
|
|
try {
|
|
|
|
options.simulate_success();
|
|
|
|
} catch (error) {
|
|
|
|
assert.equal(error.message, "success");
|
|
|
|
raised_error = true;
|
|
|
|
}
|
|
|
|
assert.ok(success_called);
|
|
|
|
assert.ok(raised_error);
|
|
|
|
assert.ok(!error_called);
|
|
|
|
|
|
|
|
success_called = false;
|
|
|
|
raised_error = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
options.simulate_error();
|
|
|
|
} catch (error) {
|
|
|
|
assert.equal(error.message, "failure");
|
|
|
|
raised_error = true;
|
|
|
|
}
|
|
|
|
assert.ok(!success_called);
|
|
|
|
assert.ok(raised_error);
|
|
|
|
assert.ok(error_called);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|