aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm6
-rw-r--r--perllib/Open311/PopulateServiceList.pm2
-rw-r--r--t/app/controller/report_new_open311.t87
-rw-r--r--t/open311/populate-service-list.t90
4 files changed, 78 insertions, 107 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index f9cbf1c44..c544f084a 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -97,7 +97,11 @@ sub category_display {
sub get_metadata_for_input {
my $self = shift;
my $id_field = $self->id_field;
- my @metadata = grep { $_->{code} !~ /^(easting|northing|closest_address|$id_field)$/ } @{$self->get_extra_fields};
+ my @metadata = @{$self->get_extra_fields};
+ # First, ones we always want to ignore (hard-coded, old system)
+ @metadata = grep { $_->{code} !~ /^(easting|northing|closest_address|$id_field)$/ } @metadata;
+ # Also ignore any we have with a 'server_set' automated attribute
+ @metadata = grep { !$_->{automated} || $_->{automated} ne 'server_set' } @metadata;
# Just in case the extra data is in an old parsed format
foreach (@metadata) {
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index af89e3169..30d888eb4 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -267,8 +267,6 @@ sub _add_meta_to_contact {
@meta = grep { ! $ignore{ $_->{ code } } } @meta;
}
- @meta = grep { !defined $_->{automated} || $_->{ automated } eq 'hidden_field' } @meta;
-
$contact->set_extra_fields(@meta);
$contact->update;
}
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index d79f7883c..58644eabb 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -39,28 +39,42 @@ my $contact2 = $mech->create_contact_ok(
category => 'Graffiti Removal',
email => '101',
);
+$mech->create_contact_ok(
+ body_id => $body->id, # Edinburgh
+ category => 'Ball lighting',
+ email => '102',
+ extra => { _fields => [
+ { description => 'Size', code => 'size', required => 'True', automated => '' },
+ { description => 'Speed', code => 'speed', required => 'True', automated => 'server_set' },
+ { description => 'Colour', code => 'colour', required => 'True', automated => 'hidden_field' },
+ ] },
+);
# test that the various bit of form get filled in and errors correctly
# generated.
+my $empty_form = {
+ title => '',
+ detail => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ name => '',
+ may_show_name => '1',
+ username => '',
+ email => '',
+ phone => '',
+ category => '',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+};
foreach my $test (
{
msg => 'all fields empty',
pc => 'EH99 1SP',
fields => {
- title => '',
- detail => '',
- photo1 => '',
- photo2 => '',
- photo3 => '',
- name => '',
- may_show_name => '1',
- username => '',
- email => '',
- phone => '',
- category => 'Street lighting',
- password_sign_in => '',
- password_register => '',
- remember_me => undef,
+ %$empty_form,
+ category => 'Street lighting',
},
changes => {
number => '',
@@ -95,6 +109,45 @@ foreach my $test (
}
]
},
+ {
+ msg => 'automated things',
+ pc => 'EH99 1SP',
+ fields => {
+ %$empty_form,
+ category => 'Ball lighting',
+ },
+ changes => {
+ size => '',
+ },
+ hidden => [ 'colour' ],
+ errors => [
+ 'This information is required',
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ submit_with => {
+ title => 'test',
+ detail => 'test detail',
+ name => 'Test User',
+ username => 'testopen311@example.com',
+ size => 'big',
+ colour => 'red',
+ },
+ extra => [
+ {
+ name => 'size',
+ value => 'big',
+ description => 'Size',
+ },
+ {
+ name => 'colour',
+ value => 'red',
+ description => 'Colour',
+ }
+ ]
+ },
)
{
subtest "check form errors where $test->{msg}" => sub {
@@ -140,6 +193,12 @@ foreach my $test (
};
is_deeply $mech->visible_form_values, $new_values,
"values correctly changed";
+ if ($test->{hidden}) {
+ my %hidden_fields = map { $_->name => 1 } grep { $_->type eq 'hidden' } ($mech->forms)[0]->inputs;
+ foreach (@{$test->{hidden}}) {
+ is $hidden_fields{$_}, 1;
+ }
+ }
if ( $test->{fields}->{category} eq 'Street lighting' ) {
my $result = scraper {
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 149fb4b2a..7d4f491c6 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -646,96 +646,6 @@ subtest 'check bromely skip code' => sub {
is_deeply $contact->get_extra_fields, $extra, 'all meta data saved for non bromley';
};
-subtest 'check automated meta skip code' => 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>type</code>
- <datatype>string</datatype>
- <required>true</required>
- <datatype_description>Type of bin</datatype_description>
- <order>1</order>
- <description>Type of bin</description>
- </attribute>
- <attribute>
- <automated>server_set</automated>
- <variable>true</variable>
- <code>title</code>
- <datatype>string</datatype>
- <required>true</required>
- <datatype_description>Type of bin</datatype_description>
- <order>1</order>
- <description>Type of bin</description>
- </attribute>
- <attribute>
- <automated>hidden_field</automated>
- <variable>true</variable>
- <code>asset_id</code>
- <datatype>string</datatype>
- <required>true</required>
- <datatype_description>Id of bin</datatype_description>
- <order>1</order>
- <description>Id of bin</description>
- </attribute>
- </attributes>
-</service_definition>
- ';
-
- my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create(
- {
- body_id => 1,
- email => '001',
- category => 'Bins left out 24x7',
- 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 );
- $processor->_current_body( $body );
- $processor->_current_service( { service_code => 100 } );
-
- $processor->_add_meta_to_contact( $contact );
-
- my $extra = [ {
- variable => 'true',
- code => 'type',
- datatype => 'string',
- required => 'true',
- datatype_description => 'Type of bin',
- order => 1,
- description => 'Type of bin'
- },
- {
- automated => 'hidden_field',
- variable => 'true',
- code => 'asset_id',
- datatype => 'string',
- required => 'true',
- datatype_description => 'Id of bin',
- order => 1,
- description => 'Id of bin'
- } ];
-
- $contact->discard_changes;
-
- is_deeply $contact->get_extra_fields, $extra, 'only hidden automated meta data saved';
-};
-
sub get_standard_xml {
return qq{<?xml version="1.0" encoding="utf-8"?>
<services>