1#!/usr/bin/perl -w
2
3# to run:
4# RT_DBA_USER=root RT_DBA_PASSWORD= prove -lv -I/opt/rt3/lib t/bogus-rt-data.t
5use strict;
6
7use Prophet::Test;
8
9BEGIN {
10    unless (eval 'use RT::Test tests => "no_declare"; 1') {
11        diag $@ if $ENV{'TEST_VERBOSE'};
12        plan skip_all => 'requires RT 3.8 or newer to run tests.';
13    }
14}
15
16plan tests => 6;
17use App::SD::Test;
18
19no warnings 'once';
20
21RT::Handle->InsertData( $RT::EtcPath . '/initialdata' );
22use Prophet::Test;
23
24BEGIN {
25    require File::Temp;
26    $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'}
27        = File::Temp::tempdir( CLEANUP => 1 ) . '/_svb';
28    diag "export SD_REPO=" . $ENV{'PROPHET_REPO'} . "\n";
29}
30
31my $IMAGE_FILE = qw|t/data/bplogo.gif|;
32
33$RT::Test::SKIP_REQUEST_WORK_AROUND = 1;
34
35
36diag("This test file makes sure that when someone has messed with RT's internal history, prophet doesn't explode");
37
38my ( $url, $m ) = RT::Test->started_ok;
39
40use RT::Client::REST;
41use RT::Client::REST::Ticket;
42my $rt = RT::Client::REST->new( server => $url );
43$rt->login( username => 'root', password => 'password' );
44
45$url =~ s|http://|http://root:password@|;
46my $sd_rt_url = "rt:$url|General|Status!='resolved'";
47
48my $ticket = RT::Client::REST::Ticket->new(
49    rt      => $rt,
50    queue   => 'General',
51    status  => 'new',
52    subject => 'Fly Man',
53)->store( text => "Ticket Comment" );
54
55my $flyman_rt_id = $ticket->id;
56
57my ( $ret, $out, $err );
58( $ret, $out, $err )
59    = run_script( 'sd',
60        [ 'clone', '--from', $sd_rt_url, '--non-interactive' ] );
61my ( $flyman_id );
62run_output_matches(
63    'sd',
64    [ 'ticket', 'list', '--regex', '.' ],
65    [qr/(.*?)(?{ $flyman_id = $1 }) Fly Man new/]
66);
67RT::Client::REST::Ticket->new( rt     => $rt, id     => $ticket->id, status => 'open',)->store();
68diag("AB");
69( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
70
71run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], ["$flyman_id Fly Man open"]);
72
73# create from sd and push
74
75( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] );
76diag($out);
77diag($err);
78( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
79diag("DE");
80diag("FE");
81RT::Client::REST::Ticket->new( rt     => $rt, id     => $ticket->id, status => 'stalled',)->store();
82
83( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
84diag("XE");
85run_output_matches_unordered(
86    'sd',
87    [ 'ticket',              'list', '--regex', '.' ],
88    [ "$flyman_id Fly Man stalled", ]
89);
90
91$RT::Handle->dbh->do("UPDATE Tickets SET Status = 'rejected' WHERE id = ".$ticket->id);
92RT::Client::REST::Ticket->new( rt     => $rt, id     => $ticket->id, status => 'open',)->store();
93
94( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url, '--prefer', 'from' ] );
95ok( $ret, $out );
96run_output_matches_unordered(
97    'sd',
98    [ 'ticket',              'list', '--regex', '.' ],
99    [ "$flyman_id Fly Man open", ]
100);
1011;
102
103