diff --git a/tests/48admin.pl b/tests/48admin.pl new file mode 100644 index 000000000..3e445893d --- /dev/null +++ b/tests/48admin.pl @@ -0,0 +1,35 @@ +test "/whois", + requires => [ $main::API_CLIENTS[0] ], + + do => sub { + my ( $http ) = @_; + + my $user; + + # Register a user, rather than using a fixture, because we want to very + # tightly control the actions taken by that user. + # Conceivably this API may change based on the number of API calls the + # user made, for instance. + matrix_register_user( $http ) + ->then( sub { + ( $user ) = @_; + + do_request_json_for( $user, + method => "GET", + uri => "/api/v1/admin/whois/".$user->user_id, + ) + })->then( sub { + my ( $body ) = @_; + + assert_json_keys( $body, qw( devices user_id ) ); + assert_eq( $body->{user_id}, $user->user_id, "user_id" ); + assert_json_list( $body->{devices} ); + assert_json_keys( $body->{devices}[0], "sessions" ); + assert_json_list( $body->{devices}[0]{sessions} ); + assert_json_keys( $body->{devices}[0]{sessions}[0], "connections" ); + assert_json_list( $body->{devices}[0]{sessions}[0]{connections} ); + assert_json_keys( $body->{devices}[0]{sessions}[0]{connections}[0], qw( ip last_seen user_agent ) ); + + Future->done( 1 ); + }); + };