diff options
Diffstat (limited to 't/open311.t')
-rw-r--r-- | t/open311.t | 96 |
1 files changed, 90 insertions, 6 deletions
diff --git a/t/open311.t b/t/open311.t index 85176ff0d..9524006b8 100644 --- a/t/open311.t +++ b/t/open311.t @@ -263,6 +263,36 @@ for my $test ( }; } +for my $test ( + { + desc => 'account_id handled correctly when present', + account_id => '1c304134-ef12-c128-9212-123908123901', + }, + { + desc => 'account_id handled correctly when 0', + account_id => '0' + }, + { + desc => 'account_id handled correctly when missing', + account_id => undef + } +) { + subtest $test->{desc} => sub { + $problem->extra( undef ); + my $extra = { + url => 'http://example.com/report/1', + defined $test->{account_id} ? ( account_id => $test->{account_id} ) : () + }; + + my $results = make_service_req( $problem, $extra, $problem->category, +'<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' + ); + my $c = CGI::Simple->new( $results->{req}->content ); + + is $c->param( 'account_id' ), $test->{account_id}, 'correct account_id'; + }; +} + subtest 'test always_send_email' => sub { my $email = $user->email; $user->email(undef); @@ -302,14 +332,14 @@ subtest 'basic request update post parameters' => sub { my $c = CGI::Simple->new( $results->{ req }->content ); - is $c->param('description'), 'this is a comment', 'email correct'; + is $c->param('description'), 'this is a comment', 'description correct'; is $c->param('email'), 'test@example.com', 'email correct'; is $c->param('status'), 'OPEN', 'status correct'; is $c->param('service_request_id'), 81, 'request id correct'; is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date'; is $c->param('title'), 'Mr', 'correct title'; - is $c->param('last_name'), 'User', 'correct first name'; - is $c->param('first_name'), 'Test', 'correct second name'; + is $c->param('first_name'), 'Test', 'correct first name'; + is $c->param('last_name'), 'User', 'correct second name'; is $c->param('media_url'), undef, 'no media url'; }; @@ -326,7 +356,7 @@ subtest 'extended request update post parameters' => sub { my $c = CGI::Simple->new( $results->{ req }->content ); - is $c->param('description'), 'this is a comment', 'email correct'; + is $c->param('description'), 'this is a comment', 'description correct'; is $c->param('email'), 'test@example.com', 'email correct'; is $c->param('status'), 'OPEN', 'status correct'; is $c->param('service_request_id_ext'), 80, 'external request id correct'; @@ -334,12 +364,66 @@ subtest 'extended request update post parameters' => sub { is $c->param('public_anonymity_required'), 'FALSE', 'anon status correct'; is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date'; is $c->param('title'), 'Mr', 'correct title'; - is $c->param('last_name'), 'User', 'correct first name'; - is $c->param('first_name'), 'Test', 'correct second name'; + is $c->param('first_name'), 'Test', 'correct first name'; + is $c->param('last_name'), 'User', 'correct second name'; is $c->param('email_alerts_requested'), 'FALSE', 'email alerts flag correct'; is $c->param('media_url'), undef, 'no media url'; }; +subtest 'Hounslow update description is correct for same user' => sub { + my $comment = make_comment('hounslow'); + my $results; + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'hounslow', + }, sub { + $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); + }; + + is $results->{ res }, 248, 'got update id'; + + my $c = CGI::Simple->new( $results->{ req }->content ); + + is $c->param('description'), 'this is a comment', 'description correct'; + is $c->param('email'), 'test@example.com', 'email correct'; + is $c->param('status'), 'OPEN', 'status correct'; + is $c->param('service_request_id'), 81, 'request id correct'; + is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date'; + is $c->param('title'), 'Mr', 'correct title'; + is $c->param('first_name'), 'Test', 'correct first name'; + is $c->param('last_name'), 'User', 'correct second name'; + is $c->param('media_url'), undef, 'no media url'; +}; + +subtest 'Hounslow update description is correct for a different user' => sub { + my $user2 = FixMyStreet::DB->resultset('User')->new( { + name => 'Another User', + email => 'another@example.org', + } ); + + my $comment = make_comment('hounslow'); + $comment->user($user2); + my $results; + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'hounslow', + }, sub { + $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); + }; + + is $results->{ res }, 248, 'got update id'; + + my $c = CGI::Simple->new( $results->{ req }->content ); + + is $c->param('description'), "[This comment was not left by the original problem reporter] this is a comment", 'description correct'; + is $c->param('email'), 'another@example.org', 'email correct'; + is $c->param('status'), 'OPEN', 'status correct'; + is $c->param('service_request_id'), 81, 'request id correct'; + is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date'; + is $c->param('title'), 'Mr', 'correct title'; + is $c->param('first_name'), 'Another', 'correct first name'; + is $c->param('last_name'), 'User', 'correct second name'; + is $c->param('media_url'), undef, 'no media url'; +}; + subtest 'check media url set' => sub { my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); |