55using System . Linq ;
66using System . Threading . Tasks ;
77using NUnit . Framework ;
8- using StreamChat . Core ;
98using StreamChat . Core . LowLevelClient . Models ;
10- using StreamChat . Core . LowLevelClient . Requests ;
119using StreamChat . Core . Requests ;
12- using StreamChat . Core . StatefulModels ;
1310using UnityEngine . TestTools ;
1411
1512namespace StreamChat . Tests . StatefulClient
@@ -27,7 +24,7 @@ private async Task When_creating_poll_with_options_expect_poll_created_Async()
2724 {
2825 var pollId = "poll-" + Guid . NewGuid ( ) ;
2926
30- var createPollRequest = new CreatePollRequest
27+ var createPollRequest = new StreamCreatePollRequest
3128 {
3229 Id = pollId ,
3330 Name = "What is your favorite programming language?" ,
@@ -37,32 +34,31 @@ private async Task When_creating_poll_with_options_expect_poll_created_Async()
3734 AllowUserSuggestedOptions = false ,
3835 MaxVotesAllowed = 1 ,
3936 VotingVisibility = VotingVisibility . Public ,
40- Options = new List < PollOptionInput >
37+ Options = new List < StreamPollOptionRequest >
4138 {
42- new PollOptionInput { Text = "C#" } ,
43- new PollOptionInput { Text = "JavaScript" } ,
44- new PollOptionInput { Text = "Python" } ,
45- new PollOptionInput { Text = "Go" }
39+ new StreamPollOptionRequest { Text = "C#" } ,
40+ new StreamPollOptionRequest { Text = "JavaScript" } ,
41+ new StreamPollOptionRequest { Text = "Python" } ,
42+ new StreamPollOptionRequest { Text = "Go" }
4643 }
4744 } ;
4845
49- var response = await Client . InternalLowLevelClient . PollsApi . CreatePollAsync ( createPollRequest ) ;
50-
51- Assert . NotNull ( response ) ;
52- Assert . NotNull ( response . Poll ) ;
53- Assert . AreEqual ( pollId , response . Poll . Id ) ;
54- Assert . AreEqual ( "What is your favorite programming language?" , response . Poll . Name ) ;
55- Assert . AreEqual ( "Let us know which language you prefer" , response . Poll . Description ) ;
56- Assert . AreEqual ( true , response . Poll . EnforceUniqueVote ) ;
57- Assert . AreEqual ( false , response . Poll . AllowAnswers ) ;
58- Assert . AreEqual ( false , response . Poll . AllowUserSuggestedOptions ) ;
59- Assert . AreEqual ( 1 , response . Poll . MaxVotesAllowed ) ;
60- Assert . AreEqual ( VotingVisibility . Public , response . Poll . VotingVisibility ) ;
46+ var poll = await Client . Polls . CreatePollAsync ( createPollRequest ) ;
47+
48+ Assert . NotNull ( poll ) ;
49+ Assert . AreEqual ( pollId , poll . Id ) ;
50+ Assert . AreEqual ( "What is your favorite programming language?" , poll . Name ) ;
51+ Assert . AreEqual ( "Let us know which language you prefer" , poll . Description ) ;
52+ Assert . AreEqual ( true , poll . EnforceUniqueVote ) ;
53+ Assert . AreEqual ( false , poll . AllowAnswers ) ;
54+ Assert . AreEqual ( false , poll . AllowUserSuggestedOptions ) ;
55+ Assert . AreEqual ( 1 , poll . MaxVotesAllowed ) ;
56+ Assert . AreEqual ( VotingVisibility . Public , poll . VotingVisibility ) ;
6157
62- Assert . NotNull ( response . Poll . Options ) ;
63- Assert . AreEqual ( 4 , response . Poll . Options . Count ) ;
58+ Assert . NotNull ( poll . Options ) ;
59+ Assert . AreEqual ( 4 , poll . Options . Count ) ;
6460
65- var optionTexts = response . Poll . Options . Select ( o => o . Text ) . ToList ( ) ;
61+ var optionTexts = poll . Options . Select ( o => o . Text ) . ToList ( ) ;
6662 Assert . Contains ( "C#" , optionTexts ) ;
6763 Assert . Contains ( "JavaScript" , optionTexts ) ;
6864 Assert . Contains ( "Python" , optionTexts ) ;
@@ -79,33 +75,31 @@ private async Task When_fetching_poll_expect_poll_returned_Async()
7975 var pollName = "Best IDE for Unity development?" ;
8076
8177 // First, create a poll
82- var createPollRequest = new CreatePollRequest
78+ var createPollRequest = new StreamCreatePollRequest
8379 {
8480 Id = pollId ,
8581 Name = pollName ,
8682 Description = "Help us understand your preferences" ,
87- Options = new List < PollOptionInput >
83+ Options = new List < StreamPollOptionRequest >
8884 {
89- new PollOptionInput { Text = "Visual Studio" } ,
90- new PollOptionInput { Text = "Rider" } ,
91- new PollOptionInput { Text = "VS Code" }
85+ new StreamPollOptionRequest { Text = "Visual Studio" } ,
86+ new StreamPollOptionRequest { Text = "Rider" } ,
87+ new StreamPollOptionRequest { Text = "VS Code" }
9288 }
9389 } ;
9490
95- var createResponse = await Client . InternalLowLevelClient . PollsApi . CreatePollAsync ( createPollRequest ) ;
96- Assert . NotNull ( createResponse ) ;
97- Assert . NotNull ( createResponse . Poll ) ;
91+ var createdPoll = await Client . Polls . CreatePollAsync ( createPollRequest ) ;
92+ Assert . NotNull ( createdPoll ) ;
9893
9994 // Now fetch the poll
100- var fetchResponse = await Client . InternalLowLevelClient . PollsApi . GetPollAsync ( pollId ) ;
95+ var fetchedPoll = await Client . Polls . GetPollAsync ( pollId ) ;
10196
102- Assert . NotNull ( fetchResponse ) ;
103- Assert . NotNull ( fetchResponse . Poll ) ;
104- Assert . AreEqual ( pollId , fetchResponse . Poll . Id ) ;
105- Assert . AreEqual ( pollName , fetchResponse . Poll . Name ) ;
106- Assert . AreEqual ( 3 , fetchResponse . Poll . Options . Count ) ;
97+ Assert . NotNull ( fetchedPoll ) ;
98+ Assert . AreEqual ( pollId , fetchedPoll . Id ) ;
99+ Assert . AreEqual ( pollName , fetchedPoll . Name ) ;
100+ Assert . AreEqual ( 3 , fetchedPoll . Options . Count ) ;
107101
108- var optionTexts = fetchResponse . Poll . Options . Select ( o => o . Text ) . ToList ( ) ;
102+ var optionTexts = fetchedPoll . Options . Select ( o => o . Text ) . ToList ( ) ;
109103 Assert . Contains ( "Visual Studio" , optionTexts ) ;
110104 Assert . Contains ( "Rider" , optionTexts ) ;
111105 Assert . Contains ( "VS Code" , optionTexts ) ;
@@ -121,23 +115,22 @@ private async Task When_sending_message_with_poll_expect_poll_in_message_Async()
121115 var pollId = "poll-" + Guid . NewGuid ( ) ;
122116
123117 // Create a poll
124- var createPollRequest = new CreatePollRequest
118+ var createPollRequest = new StreamCreatePollRequest
125119 {
126120 Id = pollId ,
127121 Name = "Which feature should we prioritize?" ,
128122 Description = "Vote for the most important feature" ,
129- Options = new List < PollOptionInput >
123+ Options = new List < StreamPollOptionRequest >
130124 {
131- new PollOptionInput { Text = "Performance improvements" } ,
132- new PollOptionInput { Text = "New UI components" } ,
133- new PollOptionInput { Text = "Better documentation" } ,
134- new PollOptionInput { Text = "More examples" }
125+ new StreamPollOptionRequest { Text = "Performance improvements" } ,
126+ new StreamPollOptionRequest { Text = "New UI components" } ,
127+ new StreamPollOptionRequest { Text = "Better documentation" } ,
128+ new StreamPollOptionRequest { Text = "More examples" }
135129 }
136130 } ;
137131
138- var pollResponse = await Client . InternalLowLevelClient . PollsApi . CreatePollAsync ( createPollRequest ) ;
139- Assert . NotNull ( pollResponse ) ;
140- Assert . NotNull ( pollResponse . Poll ) ;
132+ var poll = await Client . Polls . CreatePollAsync ( createPollRequest ) ;
133+ Assert . NotNull ( poll ) ;
141134
142135 // Send a message with the poll
143136 var messageRequest = new StreamSendMessageRequest
@@ -153,11 +146,10 @@ private async Task When_sending_message_with_poll_expect_poll_in_message_Async()
153146 Assert . AreEqual ( pollId , message . PollId ) ;
154147
155148 // Verify the poll can be fetched using the poll ID from the message
156- var fetchedPoll = await Client . InternalLowLevelClient . PollsApi . GetPollAsync ( message . PollId ) ;
149+ var fetchedPoll = await Client . Polls . GetPollAsync ( message . PollId ) ;
157150 Assert . NotNull ( fetchedPoll ) ;
158- Assert . NotNull ( fetchedPoll . Poll ) ;
159- Assert . AreEqual ( pollId , fetchedPoll . Poll . Id ) ;
160- Assert . AreEqual ( "Which feature should we prioritize?" , fetchedPoll . Poll . Name ) ;
151+ Assert . AreEqual ( pollId , fetchedPoll . Id ) ;
152+ Assert . AreEqual ( "Which feature should we prioritize?" , fetchedPoll . Name ) ;
161153 }
162154
163155 [ UnityTest ]
@@ -168,14 +160,14 @@ private async Task When_creating_poll_with_custom_data_expect_custom_data_preser
168160 {
169161 var pollId = "poll-" + Guid . NewGuid ( ) ;
170162
171- var createPollRequest = new CreatePollRequest
163+ var createPollRequest = new StreamCreatePollRequest
172164 {
173165 Id = pollId ,
174166 Name = "Test Poll" ,
175- Options = new List < PollOptionInput >
167+ Options = new List < StreamPollOptionRequest >
176168 {
177- new PollOptionInput { Text = "Option 1" } ,
178- new PollOptionInput { Text = "Option 2" }
169+ new StreamPollOptionRequest { Text = "Option 1" } ,
170+ new StreamPollOptionRequest { Text = "Option 2" }
179171 } ,
180172 Custom = new Dictionary < string , object >
181173 {
@@ -185,14 +177,13 @@ private async Task When_creating_poll_with_custom_data_expect_custom_data_preser
185177 }
186178 } ;
187179
188- var response = await Client . InternalLowLevelClient . PollsApi . CreatePollAsync ( createPollRequest ) ;
180+ var poll = await Client . Polls . CreatePollAsync ( createPollRequest ) ;
189181
190- Assert . NotNull ( response ) ;
191- Assert . NotNull ( response . Poll ) ;
192- Assert . NotNull ( response . Poll . Custom ) ;
193- Assert . IsTrue ( response . Poll . Custom . ContainsKey ( "category" ) ) ;
194- Assert . AreEqual ( "testing" , response . Poll . Custom [ "category" ] ) ;
195- Assert . IsTrue ( response . Poll . Custom . ContainsKey ( "priority" ) ) ;
182+ Assert . NotNull ( poll ) ;
183+ Assert . NotNull ( poll . CustomData ) ;
184+ Assert . IsTrue ( poll . CustomData . ContainsKey ( "category" ) ) ;
185+ Assert . AreEqual ( "testing" , poll . CustomData . Get < string > ( "category" ) ) ;
186+ Assert . IsTrue ( poll . CustomData . ContainsKey ( "priority" ) ) ;
196187 }
197188
198189 [ UnityTest ]
@@ -204,34 +195,32 @@ private async Task When_updating_poll_expect_poll_updated_Async()
204195 var pollId = "poll-" + Guid . NewGuid ( ) ;
205196
206197 // Create a poll
207- var createPollRequest = new CreatePollRequest
198+ var createPollRequest = new StreamCreatePollRequest
208199 {
209200 Id = pollId ,
210201 Name = "Original Name" ,
211202 Description = "Original Description" ,
212- Options = new List < PollOptionInput >
203+ Options = new List < StreamPollOptionRequest >
213204 {
214- new PollOptionInput { Text = "Option 1" }
205+ new StreamPollOptionRequest { Text = "Option 1" }
215206 }
216207 } ;
217208
218- var createResponse = await Client . InternalLowLevelClient . PollsApi . CreatePollAsync ( createPollRequest ) ;
219- Assert . NotNull ( createResponse ) ;
209+ var poll = await Client . Polls . CreatePollAsync ( createPollRequest ) ;
210+ Assert . NotNull ( poll ) ;
220211
221212 // Update the poll
222- var updatePollRequest = new UpdatePollRequest
213+ var updatePollRequest = new StreamUpdatePollRequest
223214 {
224215 Name = "Updated Name" ,
225216 Description = "Updated Description"
226217 } ;
227218
228- var updateResponse = await Client . InternalLowLevelClient . PollsApi . UpdatePollAsync ( pollId , updatePollRequest ) ;
219+ await poll . UpdateAsync ( updatePollRequest ) ;
229220
230- Assert . NotNull ( updateResponse ) ;
231- Assert . NotNull ( updateResponse . Poll ) ;
232- Assert . AreEqual ( pollId , updateResponse . Poll . Id ) ;
233- Assert . AreEqual ( "Updated Name" , updateResponse . Poll . Name ) ;
234- Assert . AreEqual ( "Updated Description" , updateResponse . Poll . Description ) ;
221+ Assert . AreEqual ( pollId , poll . Id ) ;
222+ Assert . AreEqual ( "Updated Name" , poll . Name ) ;
223+ Assert . AreEqual ( "Updated Description" , poll . Description ) ;
235224 }
236225
237226 [ UnityTest ]
@@ -243,35 +232,27 @@ private async Task When_closing_poll_expect_poll_closed_Async()
243232 var pollId = "poll-" + Guid . NewGuid ( ) ;
244233
245234 // Create a poll
246- var createPollRequest = new CreatePollRequest
235+ var createPollRequest = new StreamCreatePollRequest
247236 {
248237 Id = pollId ,
249238 Name = "Test Poll" ,
250239 IsClosed = false ,
251- Options = new List < PollOptionInput >
240+ Options = new List < StreamPollOptionRequest >
252241 {
253- new PollOptionInput { Text = "Option 1" }
242+ new StreamPollOptionRequest { Text = "Option 1" }
254243 }
255244 } ;
256245
257- var createResponse = await Client . InternalLowLevelClient . PollsApi . CreatePollAsync ( createPollRequest ) ;
258- Assert . NotNull ( createResponse ) ;
259- Assert . AreEqual ( false , createResponse . Poll . IsClosed ) ;
246+ var poll = await Client . Polls . CreatePollAsync ( createPollRequest ) ;
247+ Assert . NotNull ( poll ) ;
248+ Assert . AreEqual ( false , poll . IsClosed ) ;
260249
261- // Close the poll using partial update
262- var updatePartialRequest = new UpdatePollPartialRequest
263- {
264- Set = new Dictionary < string , object >
265- {
266- { "is_closed" , true }
267- }
268- } ;
250+ // Close the poll
251+ await poll . CloseAsync ( ) ;
269252
270- var updateResponse = await Client . InternalLowLevelClient . PollsApi . UpdatePollPartialAsync ( pollId , updatePartialRequest ) ;
253+ await WaitWhileFalseAsync ( ( ) => poll . IsClosed ) ;
271254
272- Assert . NotNull ( updateResponse ) ;
273- Assert . NotNull ( updateResponse . Poll ) ;
274- Assert . AreEqual ( true , updateResponse . Poll . IsClosed ) ;
255+ Assert . AreEqual ( true , poll . IsClosed ) ;
275256 }
276257
277258 [ UnityTest ]
@@ -283,37 +264,32 @@ private async Task When_adding_poll_option_expect_option_added_Async()
283264 var pollId = "poll-" + Guid . NewGuid ( ) ;
284265
285266 // Create a poll with initial options
286- var createPollRequest = new CreatePollRequest
267+ var createPollRequest = new StreamCreatePollRequest
287268 {
288269 Id = pollId ,
289270 Name = "Test Poll" ,
290271 AllowUserSuggestedOptions = true ,
291- Options = new List < PollOptionInput >
272+ Options = new List < StreamPollOptionRequest >
292273 {
293- new PollOptionInput { Text = "Option 1" } ,
294- new PollOptionInput { Text = "Option 2" }
274+ new StreamPollOptionRequest { Text = "Option 1" } ,
275+ new StreamPollOptionRequest { Text = "Option 2" }
295276 }
296277 } ;
297278
298- var createResponse = await Client . InternalLowLevelClient . PollsApi . CreatePollAsync ( createPollRequest ) ;
299- Assert . NotNull ( createResponse ) ;
300- Assert . AreEqual ( 2 , createResponse . Poll . Options . Count ) ;
279+ var poll = await Client . Polls . CreatePollAsync ( createPollRequest ) ;
280+ Assert . NotNull ( poll ) ;
281+ Assert . AreEqual ( 2 , poll . Options . Count ) ;
301282
302283 // Add a new option
303- var createOptionRequest = new CreatePollOptionRequest
304- {
305- Text = "Option 3"
306- } ;
284+ var newOption = await poll . AddOptionAsync ( "Option 3" ) ;
307285
308- var optionResponse = await Client . InternalLowLevelClient . PollsApi . CreatePollOptionAsync ( pollId , createOptionRequest ) ;
286+ //await WaitWhileFalseAsync(() => poll.Options.Count == 3 );
309287
310- Assert . NotNull ( optionResponse ) ;
311- Assert . NotNull ( optionResponse . PollOption ) ;
312- Assert . AreEqual ( "Option 3" , optionResponse . PollOption . Text ) ;
288+ Assert . NotNull ( newOption ) ;
289+ Assert . AreEqual ( "Option 3" , newOption . Text ) ;
313290
314- // Verify the poll now has 3 options
315- var fetchResponse = await Client . InternalLowLevelClient . PollsApi . GetPollAsync ( pollId ) ;
316- Assert . AreEqual ( 3 , fetchResponse . Poll . Options . Count ) ;
291+ // Verify the poll now has 3 options (state should be auto-updated)
292+ Assert . AreEqual ( 3 , poll . Options . Count ) ;
317293 }
318294 }
319295}
0 commit comments