[Rt-commit] rt branch, 5.0/rest2-support-attachments-when-creating-ticket, updated. rt-5.0.0-59-gd2ccbc37f3

? sunnavy sunnavy at bestpractical.com
Wed Oct 28 18:08:52 EDT 2020


The branch, 5.0/rest2-support-attachments-when-creating-ticket has been updated
       via  d2ccbc37f3fef78a2c6dc95a3c54e41dcc763303 (commit)
      from  ba3b448a581ac3a18edb74b95611eb43e989f6e6 (commit)

Summary of changes:
 t/rest2/tickets.t | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

- Log -----------------------------------------------------------------
commit d2ccbc37f3fef78a2c6dc95a3c54e41dcc763303
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Oct 29 05:55:19 2020 +0800

    Test custom field uploads on ticket create for REST2

diff --git a/t/rest2/tickets.t b/t/rest2/tickets.t
index 9b9b0fdb43..72e1f6a011 100644
--- a/t/rest2/tickets.t
+++ b/t/rest2/tickets.t
@@ -637,4 +637,45 @@ my $json = JSON->new->utf8;
     like( $attachments->[4]->Content, qr/IHDR/, "Looks like a PNG image" );
 }
 
+# Ticket Creation - with custom field uploads, using multipart/form-data
+{
+    my $image_cf = RT::Test->load_or_create_custom_field( Name => 'Image', Queue => 'General', Type => 'Image' );
+    $user->PrincipalObj->GrantRight( Right => $_ ) for qw/SeeCustomField ModifyCustomField/;
+
+    my $img_name = 'image.png';
+    my $img_path = RT::Test::get_relocatable_file( $img_name, 'data' );
+    my $img_content = do {
+        local $/;
+        open my $fh, '<', $img_path or die $!;
+        <$fh>;
+    };
+
+    my $payload  = {
+        Subject      => 'Ticket creation using REST, multipart/form-data, with custom field uploads',
+        Queue        => 'General',
+        Content      => 'Testing ticket creation, multipart/form-data, with custom field uploads using REST API.',
+        CustomFields => { Image => { UploadField => 'image' } },
+    };
+
+    my $res = $mech->post(
+        "$rest_base_path/ticket",
+        $payload,
+        'Authorization' => $auth,
+        'Content_Type'  => 'form-data',
+        'Content'       => [
+            'JSON'  => $json->encode($payload),
+            'image' => [ $img_path, $img_name, 'image/png' ],
+        ],
+    );
+    is( $res->code, 201 );
+    ok( $ticket_url = $res->header('location') );
+    ok( ($ticket_id) = $ticket_url =~ qr[/ticket/(\d+)] );
+
+    my $ticket = RT::Ticket->new($user);
+    $ticket->Load($ticket_id);
+    my $value = $ticket->CustomFieldValues( $image_cf )->First;
+    is( $value->Content, 'image.png', 'image file name');
+    is( $value->LargeContent, $img_content, 'image file content');
+}
+
 done_testing;

-----------------------------------------------------------------------


More information about the rt-commit mailing list