[Bps-public-commit] rt-extension-rest2 branch, dev, updated. e43c9dc37c2e67f5653279c4eb2883c16d683c28

Wallace Reis wreis at bestpractical.com
Wed Feb 25 16:37:32 EST 2015


The branch, dev has been updated
       via  e43c9dc37c2e67f5653279c4eb2883c16d683c28 (commit)
       via  bdf35e2b6a4410d7d4afded5b7491458f461bdeb (commit)
       via  e12db290efa01dddf716fd82f34e62c168354a35 (commit)
      from  f00e2c6c63455c241be7f936f020e891041f9e63 (commit)

Summary of changes:
 lib/RT/Extension/REST2/Resource/Tickets.pm |  5 +--
 t/acceptance/tickets.t                     | 49 +++++++++++++++++++++++++++---
 2 files changed, 47 insertions(+), 7 deletions(-)

- Log -----------------------------------------------------------------
commit e12db290efa01dddf716fd82f34e62c168354a35
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Tue Feb 24 15:01:15 2015 -0300

    Add more ticket tests

diff --git a/t/acceptance/tickets.t b/t/acceptance/tickets.t
index ef1612a..6cdedb9 100644
--- a/t/acceptance/tickets.t
+++ b/t/acceptance/tickets.t
@@ -68,10 +68,38 @@ TODO : {
     is($res->code, 201);
     like($res->header('content-type'), qr{application/json});
     my $new_ticket_url = $res->header('location');
-    like($new_ticket_url, qr[/ticket/\d+]);
+    ok(my $ticket_id = $new_ticket_url =~ qr[/ticket/(\d+)]);
+
     $mech->get_ok($rest_base_path . $new_ticket_url,
         ['Authorization' => $auth]
     );
+    $res = $mech->res;
+    like($res->header('content-type'), qr{application/json});
+    ok(my $data = $json->decode($res->content));
+    is($data->{'id'}, $ticket_id);
+    is($data->{'Type'}, 'ticket');
+    is($data->{'Status'}, 'new');
+    is($data->{'Subject'}, 'Ticket creation using REST');
+    like($data->{'_url'}, qr[/ticket/$ticket_id]);
+    ok(exists $data->{$_}) for qw(AdminCc TimeEstimated Started Cc
+                                  LastUpdated TimeWorked Resolved
+                                  Created Due Priority EffectiveId);
+    my $queue = $data->{'Queue'};
+    is($queue->{'id'}, 1);
+    is($queue->{'type'}, 'queue');
+    like($queue->{'_url'}, qr{/queue/1});
+    my $owner = $data->{'Owner'};
+    is($owner->{'id'}, 'Nobody');
+    is($owner->{'type'}, 'user');
+    like($owner->{'_url'}, qr{/user/Nobody});
+    my $creator = $data->{'Creator'};
+    is($creator->{'id'}, 'root');
+    is($creator->{'type'}, 'user');
+    like($creator->{'_url'}, qr{/user/root});
+    my $updated_by = $data->{'LastUpdatedBy'};
+    is($updated_by->{'id'}, 'root');
+    is($updated_by->{'type'}, 'user');
+    like($updated_by->{'_url'}, qr{/user/root});
 }
 
 done_testing;

commit bdf35e2b6a4410d7d4afded5b7491458f461bdeb
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Tue Feb 24 16:01:27 2015 -0300

    Ticket search - status code for no rows

diff --git a/lib/RT/Extension/REST2/Resource/Tickets.pm b/lib/RT/Extension/REST2/Resource/Tickets.pm
index 39ff184..afcb57b 100644
--- a/lib/RT/Extension/REST2/Resource/Tickets.pm
+++ b/lib/RT/Extension/REST2/Resource/Tickets.pm
@@ -43,13 +43,14 @@ sub limit_collection {
     my $self = shift;
     my $collection = $self->collection;
     my ($ok, $msg) = $collection->FromSQL( $self->query );
+    my $status_code;
     if ($ok) {
         unless ($collection->Count) {
-            ($ok, $msg) = (0, 'No tickets found');
+            ($status_code, $ok, $msg) = (\404, 0, 'No tickets found');
         }
     }
     return error_as_json(
-        $self->response, $ok ? 1 : 0, $msg
+        $self->response, $ok ? 1 : ($status_code // 0), $msg
     );
 }
 
diff --git a/t/acceptance/tickets.t b/t/acceptance/tickets.t
index 6cdedb9..790ec9e 100644
--- a/t/acceptance/tickets.t
+++ b/t/acceptance/tickets.t
@@ -14,10 +14,7 @@ my $json = JSON->new->utf8;
     ok(my $res = $mech->get(
         $rest_base_path . '/tickets?query=id>0', 'Authorization' => $auth
     ));
-    TODO : {
-        local $TODO = 'Status code for no rows';
-        is($res->code, 404, 'DB empty, so no tickets found');
-    }
+    is($res->code, 404, 'DB empty, so no tickets found');
     like($res->header('content-type'), qr{application/json});
     ok(my $data = $json->decode($res->content));
     is($data->{'message'}, 'No tickets found');

commit e43c9dc37c2e67f5653279c4eb2883c16d683c28
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Wed Feb 25 18:36:53 2015 -0300

    Ticket search - Yet more test

diff --git a/t/acceptance/tickets.t b/t/acceptance/tickets.t
index 790ec9e..b06ba09 100644
--- a/t/acceptance/tickets.t
+++ b/t/acceptance/tickets.t
@@ -99,4 +99,18 @@ TODO : {
     like($updated_by->{'_url'}, qr{/user/root});
 }
 
+{
+    $mech->get_ok(
+        $rest_base_path . '/tickets?query=id>0', ['Authorization' => $auth]
+    );
+    my $res = $mech->res;
+    like($res->header('content-type'), qr{application/json});
+    ok(my $data = $json->decode($res->content));
+    is($data->{'count'}, 1);
+    is($data->{'page'}, 1);
+    is($data->{'per_page'}, 20);
+    is($data->{'total'}, 1);
+    is(scalar @{$data->{'items'}}, $data->{'count'});
+}
+
 done_testing;

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


More information about the Bps-public-commit mailing list