Files
upstream-zulip/web/tests/pm_conversations_util.test.cjs
upstream-mirror 64898b2c79
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
2026-09-15 15:05:30 +05:00

73 lines
2.4 KiB
JavaScript

"use strict";
const assert = require("node:assert/strict");
const {make_user} = require("./lib/example_user.cjs");
const {mock_esm, zrequire} = require("./lib/namespace.cjs");
const {run_test, noop} = require("./lib/test.cjs");
const channel = mock_esm("../src/channel");
const people = zrequire("people");
const pm_conversations = zrequire("pm_conversations");
const pm_conversations_util = zrequire("pm_conversations_util");
const alice = make_user({email: "alice@example.com", user_id: 4, full_name: "Alice"});
const me = make_user({email: "me@example.com", user_id: 15, full_name: "Me"});
people.add_active_user(alice);
people.add_active_user(me);
people.initialize_current_user(me.user_id);
function test(label, f) {
run_test(label, (helpers) => {
pm_conversations.clear_for_testing();
f(helpers);
});
}
test("re-adds the conversation when the server reports a remaining message", () => {
let dom_updated = false;
channel.get = (opts) => {
assert.equal(opts.url, "/json/messages");
assert.deepEqual(JSON.parse(opts.data.narrow), [
{operator: "dm", operand: [alice.user_id]},
]);
assert.equal(opts.data.anchor, "newest");
assert.equal(opts.data.num_before, 1);
assert.equal(opts.data.num_after, 0);
opts.success({messages: [{id: 555}]});
};
assert.ok(!pm_conversations.recent.has_conversation(alice.user_id.toString()));
pm_conversations_util.update_dm_last_message_id(alice.user_id.toString(), () => {
dom_updated = true;
});
assert.ok(pm_conversations.recent.has_conversation(alice.user_id.toString()));
assert.equal(pm_conversations.recent.get()[0].max_message_id, 555);
assert.ok(dom_updated);
});
test("leaves the conversation removed when the server reports it is empty", () => {
channel.get = (opts) => {
opts.success({messages: []});
};
// The conversation isn't re-added, so the dom-update callback (noop) is
// never invoked.
pm_conversations_util.update_dm_last_message_id(alice.user_id.toString(), noop);
assert.ok(!pm_conversations.recent.has_conversation(alice.user_id.toString()));
});
test("ignores errors", () => {
channel.get = (opts) => {
opts.error();
};
// Should not throw.
pm_conversations_util.update_dm_last_message_id(alice.user_id.toString(), noop);
assert.ok(!pm_conversations.recent.has_conversation(alice.user_id.toString()));
});