[Bps-public-commit] rt-extension-rest2 branch, master, updated. dcbd85d4070078ff4b45a30ed5ae054f4bea5408
Shawn Moore
shawn at bestpractical.com
Tue Dec 13 17:26:38 EST 2016
The branch, master has been updated
via dcbd85d4070078ff4b45a30ed5ae054f4bea5408 (commit)
via 89935e1c667d7371ba46373c49fde6a64dc026cf (commit)
from f0d2230b969f0fcae9c32d1617ceafb2bd10049f (commit)
Summary of changes:
t/queues.t | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
t/tickets.t | 2 +-
2 files changed, 234 insertions(+), 1 deletion(-)
create mode 100644 t/queues.t
- Log -----------------------------------------------------------------
commit 89935e1c667d7371ba46373c49fde6a64dc026cf
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Dec 13 22:15:48 2016 +0000
Fix assignment of $ticket_id
$ticket_id is assigned a value of 1 as in the return value because the regex
matched, but we're interested in the first capture group.
diff --git a/t/tickets.t b/t/tickets.t
index ad10175..627ed4c 100644
--- a/t/tickets.t
+++ b/t/tickets.t
@@ -60,7 +60,7 @@ my ($ticket_url, $ticket_id);
);
is($res->code, 201);
ok($ticket_url = $res->header('location'));
- ok($ticket_id = $ticket_url =~ qr[/ticket/(\d+)]);
+ ok(($ticket_id) = $ticket_url =~ qr[/ticket/(\d+)]);
}
# Ticket Display
commit dcbd85d4070078ff4b45a30ed5ae054f4bea5408
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Dec 13 22:17:53 2016 +0000
CRUD tests for Queues
diff --git a/t/queues.t b/t/queues.t
new file mode 100644
index 0000000..9be5138
--- /dev/null
+++ b/t/queues.t
@@ -0,0 +1,233 @@
+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;
+
+$user->PrincipalObj->GrantRight( Right => 'SuperUser' );
+
+my $queue_url;
+# search 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$});
+ $queue_url = $queue->{_url};
+}
+
+# Queue display
+{
+ my $res = $mech->get($queue_url,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 200);
+
+ my $content = $mech->json_response;
+ is($content->{id}, 1);
+ is($content->{Name}, 'General');
+ is($content->{Description}, 'The default queue');
+ is($content->{Lifecycle}, 'default');
+ is($content->{Disabled}, 0);
+
+ ok(exists $content->{$_}) for qw(LastUpdated Created SortOrder SLADisabled
+ CorrespondAddress CommentAddress);
+
+ my $links = $content->{_hyperlinks};
+ is($links->[0]{ref}, 'self');
+ is($links->[0]{id}, 1);
+ is($links->[0]{type}, 'queue');
+ like($links->[0]{_url}, qr[$rest_base_path/queue/1$]);
+
+ my $creator = $content->{Creator};
+ is($creator->{id}, 'RT_System');
+ is($creator->{type}, 'user');
+ like($creator->{_url}, qr{$rest_base_path/user/RT_System$});
+
+ my $updated_by = $content->{LastUpdatedBy};
+ is($updated_by->{id}, 'RT_System');
+ is($updated_by->{type}, 'user');
+ like($updated_by->{_url}, qr{$rest_base_path/user/RT_System$});
+
+ is_deeply($content->{Cc}, [], 'no Ccs set');
+ is_deeply($content->{AdminCc}, [], 'no AdminCcs set');
+
+ TODO: {
+ local $TODO = "need to filter out ticket-level roles";
+ ok(!exists($content->{Owner}), 'no Owner at the queue level');
+ ok(!exists($content->{Requestor}), 'no Requestor at the queue level');
+ }
+}
+
+# Queue update
+{
+ my $payload = {
+ Name => 'Bugs',
+ Description => 'gotta squash em all',
+ };
+
+ my $res = $mech->put_json($queue_url,
+ $payload,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 200);
+ is_deeply($mech->json_response, ['Queue General: Description changed from "The default queue" to "gotta squash em all"', 'Queue Bugs: Name changed from "General" to "Bugs"']);
+
+ $res = $mech->get($queue_url,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 200);
+
+ my $content = $mech->json_response;
+ is($content->{Name}, 'Bugs');
+ is($content->{Description}, 'gotta squash em all');
+
+ my $updated_by = $content->{LastUpdatedBy};
+ is($updated_by->{id}, 'test');
+ is($updated_by->{type}, 'user');
+ like($updated_by->{_url}, qr{$rest_base_path/user/test$});
+}
+
+# search Name = Bugs
+{
+ my $res = $mech->post_json("$rest_base_path/queues",
+ [{ field => 'Name', value => 'Bugs' }],
+ '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$});
+}
+
+# Queue delete
+{
+ my $res = $mech->delete($queue_url,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 204);
+
+ my $queue = RT::Queue->new(RT->SystemUser);
+ $queue->Load(1);
+ is($queue->Id, 1, '"deleted" queue still in the database');
+ ok($queue->Disabled, '"deleted" queue disabled');
+
+ $res = $mech->get($queue_url,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 200);
+
+ my $content = $mech->json_response;
+ is($content->{Name}, 'Bugs');
+ is($content->{Disabled}, 1);
+}
+
+# Queue create
+my ($features_url, $features_id);
+{
+ my $payload = {
+ Name => 'Features',
+ CorrespondAddress => 'features at example.com',
+ CommentAddress => 'comment at example.com',
+ };
+
+ my $res = $mech->post_json("$rest_base_path/queue",
+ $payload,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 201);
+ ok($features_url = $res->header('location'));
+ ok(($features_id) = $features_url =~ qr[/queue/(\d+)]);
+}
+
+# Queue display
+{
+ my $res = $mech->get($features_url,
+ 'Authorization' => $auth,
+ );
+ is($res->code, 200);
+
+ my $content = $mech->json_response;
+ is($content->{id}, $features_id);
+ is($content->{Name}, 'Features');
+ is($content->{Lifecycle}, 'default');
+ is($content->{Disabled}, 0);
+
+ ok(exists $content->{$_}) for qw(LastUpdated Created SortOrder SLADisabled
+ CorrespondAddress CommentAddress Description);
+
+ my $links = $content->{_hyperlinks};
+ is($links->[0]{ref}, 'self');
+ is($links->[0]{id}, $features_id);
+ is($links->[0]{type}, 'queue');
+ like($links->[0]{_url}, qr[$rest_base_path/queue/$features_id$]);
+
+ my $creator = $content->{Creator};
+ is($creator->{id}, 'test');
+ is($creator->{type}, 'user');
+ like($creator->{_url}, qr{$rest_base_path/user/test$});
+
+ my $updated_by = $content->{LastUpdatedBy};
+ is($updated_by->{id}, 'test');
+ is($updated_by->{type}, 'user');
+ like($updated_by->{_url}, qr{$rest_base_path/user/test$});
+
+ is_deeply($content->{Cc}, [], 'no Ccs set');
+ is_deeply($content->{AdminCc}, [], 'no AdminCcs set');
+
+ TODO: {
+ local $TODO = "need to filter out ticket-level roles";
+ ok(!exists($content->{Owner}), 'no Owner at the queue level');
+ ok(!exists($content->{Requestor}), 'no Requestor at the queue level');
+ }
+}
+
+# id > 0 (finds new Features queue but not disabled Bugs queue)
+{
+ my $res = $mech->post_json("$rest_base_path/queues",
+ [{ field => 'id', operator => '>', value => 0 }],
+ '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}, $features_id);
+ like($queue->{_url}, qr{$rest_base_path/queue/$features_id$});
+}
+
+done_testing;
+
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list