diff options
author | Struan Donald <struan@exo.org.uk> | 2012-09-06 16:03:01 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-09-06 16:03:01 +0100 |
commit | 7e4606306a62eac2ace15322d361b7ad36bcbecf (patch) | |
tree | e56aa0b8d88614fc38198d719d546c8797d2ba22 | |
parent | d6b32e50c09b03218164fbe4590077516ef5b609 (diff) |
send out open311 fms standard updates unless in extended mode
-rw-r--r-- | perllib/Open311.pm | 12 | ||||
-rw-r--r-- | t/open311.t | 70 |
2 files changed, 63 insertions, 19 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm index 6d218131f..f40481c81 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -24,6 +24,7 @@ has always_send_latlong => ( is => 'ro', isa => 'Bool', default => 1 ); has send_notpinpointed => ( is => 'ro', isa => 'Bool', default => 0 ); has basic_description => ( is => 'ro', isa => 'Bool', default => 0 ); has use_service_as_deviceid => ( is => 'ro', isa => 'Bool', default => 0 ); +has use_extended_updates => ( is => 'ro', isa => 'Bool', default => 0 ); before [ qw/get_service_list get_service_meta_info get_service_requests get_service_request_updates @@ -275,18 +276,23 @@ sub _populate_service_request_update_params { my ( $firstname, $lastname ) = ( $name =~ /(\w+)\.?\s+(.+)/ ); my $params = { - update_id_ext => $comment->id, updated_datetime => DateTime::Format::W3CDTF->format_datetime($comment->confirmed_local->set_nanosecond(0)), service_request_id => $comment->problem->external_id, - service_request_id_ext => $comment->problem->id, status => $comment->problem->is_open ? 'OPEN' : 'CLOSED', email => $comment->user->email, description => $comment->text, - public_anonymity_required => $comment->anonymous ? 'TRUE' : 'FALSE', last_name => $lastname, first_name => $firstname, }; + if ( $self->use_extended_updates ) { + $params->{public_anonymity_required} = $comment->anonymous ? 'TRUE' : 'FALSE', + $params->{update_id_ext} = $comment->id; + $params->{service_request_id_ext} = $comment->problem->id; + } else { + $params->{update_id} = $comment->id; + } + if ( $comment->photo ) { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($comment->cobrand)->new(); my $email_base_url = $cobrand->base_url($comment->cobrand_data); diff --git a/t/open311.t b/t/open311.t index 835d8d8cb..35b91faec 100644 --- a/t/open311.t +++ b/t/open311.t @@ -206,6 +206,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>', 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'; @@ -236,42 +256,57 @@ foreach my $test ( { desc => 'comment with fixed state sends status of CLOSED', state => 'fixed', - anon => 0, status => 'CLOSED', }, { desc => 'comment with fixed - user state sends status of CLOSED', state => 'fixed - user', - anon => 0, status => 'CLOSED', }, { desc => 'comment with fixed - council state sends status of CLOSED', state => 'fixed - council', - anon => 0, status => 'CLOSED', }, { 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', }, { desc => 'comment with planned state sends status of OPEN', state => 'planned', - anon => 0, status => 'OPEN', }, { 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', }, @@ -286,10 +321,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>', 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'; }; } @@ -504,15 +538,19 @@ done_testing(); sub make_update_req { my $comment = shift; my $xml = shift; + my $extended = shift; - return make_req( - { - object => $comment, - xml => $xml, - method => 'post_service_request_update', - path => 'update.xml', - } - ); + my $params = { + object => $comment, + xml => $xml, + method => 'post_service_request_update', + path => 'update.xml', + }; + + if ( $extended ) { + $params->{ open311_conf } = { use_extended_updates => 1 }; + } + return make_req( $params ); } sub make_service_req { |