Skip to content

Commit 21008ff

Browse files
committed
Fix the When_user_casts_vote_expect_other_user_to_receive_event test
1 parent 714aa55 commit 21008ff

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Assets/Plugins/StreamChat/Tests/StatefulClient/PollsTests.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ private async Task When_adding_poll_option_expect_option_added_Async()
326326
// Add a new option
327327
var newOption = await poll.AddOptionAsync("Option 3");
328328

329-
//await WaitWhileFalseAsync(() => poll.Options.Count == 3);
329+
await WaitWhileFalseAsync(() => poll.Options.Count == 3);
330330

331331
Assert.NotNull(newOption);
332332
Assert.AreEqual("Option 3", newOption.Text);
@@ -520,11 +520,6 @@ private async Task When_user_casts_vote_expect_other_user_to_receive_event_Async
520520
Assert.NotNull(message.PollId);
521521
Assert.AreEqual(poll.Id, message.PollId);
522522

523-
// Fetch the poll to get the full object
524-
var messagePoll = await Client.Polls.GetPollAsync(message.PollId);
525-
Assert.NotNull(messagePoll);
526-
Assert.AreEqual(poll.Id, messagePoll.Id);
527-
528523
// User B connects and fetches the channel
529524
var otherClient = await GetConnectedOtherClientAsync();
530525
var otherClientChannel = await otherClient.GetOrCreateChannelWithIdAsync(channel.Type, channel.Id);
@@ -559,7 +554,7 @@ void OnVoteCasted(IStreamPoll eventPoll, StreamPollVote vote)
559554
eventThreadId = GetCurrentThreadId();
560555
}
561556

562-
messagePoll.VoteCasted += OnVoteCasted;
557+
poll.VoteCasted += OnVoteCasted;
563558

564559
// User B casts a vote - must provide the message ID
565560
var optionToCastVote = otherClientPoll.Options.First();
@@ -573,7 +568,7 @@ void OnVoteCasted(IStreamPoll eventPoll, StreamPollVote vote)
573568
await WaitWhileFalseAsync(() => voteEventReceived, maxSeconds: 20);
574569

575570
// Clean up event handler
576-
messagePoll.VoteCasted -= OnVoteCasted;
571+
poll.VoteCasted -= OnVoteCasted;
577572

578573
// Verify the event was received
579574
Assert.IsTrue(voteEventReceived);
@@ -584,8 +579,9 @@ void OnVoteCasted(IStreamPoll eventPoll, StreamPollVote vote)
584579
Assert.AreEqual(MainThreadId, eventThreadId);
585580

586581
// Verify the poll state was updated for User A
587-
Assert.AreEqual(1, messagePoll.VoteCount);
588-
Assert.IsTrue(messagePoll.LatestAnswers.Any(v => v.UserId == otherClient.LocalUserData.UserId));
582+
Assert.AreEqual(1, poll.VoteCount);
583+
Assert.IsTrue(poll.LatestVotesByOption.ContainsKey(optionToCastVote.Id));
584+
Assert.IsTrue(poll.LatestVotesByOption[optionToCastVote.Id].Any(v => v.UserId == otherClient.LocalUserData.UserId));
589585
}
590586
}
591587
}

0 commit comments

Comments
 (0)