fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / rest-search-queue.t
1 use strict;
2 use warnings;
3 use RT::Test tests => undef;
4
5 my $queue_foo = RT::Test->load_or_create_queue( Name => 'Foo' );
6 my $queue_bar = RT::Test->load_or_create_queue( Name => 'Bar' );
7 my $queue_baz = RT::Test->load_or_create_queue( Name => 'Baz' );
8 $queue_baz->SetDisabled(1);
9
10 my ( $baseurl, $m ) = RT::Test->started_ok;
11
12 ok( $m->login, 'logged in' );
13
14 search_queues_ok( { query => 'id = 1' }, ['1: General'], 'search id = 1' );
15 search_queues_ok(
16     {
17         query  => 'Name = General',
18         format => 's',
19         fields => 'id,name,description'
20     },
21     [ "id\tName\tDescription", "1\tGeneral\tThe default queue" ],
22     'search by name with customized fields'
23 );
24
25 search_queues_ok(
26     { query => 'id > 10' },
27     ['No matching results.'],
28     'no matching results'
29 );
30
31 search_queues_ok(
32     { query => 'foo = 3' },
33     ['Invalid field specification: foo'],
34     'invalid field'
35 );
36
37 search_queues_ok(
38     { query => 'id foo 3' },
39     ['Invalid operator specification: foo'],
40     'invalid op'
41 );
42
43 search_queues_ok(
44     { query => '', orderby => 'id' },
45     [ '1: General', $queue_foo->id . ': Foo', $queue_bar->id . ': Bar', ],
46     'order by id'
47 );
48
49 search_queues_ok(
50     { query => '', orderby => 'name' },
51     [ $queue_bar->id . ': Bar', $queue_foo->id . ': Foo', '1: General', ],
52     'order by name'
53 );
54
55 search_queues_ok(
56     { query => '', orderby => '+name' },
57     [ $queue_bar->id . ': Bar', $queue_foo->id . ': Foo', '1: General', ],
58     'order by +name'
59 );
60
61 search_queues_ok(
62     { query => '', orderby => '-name' },
63     [ '1: General', $queue_foo->id . ': Foo', $queue_bar->id . ': Bar', ],
64     'order by -name'
65 );
66
67 search_queues_ok(
68     { query => 'Disabled = 0', orderby => 'id' },
69     [ '1: General', $queue_foo->id . ': Foo', $queue_bar->id . ': Bar', ],
70     'enabled queues'
71 );
72
73 search_queues_ok(
74     { query => 'Disabled = 1', orderby => 'id' },
75     [ $queue_baz->id . ': Baz', ],
76     'disabled queues'
77 );
78
79 search_queues_ok(
80     { query => 'Disabled = 2', orderby => 'id' },
81     [ '2: ___Approvals', ],
82     'special Approvals queue'
83 );
84
85 sub search_queues_ok {
86     local $Test::Builder::Level = $Test::Builder::Level + 1;
87     my $query    = shift;
88     my $expected = shift;
89     my $name     = shift || 'search queues';
90
91     my $uri = URI->new("$baseurl/REST/1.0/search/queue");
92     $uri->query_form(%$query);
93     $m->get_ok($uri);
94
95     my @lines = split /\n/, $m->content;
96     shift @lines;    # header
97     shift @lines;    # empty line
98
99     is_deeply( \@lines, $expected, $name );
100
101 }
102
103 undef $m;
104 done_testing();