buddy_list: Fetch full subscriber data before showing user counts.

Work towards #34244.

Note that this doesn't show the right counts when the counts appear, because
yet. We can double check functionality after that change is complete.
This commit is contained in:
Evy Kassirer
2025-04-07 14:25:15 -07:00
committed by Tim Abbott
parent e2474d8e44
commit 8efe6a7b67
4 changed files with 186 additions and 59 deletions

View File

@@ -9,11 +9,13 @@
const assert = require("node:assert/strict");
const example_settings = require("./lib/example_settings.cjs");
const {zrequire} = require("./lib/namespace.cjs");
const {mock_esm, 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");
const channel = mock_esm("../src/channel");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
const {set_current_user, set_realm} = zrequire("state_data");
@@ -83,7 +85,7 @@ function test(label, f) {
);
override(realm, "realm_can_access_all_users_group", nobody_group.id);
f({override});
return f({override});
});
}
@@ -240,6 +242,47 @@ test("subscribers", () => {
blueslip.reset();
});
test("maybe_fetch_stream_subscribers", async () => {
const india = {
stream_id: 102,
name: "India",
subscribed: true,
};
stream_data.add_sub(india);
let channel_get_calls = 0;
channel.get = (opts) => {
assert.equal(opts.url, `/json/streams/${india.stream_id}/members`);
channel_get_calls += 1;
return {
subscribers: [1, 2, 3, 4],
};
};
// Only one of these will do the fetch, and the other will wait
// for the first fetch to complete.
const promise1 = peer_data.maybe_fetch_stream_subscribers(india.stream_id);
const promise2 = peer_data.maybe_fetch_stream_subscribers(india.stream_id);
await promise1;
await promise2;
assert.equal(channel_get_calls, 1);
peer_data.clear_for_testing();
assert.equal(await peer_data.maybe_fetch_is_user_subscribed(india.stream_id, 2), true);
assert.equal(peer_data.has_full_subscriber_data(india.stream_id), true);
peer_data.clear_for_testing();
assert.equal(peer_data.has_full_subscriber_data(india.stream_id), false);
assert.equal(await peer_data.maybe_fetch_is_user_subscribed(india.stream_id, 2), true);
assert.equal(await peer_data.maybe_fetch_is_user_subscribed(india.stream_id, 5), false);
channel.get = () => {
throw new Error("error");
};
peer_data.clear_for_testing();
blueslip.expect("error", "Failure fetching channel subscribers");
peer_data.maybe_fetch_stream_subscribers(india.stream_id);
});
test("get_subscriber_count", () => {
people.add_active_user(fred);
people.add_active_user(gail);