X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Ft%2Fweb%2Frest.t;h=8b8cbcb86f5e2194b781524331a0d7f5cbda31cc;hb=606acab48f55da2b8846e5539839d591b63ae18c;hp=b3a7c558b25b4cfa7849124cb9bf38ae1c24738c;hpb=63a268637b2d51a8766412617724b9436439deb6;p=freeside.git diff --git a/rt/t/web/rest.t b/rt/t/web/rest.t index b3a7c558b..8b8cbcb86 100644 --- a/rt/t/web/rest.t +++ b/rt/t/web/rest.t @@ -1,19 +1,28 @@ -#!/usr/bin/env perl use strict; use warnings; -use RT::Test tests => 16; +use RT::Interface::REST; + +use RT::Test tests => 34; my ($baseurl, $m) = RT::Test->started_ok; for my $name ("severity", "fu()n:k/") { my $cf = RT::Test->load_or_create_custom_field( Name => $name, - Type => 'Freeform', + Type => 'FreeformMultiple', Queue => 'General', ); ok($cf->Id, "created a CustomField"); is($cf->Name, $name, "correct CF name"); } +{ + my $cf = RT::Test->load_or_create_custom_field( + Name => 'single', + Type => 'FreeformSingle', + Queue => 'General', + ); + ok($cf->Id, "created a CustomField"); +} my $queue = RT::Test->load_or_create_queue(Name => 'General'); ok($queue->Id, "loaded the General queue"); @@ -46,7 +55,7 @@ $m->post("$baseurl/REST/1.0/ticket/edit", [ my ($id) = $m->content =~ /Ticket (\d+) created/; ok($id, "got ticket #$id"); -my $ticket = RT::Ticket->new($RT::SystemUser); +my $ticket = RT::Ticket->new(RT->SystemUser); $ticket->Load($id); is($ticket->Id, $id, "loaded the REST-created ticket"); is($ticket->Subject, "REST interface", "subject successfully set"); @@ -69,3 +78,250 @@ for ("id: ticket/1", $m->content_contains($_); } +# Create ticket 2 for testing ticket links +for (2 .. 3) { + $m->post("$baseurl/REST/1.0/ticket/edit", [ + user => 'root', + pass => 'password', + content => $text, + ], Content_Type => 'form-data'); + + $m->post( + "$baseurl/REST/1.0/ticket/1/links", + [ + user => 'root', + pass => 'password', + ], + Content_Type => 'form-data', + ); + + my $link_data = form_parse($m->content); + + push @{$link_data->[0]->[1]}, 'DependsOn'; + vpush($link_data->[0]->[2], 'DependsOn', $_); + + $m->post( + "$baseurl/REST/1.0/ticket/1/links", + [ + user => 'root', + pass => 'password', + content => form_compose($link_data), + ], + Content_Type => 'form-data', + ); + +} + +# See what links get reported for ticket 1. +$m->post( + "$baseurl/REST/1.0/ticket/1/links/show", + [ + user => 'root', + pass => 'password', + ], + Content_Type => 'form-data', +); + +# Verify that the link was added correctly. +my $content = form_parse($m->content); +my $depends_on = vsplit($content->[0]->[2]->{DependsOn}); +@$depends_on = sort @$depends_on; +like( + $depends_on->[0], qr{/ticket/2$}, + "Check ticket link.", +) or diag("'content' obtained:\n", $m->content); + +like( + $depends_on->[1], qr{/ticket/3$}, + "Check ticket link.", +) or diag("'content' obtained:\n", $m->content); + +$m->post( + "$baseurl/REST/1.0/ticket/2/links/show", + [ + user => 'root', + pass => 'password', + ], + Content_Type => 'form-data', +); +my ($link) = $m->content =~ m|DependedOnBy:.*ticket/(\d+)|; +is($link, 1, "Check ticket link.") or diag("'content' obtained:\n", $m->content); + +$m->post( + "$baseurl/REST/1.0/ticket/3/links/show", + [ + user => 'root', + pass => 'password', + ], + Content_Type => 'form-data', +); +($link) = $m->content =~ m|DependedOnBy:.*ticket/(\d+)|; +is($link, 1, "Check ticket link.") or diag("'content' obtained:\n", $m->content); + + +{ + $m->post("$baseurl/REST/1.0/ticket/new", [ + user => 'root', + pass => 'password', + format => 'l', + ]); + + my $text = $m->content; + my @lines = $text =~ m{.*}g; + shift @lines; # header + push @lines, "CF.{severity}: explosive"; + push @lines, "CF.{severity}: very"; + $text = join "\n", @lines; + + $m->post("$baseurl/REST/1.0/ticket/edit", [ + user => 'root', + pass => 'password', + + content => $text, + ], Content_Type => 'form-data'); + + my ($id) = $m->content =~ /Ticket (\d+) created/; + ok($id, "got ticket #$id"); + + my $ticket = RT::Ticket->new(RT->SystemUser); + $ticket->Load($id); + is($ticket->Id, $id, "loaded the REST-created ticket"); + is_deeply( + [sort map $_->Content, @{ $ticket->CustomFieldValues("severity")->ItemsArrayRef }], + ["explosive", "very"], + "CF successfully set" + ); + + $m->post( + "$baseurl/REST/1.0/ticket/show", + [ + user => 'root', + pass => 'password', + format => 'l', + id => "ticket/$id", + ] + ); + $text = $m->content; + $text =~ s/.*?\n\n//; + $text =~ s/\n\n/\n/; + $text =~ s{CF\.\{severity\}:.*\n}{}img; + $text .= "CF.{severity}: explosive, a bit\n"; + $m->post( + "$baseurl/REST/1.0/ticket/edit", + [ + user => 'root', + pass => 'password', + content => $text, + ], + Content_Type => 'form-data' + ); + $m->content =~ /Ticket ($id) updated/; + + $ticket->Load($id); + is_deeply( + [sort map $_->Content, @{ $ticket->CustomFieldValues("severity")->ItemsArrayRef }], + ['a bit', 'explosive'], + "CF successfully set" + ); + + $m->post( + "$baseurl/REST/1.0/ticket/show", + [ + user => 'root', + pass => 'password', + format => 'l', + id => "ticket/$id", + ] + ); + $text = $m->content; + $text =~ s{CF\.\{severity\}:.*\n}{}img; + $text .= "CF.{severity}:\n"; + $m->post( + "$baseurl/REST/1.0/ticket/edit", + [ + user => 'root', + pass => 'password', + content => $text, + ], + Content_Type => 'form-data' + ); + $m->content =~ /Ticket ($id) updated/; + + $ticket->Load($id); + is_deeply( + [sort map $_->Content, @{ $ticket->CustomFieldValues("severity")->ItemsArrayRef }], + [], + "CF successfully set" + ); + + my @txns = map [$_->OldValue, $_->NewValue], grep $_->Type eq 'CustomField', + @{ $ticket->Transactions->ItemsArrayRef }; + is_deeply(\@txns, [['very', undef], [undef, 'a bit'], ['explosive', undef], ['a bit', undef]]); +} + +{ + $m->post("$baseurl/REST/1.0/ticket/new", [ + user => 'root', + pass => 'password', + format => 'l', + ]); + + my $text = $m->content; + my @lines = $text =~ m{.*}g; + shift @lines; # header + push @lines, "CF.{single}: this"; + $text = join "\n", @lines; + + $m->post("$baseurl/REST/1.0/ticket/edit", [ + user => 'root', + pass => 'password', + + content => $text, + ], Content_Type => 'form-data'); + + my ($id) = $m->content =~ /Ticket (\d+) created/; + ok($id, "got ticket #$id"); + + my $ticket = RT::Ticket->new(RT->SystemUser); + $ticket->Load($id); + is($ticket->Id, $id, "loaded the REST-created ticket"); + is_deeply( + [sort map $_->Content, @{ $ticket->CustomFieldValues("single")->ItemsArrayRef }], + ["this"], + "CF successfully set" + ); + + $m->post( + "$baseurl/REST/1.0/ticket/show", + [ + user => 'root', + pass => 'password', + format => 'l', + id => "ticket/$id", + ] + ); + $text = $m->content; + $text =~ s{CF\.\{single\}:.*\n}{}img; + $text .= "CF.{single}: that\n"; + $m->post( + "$baseurl/REST/1.0/ticket/edit", + [ + user => 'root', + pass => 'password', + content => $text, + ], + Content_Type => 'form-data' + ); + $m->content =~ /Ticket ($id) updated/; + + $ticket->Load($id); + is_deeply( + [sort map $_->Content, @{ $ticket->CustomFieldValues("single")->ItemsArrayRef }], + ['that'], + "CF successfully set" + ); + + my @txns = map [$_->OldValue, $_->NewValue], grep $_->Type eq 'CustomField', + @{ $ticket->Transactions->ItemsArrayRef }; + is_deeply(\@txns, [['this', 'that']]); +}