Skip to content

Commit

Permalink
Test REST2 /users/privileged and /users/unprivileged endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Nov 27, 2024
1 parent 584042b commit 72cb1a7
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion t/rest2/users.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ my $user_foo = RT::Test->load_or_create_user(
);
my $user_bar = RT::Test->load_or_create_user( Name => 'bar', RealName => 'Bar Jr III', );
my $user_baz = RT::Test->load_or_create_user( Name => 'baz' );
my $user_quuz = RT::Test->load_or_create_user( Name => 'quuz' );
my $user_quuz = RT::Test->load_or_create_user( Name => 'quuz', Privileged => 0 );

$user_baz->SetDisabled(1);

Expand Down Expand Up @@ -195,6 +195,39 @@ diag "Test searching users based on custom field value";
is( $content->{'items'}[0]->{'id'}, 'foo', "Found foo user" );
}

diag "Test searching privileged/unprivileged users";
{
my $payload = [
{ "field" => 'Name',
"value" => "bar",
"operator" => "="
},
{ "field" => 'Name',
"value" => "quuz",
"operator" => "="
},
];

my $res = $mech->post_json( "$rest_base_path/users", $payload, 'Authorization' => $auth, );
is( $res->code, 200 );
my $content = $mech->json_response;
is( $content->{'count'}, 2, "Found two users" );
is( $content->{'items'}[0]->{'id'}, 'bar', "Found bar user" );
is( $content->{'items'}[1]->{'id'}, 'quuz', "Found quuz user" );

$res = $mech->post_json( "$rest_base_path/users/privileged", $payload, 'Authorization' => $auth, );
is( $res->code, 200 );
$content = $mech->json_response;
is( $content->{'count'}, 1, "Found one user" );
is( $content->{'items'}[0]->{'id'}, 'bar', "Found bar user" );

$res = $mech->post_json( "$rest_base_path/users/unprivileged", $payload, 'Authorization' => $auth, );
is( $res->code, 200 );
$content = $mech->json_response;
is( $content->{'count'}, 1, "Found one user" );
is( $content->{'items'}[0]->{'id'}, 'quuz', "Found quuz user" );
}

$test_user->PrincipalObj->RevokeRight( Right => $_ ) for qw/SeeCustomField ShowUserHistory AdminUsers/;

done_testing;

0 comments on commit 72cb1a7

Please sign in to comment.