[Bps-public-commit] rt-extension-rest2 03/05: Test /tickets/bulk/correspond and /tickets/bulk/comment endpoints

sunnavy sunnavy at bestpractical.com
Fri Jul 16 19:39:48 UTC 2021


This is an automated email from the git hooks/post-receive script.

jbrandt pushed a commit to branch tickets-bulk-message
in repository rt-extension-rest2.

commit 96b713a6cba048ae390a3209d8f77b1a0842175f
Author: sunnavy <sunnavy at bestpractical.com>
AuthorDate: Fri Jun 18 02:47:35 2021 +0800

    Test /tickets/bulk/correspond and /tickets/bulk/comment endpoints
---
 xt/tickets-bulk.t | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/xt/tickets-bulk.t b/xt/tickets-bulk.t
index b6a67bf..0b8b23b 100644
--- a/xt/tickets-bulk.t
+++ b/xt/tickets-bulk.t
@@ -176,6 +176,7 @@ my @ticket_ids;
         ],
         'json response content'
     );
+    $user->PrincipalObj->RevokeRight( Right => 'ModifyTicket' );
 }
 
 {
@@ -185,5 +186,80 @@ my @ticket_ids;
     }
 }
 
+$user->PrincipalObj->GrantRight( Right => 'ShowTicket' );
+
+{
+    diag "no ReplyToTicket right";
+    my $res = $mech->post_json(
+        "$rest_base_path/tickets/bulk/correspond",
+        [ { id => $ticket_ids[0], Content => 'test correspond', ContentType => 'text/plain' } ],
+        'Authorization' => $auth,
+    );
+    is( $res->code, 201, "status code" );
+    is_deeply( $mech->json_response, [ [ $ticket_ids[0], "Permission Denied", ] ], 'permission denied' );
+
+    diag "grant ReplyToTicket right";
+    $user->PrincipalObj->GrantRight( Right => 'ReplyToTicket' );
+
+    $res = $mech->post_json(
+        "$rest_base_path/tickets/bulk/correspond",
+        [ { id => $ticket_ids[0], Content => 'test correspond', ContentType => 'text/plain' } ],
+        'Authorization' => $auth,
+    );
+    is( $res->code, 201, 'status code' );
+    is_deeply( $mech->json_response, [ [ $ticket_ids[0], "Correspondence added", ] ], 'Correspondence added' );
+
+    $user->PrincipalObj->GrantRight( Right => 'ModifyTicket' );
+    $res = $mech->post_json(
+        "$rest_base_path/tickets/bulk/correspond",
+        [ { id => $ticket_ids[0], Content => 'test correspond', ContentType => 'text/plain', Status => 'new' } ],
+        'Authorization' => $auth,
+    );
+    is( $res->code, 201, 'status code' );
+    is_deeply(
+        $mech->json_response,
+        [ [ $ticket_ids[0], "Correspondence added", "Status changed from 'open' to 'new'" ] ],
+        'Correspondence added'
+    );
+    $user->PrincipalObj->RevokeRight( Right => $_ ) for qw/ReplyToTicket ModifyTicket/;
+}
+
+{
+    diag "no CommentOnTicket right";
+    my $res = $mech->post_json(
+        "$rest_base_path/tickets/bulk/comment",
+        [ { id => $ticket_ids[0], Content => 'test comment', ContentType => 'text/plain' } ],
+        'Authorization' => $auth,
+    );
+    is( $res->code, 201, "status code" );
+    is_deeply( $mech->json_response, [ [ $ticket_ids[0], "Permission Denied", ] ], 'permission denied' );
+
+    diag "grant CommentOnTicket right";
+    $user->PrincipalObj->GrantRight( Right => 'CommentOnTicket' );
+
+    $res = $mech->post_json(
+        "$rest_base_path/tickets/bulk/comment",
+        [ { id => $ticket_ids[0], Content => 'test comment', ContentType => 'text/plain' } ],
+        'Authorization' => $auth,
+    );
+    is( $res->code, 201, 'status code' );
+    is_deeply( $mech->json_response, [ [ $ticket_ids[0], "Comments added", ] ], 'Comments added' );
+
+    # Do status change along with comment
+    $user->PrincipalObj->GrantRight( Right => $_ ) for qw/ShowTicket ModifyTicket/;
+    $res = $mech->post_json(
+        "$rest_base_path/tickets/bulk/comment",
+        [ { id => $ticket_ids[0], Content => 'test comment', ContentType => 'text/plain', Status => 'open' } ],
+        'Authorization' => $auth,
+    );
+    is( $res->code, 201, 'status code' );
+    is_deeply(
+        $mech->json_response,
+        [ [ $ticket_ids[0], "Comments added", "Status changed from 'new' to 'open'" ] ],
+        'Comments added'
+    );
+    $user->PrincipalObj->RevokeRight( Right => $_ ) for qw/CommentOnTicket ModifyTicket/;
+}
+
 done_testing;
 

-- 
To stop receiving notification emails like this one, please contact
sysadmin at bestpractical.com.


More information about the Bps-public-commit mailing list