aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/controller/admin/bodies.t43
-rw-r--r--t/app/controller/report_new.t8
-rw-r--r--t/open311/populate-service-list.t165
3 files changed, 189 insertions, 27 deletions
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index f67e45bf6..db53b7cda 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -1,10 +1,3 @@
-package FixMyStreet::Cobrand::Tester;
-
-use parent 'FixMyStreet::Cobrand::Default';
-
-sub enable_category_groups { 1 }
-
-package main;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -210,10 +203,12 @@ subtest 'check text output' => sub {
}; # END of override wrap
FixMyStreet::override_config {
- ALLOWED_COBRANDS => ['tester'],
MAPIT_URL => 'http://mapit.uk/',
MAPIT_TYPES => [ 'UTA' ],
BASE_URL => 'http://www.example.org',
+ COBRAND_FEATURES => {
+ category_groups => { default => 1 },
+ }
}, sub {
subtest 'group editing works' => sub {
$mech->get_ok('/admin/body/' . $body->id);
@@ -229,7 +224,7 @@ FixMyStreet::override_config {
} } );
my $contact = $body->contacts->find({ category => 'grouped category' });
- is $contact->get_extra_metadata('group'), 'group a', "group stored correctly";
+ is_deeply $contact->get_extra_metadata('group'), ['group a'], "group stored correctly";
};
subtest 'group can be unset' => sub {
@@ -251,5 +246,35 @@ FixMyStreet::override_config {
};
+FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ MAPIT_TYPES => [ 'UTA' ],
+ BASE_URL => 'http://www.example.org',
+ COBRAND_FEATURES => {
+ category_groups => { default => 1 },
+ multiple_category_groups => { default => 1 },
+ }
+}, sub {
+ subtest 'multi group editing works' => sub {
+ $mech->get_ok('/admin/body/' . $body->id);
+ $mech->content_contains( 'group</strong> is used for the top-level category' );
+
+ # have to do this as a post as adding a second group requires
+ # javascript
+ $mech->post_ok( '/admin/body/' . $body->id, {
+ posted => 'new',
+ token => $mech->form_id('category_edit')->value('token'),
+ category => 'grouped category',
+ email => 'test@example.com',
+ note => 'test note',
+ 'group' => [ 'group a', 'group b'],
+ non_public => undef,
+ state => 'unconfirmed',
+ } );
+
+ my $contact = $body->contacts->find({ category => 'grouped category' });
+ is_deeply $contact->get_extra_metadata('group'), ['group a', 'group b'], "group stored correctly";
+ };
+};
done_testing();
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 848529686..f65ca243d 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -1271,16 +1271,18 @@ subtest "Test inactive categories" => sub {
};
subtest "category groups" => sub {
- my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::FixMyStreet');
- $cobrand->mock('enable_category_groups', sub { 1 });
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'fixmystreet',
MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => {
+ category_groups => { fixmystreet => 1 }
+ }
}, sub {
- $contact2->update( { extra => { group => 'Roads' } } );
+ $contact2->update( { extra => { group => ['Roads','Pavements'] } } );
$contact9->update( { extra => { group => 'Roads' } } );
$contact10->update( { extra => { group => 'Roads' } } );
$mech->get_ok("/report/new?lat=$saved_lat&lon=$saved_lon");
+ $mech->content_like(qr{<optgroup label="Pavements">\s*<option value='Potholes'>Potholes</option></optgroup>});
$mech->content_like(qr{<optgroup label="Roads">\s*<option value='Potholes'>Potholes</option>\s*<option value='Street lighting'>Street lighting</option></optgroup>});
};
};
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index c67fae9bd..9f8b4d9f0 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -5,20 +5,11 @@ use parent 'FixMyStreet::Cobrand::Default';
sub council_area_id { 1 }
-
-package FixMyStreet::Cobrand::TesterGroups;
-
-use parent 'FixMyStreet::Cobrand::Default';
-
-sub council_area_id { 1 }
-
-sub enable_category_groups { 1 }
-
-
package main;
use FixMyStreet::Test;
use FixMyStreet::DB;
+use Test::Warn;
use utf8;
use_ok( 'Open311::PopulateServiceList' );
@@ -51,13 +42,16 @@ $bucks->body_areas->create({
});
for my $test (
- { desc => 'groups not set for new contacts', cobrand => 'tester', groups => 0, delete => 1 },
- { desc => 'groups set for new contacts', cobrand => 'testergroups', groups => 1, delete => 1},
- { desc => 'groups removed for existing contacts', cobrand => 'tester', groups => 0, delete => 0 },
- { desc => 'groups added for existing contacts', cobrand => 'testergroups', groups => 1, delete => 0},
+ { desc => 'groups not set for new contacts', enable_groups => 0, groups => 0, delete => 1 },
+ { desc => 'groups set for new contacts', enable_groups => 1, groups => 1, delete => 1},
+ { desc => 'groups removed for existing contacts', enable_groups => 0, groups => 0, delete => 0 },
+ { desc => 'groups added for existing contacts', enable_groups => 1, groups => 1, delete => 0},
) {
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ $test->{cobrand} ],
+ ALLOWED_COBRANDS => [ 'tester' ],
+ COBRAND_FEATURES => {
+ category_groups => { tester => $test->{enable_groups} },
+ }
}, sub {
subtest 'check basic functionality, ' . $test->{desc} => sub {
FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete() if $test->{delete};
@@ -83,6 +77,147 @@ for my $test (
};
}
+my $last_update = {};
+for my $test (
+ { desc => 'set multiple groups for contact', enable_multi => 1, groups => ['sanitation', 'street'] },
+ { desc => 'groups not edited if unchanged', enable_multi => 1, groups => ['sanitation', 'street'], unchanged => 1 },
+ { desc => 'multiple groups has to be configured', enable_multi => 0, groups => 'sanitation,street'},
+) {
+ subtest $test->{desc} => sub {
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete();
+
+ 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,street</group>
+ </service>
+ <service>
+ <service_code>002</service_code>
+ <metadata>false</metadata>
+ <type>realtime</type>
+ <keywords>lorem, ipsum, dolor</keywords>
+ <group>street</group>
+ <service_name>Construction plate shifted</service_name>
+ <description>Metal construction plate covering the street or sidewalk has been moved.</description>
+ </service>
+ </services>
+ ';
+
+ my $service_list = get_xml_simple_object($services_xml);
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tester' ],
+ COBRAND_FEATURES => {
+ category_groups => { tester => 1 },
+ multiple_category_groups => { tester => $test->{enable_multi} },
+ }
+ }, sub {
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
+ $processor->process_services( $service_list );
+ };
+ my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count();
+ is $contact_count, 2, 'correct number of contacts';
+
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id, email => 100 } )->first;
+ is_deeply $contact->get_extra->{group}, $test->{groups}, "Multi groups set correctly";
+ if ($test->{unchanged}) {
+ is $contact->whenedited, $last_update->{100}, "contact unchanged";
+ }
+ $last_update->{100} = $contact->whenedited;
+
+ $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id, email => '002'} )->first;
+ is $contact->get_extra->{group}, 'street', "Single groups set correctly";
+ if ($test->{unchanged}) {
+ is $contact->whenedited, $last_update->{002}, "contact unchanged";
+ }
+ $last_update->{002} = $contact->whenedited;
+ };
+}
+
+subtest "set multiple groups with quoted csv" => sub {
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete();
+
+ 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>&quot;sanitation &amp; cleaning&quot;,street</group>
+ </service>
+ </services>
+ ';
+
+ my $service_list = get_xml_simple_object($services_xml);
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tester' ],
+ COBRAND_FEATURES => {
+ category_groups => { tester => 1 },
+ multiple_category_groups => { tester => 1 },
+ }
+ }, sub {
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
+ $processor->process_services( $service_list );
+ };
+ my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count();
+ is $contact_count, 1, 'correct number of contacts';
+
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id, email => 100 } )->first;
+ is_deeply $contact->get_extra->{group}, ['sanitation & cleaning','street'], "groups set correctly";
+};
+
+subtest "set multiple groups with bad csv" => sub {
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete();
+
+ 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,street</group>
+ </service>
+ </services>
+ ';
+
+ my $service_list = get_xml_simple_object($services_xml);
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tester' ],
+ COBRAND_FEATURES => {
+ category_groups => { tester => 1 },
+ multiple_category_groups => { tester => 1 },
+ }
+ }, sub {
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
+ warning_like {
+ $processor->process_services( $service_list );
+ } qr/error parsing groups for testercontact Cans left out 24x7: "sanitation,street/,
+ "warning printed for bad csv";
+ };
+ my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count();
+ is $contact_count, 1, 'correct number of contacts';
+
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id, email => 100 } )->first;
+ is_deeply $contact->get_extra->{group}, ['"sanitation,street'], "groups set correctly";
+};
+
subtest 'check non open311 contacts marked as deleted' => sub {
FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete();