fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / ticket_seen.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test nodata => 1, tests => 23, config => 'Set($ShowUnreadMessageNotifications, 1);';
6
7 my $queue = RT::Test->load_or_create_queue( Name => 'Regression' );
8 ok $queue && $queue->id, 'loaded or created queue';
9
10 my $user_a = RT::Test->load_or_create_user(
11     Name => 'user_a', Password => 'password',
12 );
13 ok $user_a && $user_a->id, 'loaded or created user';
14
15 my $user_b = RT::Test->load_or_create_user(
16     Name => 'user_b', Password => 'password',
17 );
18 ok $user_b && $user_b->id, 'loaded or created user';
19
20 ok( RT::Test->set_rights(
21     { Principal => $user_a, Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket ModifyTicket)] },
22     { Principal => $user_b, Right => [qw(SeeQueue ShowTicket ReplyToTicket)] },
23 ), 'set rights');
24 RT::Test->started_ok;
25
26 my $agent_a = RT::Test::Web->new;
27 ok $agent_a->login('user_a', 'password'), 'logged in as user A';
28
29 my $agent_b = RT::Test::Web->new;
30 ok $agent_b->login('user_b', 'password'), 'logged in as user B';
31
32 diag "create a ticket for testing";
33 my $tid;
34 {
35     my $ticket = RT::Ticket->new( $user_a );
36     my ($txn, $msg);
37     ($tid, $txn, $msg) = $ticket->Create(
38         Queue => $queue->id,
39         Owner => $user_a->id,
40         Subject => 'test',
41     );
42     ok $tid, 'created a ticket #'. $tid or diag "error: $msg";
43     is $ticket->Owner, $user_a->id, 'correct owner';
44 }
45
46 diag "user B adds a message, we check that user A see notification and can clear it";
47 {
48     my $ticket = RT::Ticket->new( $user_b );
49     $ticket->Load( $tid );
50     ok $ticket->id, 'loaded the ticket';
51
52     my ($status, $msg) = $ticket->Correspond( Content => 'bla-bla' );
53     ok $status, 'added reply' or diag "error: $msg";
54     my $txns = $ticket->Transactions;
55     $txns->Limit(
56         FIELD           => 'Type',
57         VALUE           => "Correspond",
58     );
59     my $txn = $txns->Last;
60     my $reply_id = $txn->id;
61     ok( $reply_id, 'got correspond txn id' );
62
63     $agent_a->goto_ticket($tid);
64     $agent_a->content_contains('bla-bla', 'the message on the page');
65
66     $agent_a->content_contains(
67         'unread message',
68         'we have not seen something'
69     );
70
71     $agent_a->follow_link_ok(
72         { text => 'jump to the first unread message' },
73         'try to jump to first unread message'
74     );
75     like( $agent_a->base, qr/#txn-$reply_id$/, 'contains anchor' );
76
77     $agent_a->follow_link_ok({text => 'jump to the first unread message and mark all messages as seen'}, 'try to mark all as seen');
78     $agent_a->content_contains(
79         'Marked all messages as seen',
80         'see success message'
81     );
82     like( $agent_a->base, qr/#txn-$reply_id$/, 'contains anchor' );
83
84     $agent_a->content_contains(
85         'Marked all messages as seen',
86         'see success message'
87     );
88
89     $agent_a->goto_ticket($tid);
90     $agent_a->content_lacks(
91         'unread message',
92         'we have seen everything, so no messages'
93     );
94 }
95