[Bps-public-commit] rt-extension-rest2 branch, handle-missing-content-in-json, created. 1.09-23-g4f05d3b

Dianne Skoll dianne at bestpractical.com
Thu Feb 18 12:15:06 EST 2021


The branch, handle-missing-content-in-json has been created
        at  4f05d3b709f17ecee77f42c8b7b16ab13b0ec3cc (commit)

- Log -----------------------------------------------------------------
commit 3ee5807b8e4c7672146e8b95bd4fe469acdfcbd7
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Thu Feb 18 12:05:45 2021 -0500

    Fix logic error: NoContent was only set if we had attachments

diff --git a/lib/RT/Extension/REST2/Resource/Message.pm b/lib/RT/Extension/REST2/Resource/Message.pm
index e8d9266..48ffbf6 100644
--- a/lib/RT/Extension/REST2/Resource/Message.pm
+++ b/lib/RT/Extension/REST2/Resource/Message.pm
@@ -91,10 +91,9 @@ sub from_json {
                 unless $attachment->{$field};
             }
         }
-
-        $body->{NoContent} = 1 unless $body->{Content};
     }
 
+    $body->{NoContent} = 1 unless $body->{Content};
     if (!$body->{NoContent} && !$body->{ContentType}) {
         return error_as_json(
             $self->response,

commit 4f05d3b709f17ecee77f42c8b7b16ab13b0ec3cc
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Thu Feb 18 12:14:20 2021 -0500

    Add unit test to verify logic error was fixed

diff --git a/xt/tickets.t b/xt/tickets.t
index 6c651d0..22706ff 100644
--- a/xt/tickets.t
+++ b/xt/tickets.t
@@ -467,6 +467,28 @@ my ($ticket_url, $ticket_id);
     is($content->{ContentType}, 'text/html');
 }
 
+# Ticket Reply, JSON request, missing Content
+{
+    my $res = $mech->get($ticket_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+    my $content = $mech->json_response;
+
+    my ($hypermedia) = grep { $_->{ref} eq 'correspond' } @{ $content->{_hyperlinks} };
+    ok($hypermedia, 'got correspond hypermedia');
+    like($hypermedia->{_url}, qr[$rest_base_path/ticket/$ticket_id/correspond$]);
+
+    $res = $mech->post($mech->url_for_hypermedia('correspond'),
+        'Authorization' => $auth,
+        'Content-Type' => 'application/json',
+        'Content' => '{"Subject":"No body!"}',
+    );
+    is($res->code, 201);
+
+    cmp_deeply($mech->json_response, [re(qr/Correspondence added|Message recorded/)]);
+}
+
 # Ticket Reply, changing status
 {
     my $res = $mech->get($ticket_url,

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


More information about the Bps-public-commit mailing list