aboutsummaryrefslogtreecommitdiffstats
path: root/t/open311
diff options
context:
space:
mode:
Diffstat (limited to 't/open311')
-rw-r--r--t/open311/populate-service-list.t165
1 files changed, 165 insertions, 0 deletions
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index fbd729f3a..5910a8f13 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -269,6 +269,171 @@ subtest 'check meta data population' => sub {
is_deeply $contact->extra, $extra, 'meta data saved';
};
+for my $test (
+ {
+ desc => 'check meta data added to existing contact',
+ has_meta => 1,
+ orig_meta => undef,
+ end_meta => [ {
+ variable => 'true',
+ code => 'type',
+ datatype => 'string',
+ required => 'true',
+ datatype_description => 'Type of bin',
+ order => 1,
+ description => 'Type of bin'
+
+ } ],
+ 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>
+ </attributes>
+ </service_definition>
+ ',
+ },
+ {
+ desc => 'check meta data updated',
+ has_meta => 1,
+ orig_meta => [ {
+ variable => 'true',
+ code => 'type',
+ datatype => 'string',
+ required => 'true',
+ datatype_description => 'Type of bin',
+ order => 1,
+ description => 'Type of bin'
+
+ } ],
+ end_meta => [ {
+ variable => 'true',
+ code => 'type',
+ datatype => 'string',
+ required => 'true',
+ datatype_description => 'Colour of bin',
+ order => 1,
+ description => 'Colour of bin'
+
+ } ],
+ 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>Colour of bin</datatype_description>
+ <order>1</order>
+ <description>Colour of bin</description>
+ </attribute>
+ </attributes>
+ </service_definition>
+ ',
+ },
+ {
+ desc => 'check meta data removed',
+ has_meta => 0,
+ end_meta => undef,
+ orig_meta => [ {
+ variable => 'true',
+ code => 'type',
+ datatype => 'string',
+ required => 'true',
+ datatype_description => 'Type of bin',
+ order => 1,
+ description => 'Type of bin'
+
+ } ],
+ 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>
+ </attributes>
+ </service_definition>
+ ',
+ },
+) {
+ subtest $test->{desc} => sub {
+ my $processor = Open311::PopulateServiceList->new( council_list => [] );
+
+ my $services_xml = '<?xml version="1.0" encoding="utf-8"?>
+ <services>
+ <service>
+ <service_code>100</service_code>
+ <service_name>Cans left out 24x7</service_name>
+ <description>Garbage or recycling cans that have been left out for more than 24 hours after collection. Violators will be cited.</description>
+ <metadata>false</metadata>
+ <type>realtime</type>
+ <keywords>lorem, ipsum, dolor</keywords>
+ <group>sanitation</group>
+ </service>
+ </services>
+ ';
+
+ if ( $test->{has_meta} ) {
+ $services_xml =~ s/metadata>false/metadata>true/ms;
+ }
+
+ my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
+ {
+ area_id => 1,
+ email => '100',
+ category => 'Cans left out 24x7',
+ confirmed => 1,
+ deleted => 0,
+ editor => $0,
+ whenedited => \'ms_current_timestamp()',
+ note => 'test contact',
+ }
+ );
+
+ $contact->update( { extra => $test->{orig_meta} } );
+
+ my $o = Open311->new(
+ jurisdiction => 'mysociety',
+ endpoint => 'http://example.com',
+ test_mode => 1,
+ test_get_returns => { 'services.xml' => $services_xml, 'services/100.xml' => $test->{meta_xml} }
+ );
+
+ my $service_list = get_xml_simple_object( $services_xml );
+ $service_list = { service => [ $service_list->{ service } ] };
+
+ my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
+ area_id => 1
+ } );
+
+ $processor->_current_open311( $o );
+ $processor->_current_council( $council );
+
+ $processor->process_services( $service_list );
+
+ $contact->discard_changes;
+
+ is_deeply $contact->extra, $test->{end_meta}, 'meta data saved';
+ };
+}
+
subtest 'check attribute ordering' => sub {
my $processor = Open311::PopulateServiceList->new( council_list => [] );