[Bps-public-commit] rt-extension-rest2 branch, transaction-cfs, updated. 1.07-9-gea9b66c

Aaron Trevena ast at bestpractical.com
Thu Mar 12 08:25:51 EDT 2020


The branch, transaction-cfs has been updated
       via  ea9b66cfa72a2e2e11c3c9f12b5c44129b4f4d95 (commit)
      from  e3b6480cc0454e0c617f7b5a7c78a1c4059a1bfc (commit)

Summary of changes:
 xt/transaction-customfields.t | 91 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

- Log -----------------------------------------------------------------
commit ea9b66cfa72a2e2e11c3c9f12b5c44129b4f4d95
Author: Andrew Ruthven <puck at catalystcloud.nz>
Date:   Sun Dec 1 21:00:17 2019 +0000

    Test seting Txn CF as a user, test retrieval of Txn CF via REST API

diff --git a/xt/transaction-customfields.t b/xt/transaction-customfields.t
index 93c5650..9851bd5 100644
--- a/xt/transaction-customfields.t
+++ b/xt/transaction-customfields.t
@@ -71,4 +71,95 @@ is( $res->code, 200, 'Fetched ticket via REST2 API');
 
 =cut
 
+# Test as a user.
+my $user = RT::Extension::REST2::Test->user;
+
+$user->PrincipalObj->GrantRight( Right => 'CreateTicket' );
+$user->PrincipalObj->GrantRight( Right => 'ModifyTicket' );
+$user->PrincipalObj->GrantRight( Right => 'ReplyToTicket' );
+$user->PrincipalObj->GrantRight( Right => 'SeeQueue' );
+$user->PrincipalObj->GrantRight( Right => 'ShowTicket' );
+$user->PrincipalObj->GrantRight( Right => 'ShowTicketComments' );
+$user->PrincipalObj->GrantRight( Right => 'SeeCustomField' );
+$user->PrincipalObj->GrantRight( Right => 'ModifyCustomField' );
+
+my ($ticket_url, $ticket_id);
+{
+    my $payload = {
+        Subject => 'Ticket for CF test',
+        Queue   => 'General',
+        Content => 'Ticket for CF test content',
+    };
+
+    my $res = $mech->post_json("$rest_base_path/ticket",
+        $payload,
+        'Authorization' => $auth,
+    );
+    is($res->code, 201);
+    ok($ticket_url = $res->header('location'));
+    ok(($ticket_id) = $ticket_url =~ qr[/ticket/(\d+)]);
+
+    # We need the hypermedia URLs...
+    $res = $mech->get($ticket_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+
+    $payload = {
+        Subject => 'Add Txn with CF',
+        Content => 'Content',
+        ContentType => 'text/plain',
+        'TxnCustomFields' => {
+            'TxnCF' => 'Txn CustomField',
+         },
+    };
+
+    $res = $mech->post_json($mech->url_for_hypermedia('correspond'),
+        $payload,
+        'Authorization' => $auth,
+    );
+    is($res->code, 201);
+    my $response = $mech->json_response;
+
+
+    my $response_value = bag(
+        re(qr/Correspondence added|Message added/), 'Custom fields updated',
+    );
+
+    cmp_deeply($mech->json_response, $response_value, 'Response containts correct strings');
+}
+
+# Look for the Transaction with our CustomField set.
+{
+    my $res = $mech->get($ticket_url,
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+
+    $res = $mech->get($mech->url_for_hypermedia('history'),
+        '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);
+
+    # Check the correspond txn (0 = create, 1 = correspond)
+    my $txn = @{ $content->{items} }[1];
+
+    $res = $mech->get($txn->{_url},
+        'Authorization' => $auth,
+    );
+    is($res->code, 200);
+
+    $content = $mech->json_response;
+    like($content->{Data}, qr/^Add Txn with CF/);
+
+    cmp_deeply($content->{CustomFields}, { $cfid => ['Txn CustomField' ] }, 'Txn is set');
+}
+
 done_testing();

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


More information about the Bps-public-commit mailing list