[Bps-public-commit] rt-extension-rest2 branch, master, updated. f0d2230b969f0fcae9c32d1617ceafb2bd10049f

Shawn Moore shawn at bestpractical.com
Tue Dec 13 17:01:57 EST 2016


The branch, master has been updated
       via  f0d2230b969f0fcae9c32d1617ceafb2bd10049f (commit)
       via  ceaf53d812477fa35eca8161e6eb51d7d4bfbda6 (commit)
      from  2f83f43d96109ca8c751324a1e76dcdb13e7bbb8 (commit)

Summary of changes:
 lib/RT/Extension/REST2/Resource/Collection.pm      |   1 -
 .../REST2/Resource/Collection/QueryByJSON.pm       |   1 +
 t/search-json.t                                    | 142 +++++++++++++++++++++
 3 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 t/search-json.t

- Log -----------------------------------------------------------------
commit ceaf53d812477fa35eca8161e6eb51d7d4bfbda6
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Dec 13 20:49:05 2016 +0000

    Remove unused (and unwise?) imports from Web::Machine::Util

diff --git a/lib/RT/Extension/REST2/Resource/Collection.pm b/lib/RT/Extension/REST2/Resource/Collection.pm
index 7d61bbf..75ba54f 100644
--- a/lib/RT/Extension/REST2/Resource/Collection.pm
+++ b/lib/RT/Extension/REST2/Resource/Collection.pm
@@ -8,7 +8,6 @@ use namespace::autoclean;
 extends 'RT::Extension::REST2::Resource';
 
 use Scalar::Util qw( blessed );
-use Web::Machine::Util qw( bind_path create_date );
 use Web::Machine::FSM::States qw( is_status_code );
 use Module::Runtime qw( require_module );
 use RT::Extension::REST2::Util qw( serialize_record expand_uid );

commit f0d2230b969f0fcae9c32d1617ceafb2bd10049f
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Dec 13 21:53:18 2016 +0000

    Tests for searching collections with JSON

diff --git a/lib/RT/Extension/REST2/Resource/Collection/QueryByJSON.pm b/lib/RT/Extension/REST2/Resource/Collection/QueryByJSON.pm
index 0bd19d9..b1e2dc1 100644
--- a/lib/RT/Extension/REST2/Resource/Collection/QueryByJSON.pm
+++ b/lib/RT/Extension/REST2/Resource/Collection/QueryByJSON.pm
@@ -53,6 +53,7 @@ sub limit_collection {
             ( $limit->{operator}
                 ? (OPERATOR => $limit->{operator})
                 : () ),
+            CASESENSITIVE => ($limit->{case_sensitive} || 0),
         );
     }
     return 1;
diff --git a/t/search-json.t b/t/search-json.t
new file mode 100644
index 0000000..5efd849
--- /dev/null
+++ b/t/search-json.t
@@ -0,0 +1,142 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use RT::Extension::REST2::Test tests => undef;
+
+my $mech = RT::Extension::REST2::Test->mech;
+my $auth = RT::Extension::REST2::Test->authorization_header;
+my $rest_base_path = '/REST/2.0';
+my $user = RT::Extension::REST2::Test->user;
+
+my $alpha = RT::Test->load_or_create_queue( Name => 'Alpha' );
+my $beta  = RT::Test->load_or_create_queue( Name => 'Beta' );
+my $bravo = RT::Test->load_or_create_queue( Name => 'Bravo' );
+$user->PrincipalObj->GrantRight( Right => 'SuperUser' );
+
+my $alpha_id = $alpha->Id;
+my $beta_id  = $beta->Id;
+my $bravo_id = $bravo->Id;
+
+# Name = General
+{
+    my $res = $mech->post_json("$rest_base_path/queues",
+        [{ field => 'Name', value => 'General' }],
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+
+    my $content = $mech->json_response;
+    is($content->{count}, 1);
+    is($content->{page}, 1);
+    is($content->{per_page}, 20);
+    is($content->{total}, 1);
+    is(scalar @{$content->{items}}, 1);
+
+    my $queue = $content->{items}->[0];
+    is($queue->{type}, 'queue');
+    is($queue->{id}, 1);
+    like($queue->{_url}, qr{$rest_base_path/queue/1$});
+}
+
+# Name != General
+{
+    my $res = $mech->post_json("$rest_base_path/queues",
+        [{ field => 'Name', operator => '!=', value => 'General' }],
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+
+    my $content = $mech->json_response;
+    is($content->{count}, 3);
+    is($content->{page}, 1);
+    is($content->{per_page}, 20);
+    is($content->{total}, 3);
+    is(scalar @{$content->{items}}, 3);
+
+    my ($first, $second, $third) = @{ $content->{items} };
+    is($first->{type}, 'queue');
+    is($first->{id}, $alpha_id);
+    like($first->{_url}, qr{$rest_base_path/queue/$alpha_id$});
+
+    is($second->{type}, 'queue');
+    is($second->{id}, $beta_id);
+    like($second->{_url}, qr{$rest_base_path/queue/$beta_id$});
+
+    is($third->{type}, 'queue');
+    is($third->{id}, $bravo_id);
+    like($third->{_url}, qr{$rest_base_path/queue/$bravo_id$});
+}
+
+# Name STARTSWITH B
+{
+    my $res = $mech->post_json("$rest_base_path/queues",
+        [{ field => 'Name', operator => 'STARTSWITH', value => 'B' }],
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+
+    my $content = $mech->json_response;
+    is($content->{count}, 2);
+    is($content->{page}, 1);
+    is($content->{per_page}, 20);
+    is($content->{total}, 2);
+    is(scalar @{$content->{items}}, 2);
+
+    my ($first, $second) = @{ $content->{items} };
+    is($first->{type}, 'queue');
+    is($first->{id}, $beta_id);
+    like($first->{_url}, qr{$rest_base_path/queue/$beta_id$});
+
+    is($second->{type}, 'queue');
+    is($second->{id}, $bravo_id);
+    like($second->{_url}, qr{$rest_base_path/queue/$bravo_id$});
+}
+
+# id > 2
+{
+    my $res = $mech->post_json("$rest_base_path/queues",
+        [{ field => 'id', operator => '>', value => 2 }],
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+
+    my $content = $mech->json_response;
+    is($content->{count}, 3);
+    is($content->{page}, 1);
+    is($content->{per_page}, 20);
+    is($content->{total}, 3);
+    is(scalar @{$content->{items}}, 3);
+
+    my ($first, $second, $third) = @{ $content->{items} };
+    is($first->{type}, 'queue');
+    is($first->{id}, $alpha_id);
+    like($first->{_url}, qr{$rest_base_path/queue/$alpha_id$});
+
+    is($second->{type}, 'queue');
+    is($second->{id}, $beta_id);
+    like($second->{_url}, qr{$rest_base_path/queue/$beta_id$});
+
+    is($third->{type}, 'queue');
+    is($third->{id}, $bravo_id);
+    like($third->{_url}, qr{$rest_base_path/queue/$bravo_id$});
+}
+
+# Invalid query ({ ... })
+{
+    my $res = $mech->post_json("$rest_base_path/queues",
+        { field => 'Name', value => 'General' },
+        'Authorization' => $auth,
+    );
+    is($res->code, 400);
+
+    my $content = $mech->json_response;
+
+    TODO: {
+        local $TODO = "better error reporting";
+        is($content->{message}, 'Query must be an array of objects');
+    }
+    is($content->{message}, 'JSON object must be a ARRAY');
+}
+
+done_testing;
+

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


More information about the Bps-public-commit mailing list