aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311.t
diff options
context:
space:
mode:
Diffstat (limited to 't/open311.t')
-rw-r--r--t/open311.t79
1 files changed, 57 insertions, 22 deletions
diff --git a/t/open311.t b/t/open311.t
index f9315982d..4c451d55e 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -37,9 +37,10 @@ my $p = FixMyStreet::App->model('DB::Problem')->new( {
title => 'title',
detail => 'detail',
user => $u,
+ id => 1,
} );
-my $expected_error = qr{.*request failed: 500 Can.t connect to 192.168.50.1:80 \([^)]*\).*};
+my $expected_error = qr{Failed to submit problem 1 over Open311}ism;
warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 )} $expected_error, 'warning generated on failed call';
@@ -105,7 +106,7 @@ subtest 'posting service request with basic_description' => sub {
$extra,
$problem->category,
'<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>',
- { basic_description => 1 },
+ { extended_description => 0 },
);
is $results->{ res }, 248, 'got request id';
@@ -207,6 +208,26 @@ subtest 'basic request update post parameters' => sub {
is $c->param('description'), 'this is a comment', 'email 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('media_url'), undef, 'no media url';
+};
+
+subtest 'extended request update post parameters' => sub {
+ my $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>', { extended_updates => 1 } );
+
+ is $results->{ res }, 248, 'got update id';
+
+ my $req = $o->test_req_used;
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+
+ is $c->param('description'), 'this is a comment', 'email 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';
is $c->param('service_request_id'), 81, 'request id correct';
is $c->param('public_anonymity_required'), 'FALSE', 'anon status correct';
@@ -237,21 +258,18 @@ foreach my $test (
{
desc => 'comment with fixed state sends status of CLOSED',
state => 'fixed',
- anon => 0,
status => 'CLOSED',
extended => 'FIXED',
},
{
desc => 'comment with fixed - user state sends status of CLOSED',
state => 'fixed - user',
- anon => 0,
status => 'CLOSED',
extended => 'FIXED',
},
{
desc => 'comment with fixed - council state sends status of CLOSED',
state => 'fixed - council',
- anon => 0,
status => 'CLOSED',
extended => 'FIXED',
},
@@ -279,20 +297,17 @@ foreach my $test (
{
desc => 'comment with closed state sends status of CLOSED',
state => 'closed',
- anon => 0,
status => 'CLOSED',
},
{
desc => 'comment with investigating state sends status of OPEN',
state => 'investigating',
- anon => 0,
status => 'OPEN',
extended => 'INVESTIGATING',
},
{
desc => 'comment with planned state sends status of OPEN',
state => 'planned',
- anon => 0,
status => 'OPEN',
extended => 'ACTION_SCHEDULED',
},
@@ -306,6 +321,27 @@ foreach my $test (
{
desc => 'comment with in progress state sends status of OPEN',
state => 'in progress',
+ status => 'OPEN',
+ },
+ {
+ state => 'confirmed',
+ status => 'OPEN',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $comment->problem->state( $test->{state} );
+
+ my $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>' );
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+ is $c->param('status'), $test->{status}, 'correct status';
+ };
+}
+
+for my $test (
+ {
+ desc => 'public comment sets public_anonymity_required to false',
+ state => 'confirmed',
anon => 0,
status => 'OPEN',
extended => 'IN_PROGRESS',
@@ -322,10 +358,9 @@ foreach my $test (
$comment->problem->state( $test->{state} );
$comment->anonymous( $test->{anon} );
- my $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>' );
+ my $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>', { extended_updates => 1 } );
my $c = CGI::Simple->new( $results->{ req }->content );
- is $c->param('status'), $test->{status}, 'correct status';
is $c->param('public_anonymity_required'), $test->{anon} ? 'TRUE' : 'FALSE', 'correct anonymity';
if ( $test->{extended} ) {
@@ -597,19 +632,19 @@ for my $test (
done_testing();
sub make_update_req {
- my $comment = shift;
- my $xml = shift;
- my $open311_args = shift || {};
+ my $comment = shift;
+ my $xml = shift;
+ my $open311conf = shift || {};
+
+ my $params = {
+ object => $comment,
+ xml => $xml,
+ method => 'post_service_request_update',
+ path => 'servicerequestupdates.xml',
+ open311_conf => $open311_args,
+ };
- return make_req(
- {
- object => $comment,
- xml => $xml,
- method => 'post_service_request_update',
- path => 'update.xml',
- open311_conf => $open311_args,
- }
- );
+ return make_req( $params );
}
sub make_service_req {