@@ -187,6 +187,49 @@ async fn test_events_received_before_start_are_not_lost() {
187
187
assert_eq ! ( results. votes[ "1" ] , vec![ ALICE . to_string( ) ] ) ;
188
188
}
189
189
190
+ #[ async_test]
191
+ async fn test_adding_response_doesnt_clear_latest_json_edit ( ) {
192
+ let timeline = TestTimeline :: new ( ) ;
193
+
194
+ // Alice sends the poll.
195
+ timeline. send_poll_start ( & ALICE , fakes:: poll_a ( ) ) . await ;
196
+
197
+ // Alice edits the poll.
198
+ let poll_item = timeline. poll_event ( ) . await ;
199
+ let poll_id = poll_item. event_id ( ) . unwrap ( ) ;
200
+ timeline. send_poll_edit ( & ALICE , poll_id, fakes:: poll_b ( ) ) . await ;
201
+ // Sanity check: the poll has a latest edit JSON.
202
+ assert ! ( timeline. event_items( ) . await [ 0 ] . latest_edit_json( ) . is_some( ) ) ;
203
+
204
+ // Now Bob also votes
205
+ timeline. send_poll_response ( & BOB , vec ! [ "0" ] , poll_id) . await ;
206
+
207
+ // The poll still has a latest edit JSON.
208
+ assert ! ( timeline. event_items( ) . await [ 0 ] . latest_edit_json( ) . is_some( ) ) ;
209
+ }
210
+
211
+ #[ async_test]
212
+ async fn test_ending_poll_doesnt_clear_latest_json_edit ( ) {
213
+ let timeline = TestTimeline :: new ( ) ;
214
+
215
+ // Alice sends the poll.
216
+ timeline. send_poll_start ( & ALICE , fakes:: poll_a ( ) ) . await ;
217
+
218
+ let poll_item = timeline. poll_event ( ) . await ;
219
+ let poll_id = poll_item. event_id ( ) . unwrap ( ) ;
220
+
221
+ // Alice edits the poll.
222
+ timeline. send_poll_edit ( & ALICE , poll_id, fakes:: poll_b ( ) ) . await ;
223
+ // Sanity check: the poll has a latest edit JSON.
224
+ assert ! ( timeline. event_items( ) . await [ 0 ] . latest_edit_json( ) . is_some( ) ) ;
225
+
226
+ // Now the poll is ended.
227
+ timeline. send_poll_end ( & ALICE , "ended" , poll_id) . await ;
228
+
229
+ // The poll still has a latest edit JSON.
230
+ assert ! ( timeline. event_items( ) . await [ 0 ] . latest_edit_json( ) . is_some( ) ) ;
231
+ }
232
+
190
233
impl TestTimeline {
191
234
async fn event_items ( & self ) -> Vec < EventTimelineItem > {
192
235
self . controller . items ( ) . await . iter ( ) . filter_map ( |item| item. as_event ( ) . cloned ( ) ) . collect ( )
0 commit comments