diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-03-12 16:18:17 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-03-12 16:18:17 +0000 |
commit | 4c1a483e4baa821c7d7b75e1bcef293ab13919ed (patch) | |
tree | 0d0994dc4ffa9b45d7dcec2d2ec40dd2e5449abd | |
parent | 2af88a4986b5fc951bdef0586f487735789d36d8 (diff) | |
parent | 435d15a06bd845bbcadc603b5a9a7ca88b7b403d (diff) |
Merge branch 'open311-hook-update-params'
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 1 | ||||
-rw-r--r-- | perllib/Open311.pm | 12 | ||||
-rwxr-xr-x | perllib/Open311/PostServiceRequestUpdates.pm | 1 | ||||
-rw-r--r-- | t/app/sendreport/open311.t | 1 | ||||
-rw-r--r-- | t/open311.t | 62 | ||||
-rw-r--r-- | t/open311/post-service-request-updates.t | 11 |
7 files changed, 59 insertions, 38 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 69aad01c8..341fb6a30 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -223,7 +223,6 @@ sub open311_config { sub open311_config_updates { my ($self, $params) = @_; - $params->{use_extended_updates} = 1; $params->{endpoints} = { service_request_updates => 'update.xml', update => 'update.xml' @@ -240,6 +239,14 @@ sub open311_pre_send { } } +sub open311_munge_update_params { + my ($self, $params, $comment, $body) = @_; + delete $params->{update_id}; + $params->{public_anonymity_required} = $comment->anonymous ? 'TRUE' : 'FALSE', + $params->{update_id_ext} = $comment->id; + $params->{service_request_id_ext} = $comment->problem->id; +} + sub open311_contact_meta_override { my ($self, $service, $contact, $meta) = @_; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index ed71d153b..a661ff206 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -29,6 +29,7 @@ sub send { use_service_as_deviceid => 0, extended_description => 1, multi_photos => 0, + fixmystreet_body => $body, ); my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged; diff --git a/perllib/Open311.pm b/perllib/Open311.pm index c0e27f96b..749e7ccad 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -29,12 +29,12 @@ has always_send_latlong => ( is => 'ro', isa => Bool, default => 1 ); has send_notpinpointed => ( is => 'ro', isa => Bool, default => 0 ); has extended_description => ( is => 'ro', isa => Str, default => 1 ); has use_service_as_deviceid => ( is => 'ro', isa => Bool, default => 0 ); -has use_extended_updates => ( is => 'ro', isa => Bool, default => 0 ); has extended_statuses => ( is => 'ro', isa => Bool, default => 0 ); has always_send_email => ( is => 'ro', isa => Bool, default => 0 ); has multi_photos => ( is => 'ro', isa => Bool, default => 0 ); has use_customer_reference => ( is => 'ro', isa => Bool, default => 0 ); has mark_reopen => ( is => 'ro', isa => Bool, default => 0 ); +has fixmystreet_body => ( is => 'ro', isa => InstanceOf['FixMyStreet::DB::Result::Body'] ); before [ qw/get_service_list get_service_meta_info get_service_requests get_service_request_updates @@ -387,14 +387,10 @@ sub _populate_service_request_update_params { $params->{phone} = $comment->user->phone if $comment->user->phone; $params->{email} = $comment->user->email if $comment->user->email; + $params->{update_id} = $comment->id; - 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; - } + my $cobrand = $self->fixmystreet_body->get_cobrand_handler || $comment->get_cobrand_logged; + $cobrand->call_hook(open311_munge_update_params => $params, $comment, $self->fixmystreet_body); if ( $comment->photo ) { my $cobrand = $comment->get_cobrand_logged; diff --git a/perllib/Open311/PostServiceRequestUpdates.pm b/perllib/Open311/PostServiceRequestUpdates.pm index c8ff2130f..1f080b168 100755 --- a/perllib/Open311/PostServiceRequestUpdates.pm +++ b/perllib/Open311/PostServiceRequestUpdates.pm @@ -38,6 +38,7 @@ sub open311_params { jurisdiction => $body->jurisdiction, api_key => $body->api_key, extended_statuses => $body->send_extended_statuses, + fixmystreet_body => $body, ); my $cobrand = $body->get_cobrand_handler; diff --git a/t/app/sendreport/open311.t b/t/app/sendreport/open311.t index df2166ab4..54aaa39d0 100644 --- a/t/app/sendreport/open311.t +++ b/t/app/sendreport/open311.t @@ -14,7 +14,6 @@ sub test_overrides; # defined below use constant TEST_USER_EMAIL => 'fred@example.com'; my %standard_open311_parameters = ( - 'use_extended_updates' => 0, 'send_notpinpointed' => 0, 'extended_description' => 1, 'use_service_as_deviceid' => 0, diff --git a/t/open311.t b/t/open311.t index f2fdefda6..85176ff0d 100644 --- a/t/open311.t +++ b/t/open311.t @@ -70,6 +70,8 @@ my $problem = FixMyStreet::DB->resultset('Problem')->new( { cobrand => 'fixmystreet', } ); +my $bromley = FixMyStreet::DB->resultset('Body')->new({ name => 'Bromley' }); + subtest 'posting service request' => sub { my $extra = { url => 'http://example.com/report/1', @@ -277,18 +279,23 @@ subtest 'test always_send_email' => sub { $user->email($email); }; -my $comment = FixMyStreet::DB->resultset('Comment')->new( { - id => 38362, - user => $user, - problem => $problem, - anonymous => 0, - text => 'this is a comment', - confirmed => $dt, - problem_state => 'confirmed', - extra => { title => 'Mr', email_alerts_requested => 0 }, -} ); +sub make_comment { + my $cobrand = shift; + FixMyStreet::DB->resultset('Comment')->new( { + id => 38362, + user => $user, + problem => $problem, + anonymous => 0, + text => 'this is a comment', + confirmed => $dt, + problem_state => 'confirmed', + cobrand => $cobrand || 'default', + extra => { title => 'Mr', email_alerts_requested => 0 }, + } ); +} subtest 'basic request update post parameters' => sub { + my $comment = make_comment(); 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>' ); is $results->{ res }, 248, 'got update id'; @@ -307,7 +314,13 @@ subtest 'basic request update post parameters' => sub { }; 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>', { use_extended_updates => 1 } ); + my $comment = make_comment('bromley'); + my $results; + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'bromley', + }, 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'; @@ -333,8 +346,8 @@ subtest 'check media url set' => sub { my $image_path = path('t/app/controller/sample.jpg'); $image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) ); + my $comment = make_comment('fixmystreet'); $comment->photo("0123456789012345678901234567890123456789"); - $comment->cobrand('fixmystreet'); FixMyStreet::override_config { PHOTO_STORAGE_BACKEND => 'FileSystem', @@ -350,7 +363,6 @@ subtest 'check media url set' => sub { my $expected_path = '/c/' . $comment->id . '.0.full.jpeg'; like $c->param('media_url'), qr/$expected_path/, 'image url included'; }; - $comment->photo(undef); }; foreach my $test ( @@ -447,6 +459,7 @@ foreach my $test ( }, ) { subtest $test->{desc} => sub { + my $comment = make_comment(); $comment->problem_state( $test->{state} ); $comment->problem->state( $test->{state} ); $comment->mark_open(1) if $test->{mark_open}; @@ -481,11 +494,17 @@ for my $test ( }, ) { subtest $test->{desc} => sub { + my $comment = make_comment('bromley'); $comment->problem_state( $test->{state} ); $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>', { use_extended_updates => 1 } ); + my $results; + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'bromley', + }, 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>' ); + }; my $c = CGI::Simple->new( $results->{ req }->content ); is $c->param('public_anonymity_required'), $test->{anon} ? 'TRUE' : 'FALSE', 'correct anonymity'; @@ -495,17 +514,6 @@ for my $test ( my $dt2 = $dt->clone; $dt2->add( 'minutes' => 1 ); -my $comment2 = FixMyStreet::DB->resultset('Comment')->new( { - id => 38363, - user => $user, - problem => $problem, - anonymous => 0, - text => 'this is a comment', - confirmed => $dt, - problem_state => 'confirmed', - extra => { title => 'Mr', email_alerts_requested => 0 }, -} ); - for my $test ( { desc => 'comment with fixed - council state sends status of CLOSED even if problem is open', @@ -530,6 +538,7 @@ for my $test ( }, ) { subtest $test->{desc} => sub { + my $comment = make_comment(); $comment->problem_state( $test->{state} ); $comment->problem->state( $test->{problem_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>' ); @@ -574,6 +583,7 @@ for my $test ( ) { subtest $test->{desc} => sub { + my $comment = make_comment(); $comment->name( $test->{comment_name} ); $user->name( $test->{user_name} ); $comment->extra( $test->{ extra } ); @@ -662,6 +672,7 @@ for my $test ( } $problem->send_fail_count(1); +my $comment = make_comment(); $comment->send_fail_count(1); subtest 'No request id in reponse' => sub { @@ -827,6 +838,7 @@ sub _make_req { $open311_conf{'test_mode'} = 1; $open311_conf{'end_point'} = 'http://localhost/o311'; + $open311_conf{fixmystreet_body} = $bromley; my $o = Open311->new( %open311_conf ); diff --git a/t/open311/post-service-request-updates.t b/t/open311/post-service-request-updates.t index 901181501..57b8f9a2a 100644 --- a/t/open311/post-service-request-updates.t +++ b/t/open311/post-service-request-updates.t @@ -34,21 +34,26 @@ subtest 'Check Open311 params' => sub { is_deeply \%conf, { %$result, extended_statuses => 1, - use_extended_updates => 1, endpoints => { service_request_updates => 'update.xml', update => 'update.xml' }, + fixmystreet_body => $bromley, }, 'Bromley params match'; %conf = $o->open311_params($oxon); is_deeply \%conf, { %$result, - use_customer_reference => 1 + use_customer_reference => 1, + fixmystreet_body => $oxon, }, 'Oxfordshire params match'; %conf = $o->open311_params($bucks); is_deeply \%conf, { %$result, mark_reopen => 1, + fixmystreet_body => $bucks, }, 'Bucks params match'; %conf = $o->open311_params($lewisham); - is_deeply \%conf, $result, 'Lewisham params match'; + is_deeply \%conf, { + %$result, + fixmystreet_body => $lewisham, + }, 'Lewisham params match'; }; }; |