node tests: Avoid people stubs for poll test.

We also have Alice vote on the current user's poll.
This commit is contained in:
Steve Howell 2021-04-16 12:43:17 +00:00 committed by Steve Howell
parent e71f906eba
commit 8ffb828030
1 changed files with 48 additions and 19 deletions

View File

@ -14,13 +14,24 @@ const poll_widget = zrequire("poll_widget");
const people = zrequire("people");
const me = {
email: "me@zulip.com",
full_name: "Me Myself",
user_id: 99,
};
const alice = {
email: "alice@zulip.com",
full_name: "Alice Lee",
user_id: 100,
};
people.add_active_user(me);
people.add_active_user(alice);
people.initialize_current_user(me.user_id);
run_test("PollData my question", () => {
const is_my_poll = true;
const question = "Favorite color?";
const sender_id = 99;
people.my_current_user_id = () => sender_id;
const data_holder = new poll_widget.PollData(is_my_poll, question, []);
let data = data_holder.get_widget_data();
@ -35,7 +46,7 @@ run_test("PollData my question", () => {
question: "best plan?",
};
data_holder.handle_event(sender_id, question_event);
data_holder.handle_event(me.user_id, question_event);
data = data_holder.get_widget_data();
assert.deepEqual(data, {
@ -49,9 +60,7 @@ run_test("PollData my question", () => {
option: "release now",
};
people.safe_full_names = () => "";
data_holder.handle_event(sender_id, option_event);
data_holder.handle_event(me.user_id, option_event);
data = data_holder.get_widget_data();
assert.deepEqual(data, {
@ -73,14 +82,14 @@ run_test("PollData my question", () => {
vote: 1,
};
data_holder.handle_event(sender_id, vote_event);
data_holder.handle_event(me.user_id, vote_event);
data = data_holder.get_widget_data();
assert.deepEqual(data, {
options: [
{
option: "release now",
names: "",
names: "Me Myself",
count: 1,
key: "99,1",
current_user_vote: true,
@ -89,6 +98,28 @@ run_test("PollData my question", () => {
question: "best plan?",
});
vote_event = {
type: "vote",
key: "99,1",
vote: 1,
};
data_holder.handle_event(alice.user_id, vote_event);
data = data_holder.get_widget_data();
assert.deepEqual(data, {
options: [
{
option: "release now",
names: "Me Myself, Alice Lee",
count: 2,
key: "99,1",
current_user_vote: true,
},
],
question: "best plan?",
});
const invalid_vote_event = {
type: "vote",
key: "98,1",
@ -96,7 +127,7 @@ run_test("PollData my question", () => {
};
blueslip.expect("warn", `unknown key for poll: ${invalid_vote_event.key}`);
data_holder.handle_event(sender_id, invalid_vote_event);
data_holder.handle_event(me.user_id, invalid_vote_event);
data = data_holder.get_widget_data();
const option_outbound_event = data_holder.handle.new_option.outbound("new option");
@ -122,15 +153,15 @@ run_test("PollData my question", () => {
vote: -1,
};
data_holder.handle_event(sender_id, vote_event);
data_holder.handle_event(me.user_id, vote_event);
data = data_holder.get_widget_data();
assert.deepEqual(data, {
options: [
{
option: "release now",
names: "",
count: 0,
names: "Alice Lee",
count: 1,
key: "99,1",
current_user_vote: false,
},
@ -140,7 +171,6 @@ run_test("PollData my question", () => {
});
run_test("activate another person poll", () => {
people.is_my_user_id = () => false;
stub_templates((template_name) => {
if (template_name === "widgets/poll_widget") {
return "widgets/poll_widget";
@ -162,7 +192,7 @@ run_test("activate another person poll", () => {
elem: widget_elem,
callback,
message: {
sender_id: 100,
sender_id: alice.user_id,
},
extra_data: {
question: "What do you want?",
@ -222,7 +252,7 @@ run_test("activate another person poll", () => {
const vote_events = [
{
sender_id: 100,
sender_id: alice.user_id,
data: {
type: "new_option",
idx: 1,
@ -230,7 +260,7 @@ run_test("activate another person poll", () => {
},
},
{
sender_id: 100,
sender_id: alice.user_id,
data: {
type: "vote",
key: "100,1",
@ -263,7 +293,6 @@ run_test("activate another person poll", () => {
});
run_test("activate own poll", () => {
people.is_my_user_id = () => true;
stub_templates((template_name) => {
if (template_name === "widgets/poll_widget") {
return "widgets/poll_widget";
@ -283,7 +312,7 @@ run_test("activate own poll", () => {
elem: widget_elem,
callback,
message: {
sender_id: 100,
sender_id: me.user_id,
},
extra_data: {
question: "Where to go?",