<commit_before>test "GET /rooms/:room_id/state/m.room.power_levels can fetch levels",
   requires => [qw( user )],

   provides => [qw( can_get_power_levels )],

   check => sub {
      my ( $user ) = @_;

      matrix_create_room( $user )
      ->then( sub {
         my ( $room_id ) = @_;

         do_request_json_for( $user,
            method => "GET",
            uri    => "/api/v1/rooms/$room_id/state/m.room.power_levels",
         )
      })->then( sub {
         my ( $body ) = @_;

         # Simple level keys
         require_json_keys( $body, qw( ban kick redact state_default events_default users_default ));
         require_json_number( $body->{$_} ) for qw( ban kick redact state_default events_default users_default );

         require_json_object( $body->{events} );

         # Don't care what they keys are
         require_json_number( $_ ) for values %{ $body->{events} };

         require_json_number( $_ ) for values %{ $body->{users} };

         exists $body->{users}{ $user->user_id } or
            die "Expected room creator to exist in user powerlevel list";

         $body->{users}{ $user->user_id } > $body->{users_default} or
            die "Expected room creator to have a higher-than-default powerlevel";

         provide can_get_power_levels => 1;
         Future->done(1);
      });
   };

test "PUT /rooms/:room_id/state/m.room.power_levels can set levels",
   requires => [qw( user more_users
                    can_get_power_levels )],

   provides => [qw( can_set_power_levels )],

   do => sub {
      my ( $user, $more_users ) = @_;

      my $room_id;

      matrix_create_room( $user )
      ->then( sub {
         ( $room_id ) = @_;
<commit_msg>10apidoc/36room-levels doesn't actually use 'more_users'<commit_after>test "GET /rooms/:room_id/state/m.room.power_levels can fetch levels",
   requires => [qw( user )],

   provides => [qw( can_get_power_levels )],

   check => sub {
      my ( $user ) = @_;

      matrix_create_room( $user )
      ->then( sub {
         my ( $room_id ) = @_;

         do_request_json_for( $user,
            method => "GET",
            uri    => "/api/v1/rooms/$room_id/state/m.room.power_levels",
         )
      })->then( sub {
         my ( $body ) = @_;

         # Simple level keys
         require_json_keys( $body, qw( ban kick redact state_default events_default users_default ));
         require_json_number( $body->{$_} ) for qw( ban kick redact state_default events_default users_default );

         require_json_object( $body->{events} );

         # Don't care what they keys are
         require_json_number( $_ ) for values %{ $body->{events} };

         require_json_number( $_ ) for values %{ $body->{users} };

         exists $body->{users}{ $user->user_id } or
            die "Expected room creator to exist in user powerlevel list";

         $body->{users}{ $user->user_id } > $body->{users_default} or
            die "Expected room creator to have a higher-than-default powerlevel";

         provide can_get_power_levels => 1;
         Future->done(1);
      });
   };

test "PUT /rooms/:room_id/state/m.room.power_levels can set levels",
   requires => [qw( user
                    can_get_power_levels )],

   provides => [qw( can_set_power_levels )],

   do => sub {
      my ( $user ) = @_;

      my $room_id;

      matrix_create_room( $user )
      ->then( sub {
         ( $room_id ) = @_;

{'fraction_non_alphanumeric': 0.1377595788242176, 'fraction_numerical': 0.0029248318221702253, 'mean_word_length': 2.223374175306315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1187596', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1080, 'n_words': 256}