|
14 | 14 |
|
15 | 15 | use Future::Utils qw( repeat ); |
16 | 16 | use List::Util qw( all first none ); |
| 17 | +use URI::Escape qw( uri_escape ); |
17 | 18 |
|
18 | 19 | push our @EXPORT, qw ( upgrade_room_synced $TEST_NEW_VERSION ); |
19 | 20 |
|
@@ -337,7 +338,8 @@ sub upgrade_room_synced { |
337 | 338 | matrix_change_room_power_levels( |
338 | 339 | $creator, $room_id, sub { |
339 | 340 | ( $pl_content ) = @_; |
340 | | - $pl_content->{users}->{'@test:xyz'} = 40; |
| 341 | + $pl_content->{users}->{'@test:xyz'} = JSON::number(40); |
| 342 | + log_if_fail "PL content in old room", $pl_content; |
341 | 343 | } |
342 | 344 | )->then( sub { |
343 | 345 | matrix_sync( $creator ); |
@@ -372,6 +374,94 @@ sub upgrade_room_synced { |
372 | 374 | }); |
373 | 375 | }; |
374 | 376 |
|
| 377 | +test "/upgrade preserves the power level of the upgrading user in old and new rooms", |
| 378 | + requires => [ |
| 379 | + local_user_and_room_fixtures(), |
| 380 | + local_user_fixture(), |
| 381 | + qw( can_upgrade_room_version can_change_power_levels ), |
| 382 | + ], |
| 383 | + |
| 384 | + do => sub { |
| 385 | + my ( $creator, $room_id, $upgrader ) = @_; |
| 386 | + |
| 387 | + my ( $pl_content, $new_room_id ); |
| 388 | + |
| 389 | + # Note that this test assumes that moderators by default are allowed to upgrade rooms |
| 390 | + |
| 391 | + matrix_join_room_synced( |
| 392 | + $upgrader, $room_id |
| 393 | + )->then( sub { |
| 394 | + # Make the joined user a moderator |
| 395 | + matrix_change_room_power_levels( |
| 396 | + $creator, $room_id, sub { |
| 397 | + ( $pl_content ) = @_; |
| 398 | + $pl_content->{users}->{$upgrader->user_id} = JSON::number(50); |
| 399 | + log_if_fail "PL content in old room", $pl_content; |
| 400 | + } |
| 401 | + ) |
| 402 | + })->then( sub { |
| 403 | + matrix_sync( $upgrader ); |
| 404 | + })->then( sub { |
| 405 | + upgrade_room_synced( |
| 406 | + $upgrader, $room_id, |
| 407 | + expected_event_counts => { 'm.room.power_levels' => 1 }, |
| 408 | + new_version => $TEST_NEW_VERSION, |
| 409 | + ); |
| 410 | + })->then( sub { |
| 411 | + ( $new_room_id, ) = @_; |
| 412 | + |
| 413 | + matrix_sync_again( $upgrader ); |
| 414 | + })->then( sub { |
| 415 | + my ( $sync_body ) = @_; |
| 416 | + |
| 417 | + log_if_fail "sync body", $sync_body; |
| 418 | + |
| 419 | + # Two power level events will be sent in the new room. The first is to make the |
| 420 | + # upgrader user (previously a moderator) an Administrator (which can only be done |
| 421 | + # when creating the room). This is such that they could send the initial state |
| 422 | + # events. The second power level event is to downgrade the upgrader user from a |
| 423 | + # Administrator to a Moderator again to keep a consistent state with the old room |
| 424 | + |
| 425 | + # Grab the latest power level state of the new room |
| 426 | + my $url_encoded_new_room_id = uri_escape( $new_room_id ); |
| 427 | + do_request_json_for( |
| 428 | + $upgrader, |
| 429 | + method => "GET", |
| 430 | + uri => "/r0/rooms/$url_encoded_new_room_id/state/m.room.power_levels/", |
| 431 | + content => {}, |
| 432 | + ); |
| 433 | + })->then( sub { |
| 434 | + my ( $new_room_pl_content ) = @_; |
| 435 | + |
| 436 | + # Check that the power levels in the new room match the original PLs |
| 437 | + assert_deeply_eq( |
| 438 | + $new_room_pl_content, |
| 439 | + $pl_content, |
| 440 | + "power levels in replacement room", |
| 441 | + ); |
| 442 | + |
| 443 | + # Grab the latest power level state of the old room |
| 444 | + my $url_encoded_old_room_id = uri_escape( $room_id ); |
| 445 | + do_request_json_for( |
| 446 | + $upgrader, |
| 447 | + method => "GET", |
| 448 | + uri => "/r0/rooms/$url_encoded_old_room_id/state/m.room.power_levels/", |
| 449 | + content => {}, |
| 450 | + ); |
| 451 | + })->then( sub { |
| 452 | + my ( $old_room_pl_content ) = @_; |
| 453 | + |
| 454 | + # Check that the power levels in the old room have not changed |
| 455 | + assert_deeply_eq( |
| 456 | + $old_room_pl_content, |
| 457 | + $pl_content, |
| 458 | + "power levels in old room", |
| 459 | + ); |
| 460 | + |
| 461 | + Future->done(1); |
| 462 | + }); |
| 463 | + }; |
| 464 | + |
375 | 465 | test "/upgrade copies important state to the new room", |
376 | 466 | requires => [ |
377 | 467 | local_user_and_room_fixtures(), |
|
0 commit comments