aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2019-01-18 14:55:14 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2019-01-23 10:06:32 +0000
commitf44ad2f067346cb3b03d3711fd658a5516e9fd0c (patch)
tree1667dcb3f8ce0342e3b08a98c809555d9775e58b
parentbddeaa7f8b8f495879df99eb5a85828c862f071e (diff)
[Open311] Refactor cobrand specific code.
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm39
-rw-r--r--perllib/FixMyStreet/Cobrand/Warwickshire.pm8
-rw-r--r--perllib/Open311/PopulateServiceList.pm58
-rw-r--r--t/cobrand/warwickshire.t84
-rw-r--r--t/open311/populate-service-list.t6
5 files changed, 140 insertions, 55 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index 11c685c91..386e1a269 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -196,5 +196,44 @@ sub open311_pre_send {
}
}
+sub open311_contact_meta_override {
+ my ($self, $service, $contact, $meta) = @_;
+
+ $contact->set_extra_metadata( id_field => 'service_request_id_ext');
+
+ # Lights we want to store feature ID, PROW on all categories.
+ push @$meta, {
+ code => 'prow_reference',
+ datatype => 'string',
+ description => 'Right of way reference',
+ order => 101,
+ required => 'false',
+ variable => 'true',
+ automated => 'hidden_field',
+ };
+ push @$meta, {
+ code => 'feature_id',
+ datatype => 'string',
+ description => 'Feature ID',
+ order => 100,
+ required => 'false',
+ variable => 'true',
+ automated => 'hidden_field',
+ } if $service->{service_code} eq 'SLRS';
+
+ my @override = qw(
+ requested_datetime
+ report_url
+ title
+ last_name
+ email
+ report_title
+ public_anonymity_required
+ email_alerts_requested
+ );
+ my %ignore = map { $_ => 1 } @override;
+ @$meta = grep { !$ignore{$_->{code}} } @$meta;
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/Warwickshire.pm b/perllib/FixMyStreet/Cobrand/Warwickshire.pm
index 73f66f3da..c301450bc 100644
--- a/perllib/FixMyStreet/Cobrand/Warwickshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Warwickshire.pm
@@ -34,4 +34,12 @@ sub contact_name { 'Warwickshire County Council (do not reply)'; }
sub send_questionnaires { 0 }
+sub open311_contact_meta_override {
+ my ($self, $service, $contact, $meta) = @_;
+
+ $contact->set_extra_metadata( id_field => 'external_id');
+
+ @$meta = grep { $_->{code} ne 'closest_address' } @$meta;
+}
+
1;
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 0bbd902ed..d506111ec 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -233,65 +233,15 @@ sub _add_meta_to_contact {
# Some Open311 endpoints, such as Bromley and Warwickshire send <metadata>
# for attributes which we *don't* want to display to the user (e.g. as
- # fields in "category_extras"
- $self->_add_meta_to_contact_cobrand_overrides($contact, \@meta);
+ # fields in "category_extras"), or need additional attributes adding not
+ # returned by the server for whatever reason.
+ $self->_current_body_cobrand && $self->_current_body_cobrand->call_hook(
+ open311_contact_meta_override => $self->_current_service, $contact, \@meta);
$contact->set_extra_fields(@meta);
$contact->update;
}
-sub _add_meta_to_contact_cobrand_overrides {
- my ( $self, $contact, $meta ) = @_;
-
- if ($self->_current_body->name eq 'Bromley Council') {
- $contact->set_extra_metadata( id_field => 'service_request_id_ext');
- # Lights we want to store feature ID, PROW on all categories.
- push @$meta, {
- code => 'prow_reference',
- datatype => 'string',
- description => 'Right of way reference',
- order => 101,
- required => 'false',
- variable => 'true',
- automated => 'hidden_field',
- };
- push @$meta, {
- code => 'feature_id',
- datatype => 'string',
- description => 'Feature ID',
- order => 100,
- required => 'false',
- variable => 'true',
- automated => 'hidden_field',
- } if $self->_current_service->{service_code} eq 'SLRS';
- } elsif ($self->_current_body->name eq 'Warwickshire County Council') {
- $contact->set_extra_metadata( id_field => 'external_id');
- }
-
- my %override = (
- #2482
- 'Bromley Council' => [qw(
- requested_datetime
- report_url
- title
- last_name
- email
- report_title
- public_anonymity_required
- email_alerts_requested
- ) ],
- #2243,
- 'Warwickshire County Council' => [qw(
- closest_address
- ) ],
- );
-
- if (my $override = $override{ $self->_current_body->name }) {
- my %ignore = map { $_ => 1 } @{ $override };
- @$meta = grep { ! $ignore{ $_->{ code } } } @$meta;
- }
-}
-
sub _normalize_service_name {
my $self = shift;
diff --git a/t/cobrand/warwickshire.t b/t/cobrand/warwickshire.t
new file mode 100644
index 000000000..79c9f31e0
--- /dev/null
+++ b/t/cobrand/warwickshire.t
@@ -0,0 +1,84 @@
+#!/usr/bin/env perl
+
+use FixMyStreet::Test;
+use FixMyStreet::DB;
+
+use_ok( 'Open311::PopulateServiceList' );
+use_ok( 'Open311' );
+
+my $processor = Open311::PopulateServiceList->new();
+ok $processor, 'created object';
+
+my $warks = FixMyStreet::DB->resultset('Body')->create({
+ name => 'Warwickshire County Council',
+});
+$warks->body_areas->create({ area_id => 2243 });
+
+subtest 'check Warwickshire override' => sub {
+ my $processor = Open311::PopulateServiceList->new();
+
+ my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
+<service_definition>
+ <service_code>100</service_code>
+ <attributes>
+ <attribute>
+ <variable>true</variable>
+ <code>closest_address</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <order>1</order>
+ <description>Closest address</description>
+ </attribute>
+ <attribute>
+ <variable>true</variable>
+ <code>size</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <order>2</order>
+ <description>How big is the pothole</description>
+ </attribute>
+ </attributes>
+</service_definition>
+ ';
+
+ my $contact = FixMyStreet::DB->resultset('Contact')->create({
+ body_id => $warks->id,
+ email => '100',
+ category => 'Pothole',
+ state => 'confirmed',
+ editor => $0,
+ whenedited => \'current_timestamp',
+ note => 'test contact',
+ });
+
+ my $o = Open311->new(
+ jurisdiction => 'mysociety',
+ endpoint => 'http://example.com',
+ test_mode => 1,
+ test_get_returns => { 'services/100.xml' => $meta_xml }
+ );
+
+ $processor->_current_open311( $o );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'warwickshire' ],
+ }, sub {
+ $processor->_current_body( $warks );
+ };
+ $processor->_current_service( { service_code => 100, service_name => 'Pothole' } );
+ $processor->_add_meta_to_contact( $contact );
+
+ my $extra = [ {
+ variable => 'true',
+ code => 'size',
+ datatype => 'string',
+ required => 'true',
+ order => 2,
+ description => 'How big is the pothole',
+ } ];
+
+ $contact->discard_changes;
+ is_deeply $contact->get_extra_fields, $extra, 'No closest_address field returned for Warks';
+ is $contact->get_extra_metadata('id_field'), 'external_id', 'id_field set correctly';
+};
+
+done_testing();
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 1415c7b2a..340a91ac5 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -552,7 +552,11 @@ subtest 'check Bromley skip code' => sub {
);
$processor->_current_open311( $o );
- $processor->_current_body( $bromley );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'bromley' ],
+ }, sub {
+ $processor->_current_body( $bromley );
+ };
$processor->_current_service( { service_code => 100 } );
$processor->_add_meta_to_contact( $contact );