diff options
Diffstat (limited to 't')
-rw-r--r-- | t/Mock/MapIt.pm | 8 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 2 | ||||
-rw-r--r-- | t/cobrand/bucks.t | 105 | ||||
-rw-r--r-- | t/open311/populate-service-list.t | 2 |
4 files changed, 68 insertions, 49 deletions
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index d50ebdc1d..3cbaec3b9 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -27,14 +27,14 @@ my @PLACES = ( [ 'EH1 1BB', 55.952055, -3.189579, 2651, 'Edinburgh City Council', 'UTA', 20728, 'City Centre', 'UTE' ], [ 'BS10 5EE', 51.494885, -2.602237, 2561, 'Bristol City Council', 'UTA', 148646, 'Bedminster', 'UTW' ], [ 'BS20 5EE', 51.496194, -2.603439, 2608, 'Borsetshire County Council', 'CTY', 148646, 'Bedminster', 'UTW' ], - [ 'SL9 0NX', 51.615559, -0.556903, 2217, 'Buckinghamshire County Council', 'CTY', 2257, 'Chiltern District Council', 'DIS' ], - [ '?', 51.615499, -0.556667, 2217, 'Buckinghamshire County Council', 'CTY', 2257, 'Chiltern District Council', 'DIS' ], - [ '?', 51.615439, -0.558362, 2217, 'Buckinghamshire County Council', 'CTY', 2257, 'Chiltern District Council', 'DIS' ], + [ 'SL9 0NX', 51.615559, -0.556903, 2217, 'Buckinghamshire Council', 'CTY', 2257, 'Chiltern District Council', 'DIS' ], + [ '?', 51.615499, -0.556667, 2217, 'Buckinghamshire Council', 'CTY', 2257, 'Chiltern District Council', 'DIS' ], + [ '?', 51.615439, -0.558362, 2217, 'Buckinghamshire Council', 'CTY', 2257, 'Chiltern District Council', 'DIS' ], [ 'SW1A 1AA', 51.501009, -0.141588, 2504, 'Westminster City Council', 'LBO' ], [ 'GL50 2PR', 51.896268, -2.093063, 2226, 'Gloucestershire County Council', 'CTY', 2326, 'Cheltenham Borough Council', 'DIS', 4544, 'Lansdown', 'DIW', 143641, 'Lansdown and Park', 'CED' ], [ 'OX20 1SZ', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ], [ 'OX16 9UP', 52.038712, -1.346397, 2237, 'Oxfordshire County Council', 'CTY', 2419, 'Cherwell District Council', 'DIS', 151767, "Banbury, Calthorpe & Easington", "DIW" ], - [ 'RG9 6TL', 51.561705, -0.868388, 2217, 'Buckinghamshire County Council', 'CTY'], + [ 'RG9 6TL', 51.561705, -0.868388, 2217, 'Buckinghamshire Council', 'CTY'], [ 'PE9 2GX', 52.656144, -0.502566, 2232, 'Lincolnshire County Council', 'CTY'], [ 'LE15 0GJ', 52.670447, -0.727877, 2600, 'Rutland County Council', 'CTY'], [ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ], diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index b85bae43a..236edda62 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -53,7 +53,7 @@ for my $body ( { area_id => 2333, name => 'Hart Council' }, { area_id => 2535, name => 'Sandwell Borough Council' }, { area_id => 1000, name => 'Highways England' }, - { area_id => 2217, name => 'Buckinghamshire County Council' }, + { area_id => 2217, name => 'Buckinghamshire Council' }, { area_id => 2232, name => 'Lincolnshire County Council' }, { area_id => 2237, name => 'Oxfordshire County Council' }, { area_id => 2600, name => 'Rutland County Council' }, diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t index c231a5388..230a52f99 100644 --- a/t/cobrand/bucks.t +++ b/t/cobrand/bucks.t @@ -4,18 +4,34 @@ use FixMyStreet::Script::Reports; my $mech = FixMyStreet::TestMech->new; +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + my $body = $mech->create_body_ok(2217, 'Buckinghamshire', { - send_method => 'Open311', api_key => 'key', endpoint => 'endpoint', jurisdiction => 'fms' }); + send_method => 'Open311', api_key => 'key', endpoint => 'endpoint', jurisdiction => 'fms', can_be_devolved => 1 }); my $counciluser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $body); - -$mech->create_contact_ok(body_id => $body->id, category => 'Flytipping', email => "FLY"); +my $publicuser = $mech->create_user_ok('fmsuser@example.org', name => 'Simon Neil'); + +my $contact = $mech->create_contact_ok(body_id => $body->id, category => 'Flytipping', email => "FLY"); +$contact->set_extra_fields({ + code => 'road-placement', + datatype => 'singlevaluelist', + description => 'Is the fly-tip located on', + order => 100, + required => 'true', + variable => 'true', + values => [ + { key => 'road', name => 'The road' }, + { key => 'off-road', name => 'Off the road/on a verge' }, + ], +}); +$contact->update; $mech->create_contact_ok(body_id => $body->id, category => 'Potholes', email => "POT"); $mech->create_contact_ok(body_id => $body->id, category => 'Blocked drain', email => "DRA"); - -my $district = $mech->create_body_ok(2257, 'Chiltern'); -$mech->create_contact_ok(body_id => $district->id, category => 'Car Parks', email => "car\@chiltern"); -$mech->create_contact_ok(body_id => $district->id, category => 'Flytipping', email => "flytipping\@chiltern"); -$mech->create_contact_ok(body_id => $district->id, category => 'Graffiti', email => "graffiti\@chiltern"); +$mech->create_contact_ok(body_id => $body->id, category => 'Car Parks', email => "car\@chiltern", send_method => 'Email'); +$mech->create_contact_ok(body_id => $body->id, category => 'Graffiti', email => "graffiti\@chiltern", send_method => 'Email'); +$mech->create_contact_ok(body_id => $body->id, category => 'Flytipping (off-road)', email => "districts_flytipping", send_method => 'Email'); my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::Buckinghamshire'); $cobrand->mock('lookup_site_code', sub { @@ -33,6 +49,13 @@ FixMyStreet::override_config { flytipping => 'flytipping@example.org', flood => 'floods@example.org', } + }, + borough_email_addresses => { + buckinghamshire => { + districts_flytipping => [ + { email => "flytipping\@chiltern", areas => [ 2257 ] }, + ] + } } } }, sub { @@ -45,18 +68,20 @@ subtest 'cobrand displays council name' => sub { subtest 'cobrand displays correct categories' => sub { my $json = $mech->get_ok_json('/report/new/ajax?latitude=51.615559&longitude=-0.556903'); - is @{$json->{bodies}}, 2, 'Both Chiltern and Bucks returned'; + is @{$json->{bodies}}, 1, 'Bucks returned'; like $json->{category}, qr/Car Parks/, 'Car Parks displayed'; like $json->{category}, qr/Flytipping/, 'Flytipping displayed'; like $json->{category}, qr/Blocked drain/, 'Blocked drain displayed'; - unlike $json->{category}, qr/Graffiti/, 'Graffiti not displayed'; + like $json->{category}, qr/Graffiti/, 'Graffiti displayed'; + unlike $json->{category}, qr/Flytipping \(off-road\)/, 'Flytipping (off-road) not displayed'; $json = $mech->get_ok_json('/report/new/category_extras?latitude=51.615559&longitude=-0.556903'); - is @{$json->{bodies}}, 2, 'Still both Chiltern and Bucks returned'; + is @{$json->{bodies}}, 1, 'Still Bucks returned'; }; my ($report) = $mech->create_problems_for_body(1, $body->id, 'On Road', { category => 'Flytipping', cobrand => 'fixmystreet', latitude => 51.812244, longitude => -0.827363, + dt => DateTime->now()->subtract(minutes => 10), }); subtest 'flytipping on road sent to extra email' => sub { @@ -75,6 +100,7 @@ subtest 'flytipping on road sent to extra email' => sub { contributed_as => 'another_user', contributed_by => $counciluser->id, }, + dt => DateTime->now()->subtract(minutes => 9), }); subtest 'pothole on road not sent to extra email, only confirm sent' => sub { @@ -86,22 +112,38 @@ subtest 'pothole on road not sent to extra email, only confirm sent' => sub { is $report->external_id, 248, 'Report has right external ID'; }; -($report) = $mech->create_problems_for_body(1, $district->id, 'Off Road', { - category => 'Flytipping', cobrand => 'buckinghamshire', - latitude => 51.813173, longitude => -0.826741, -}); -subtest 'flytipping off road sent to extra email' => sub { + +# report made in Flytipping category off road should get moved to other category +subtest 'Flytipping not on a road gets recategorised' => sub { + $mech->log_in_ok($publicuser->email); + $mech->get_ok('/report/new?latitude=51.615559&longitude=-0.556903&category=Flytipping'); + $mech->submit_form_ok({ + with_fields => { + title => "Test Report", + detail => 'Test report details.', + category => 'Flytipping', + 'road-placement' => 'off-road', + } + }, "submit details"); + $mech->content_contains('Your issue is on its way to the council.'); + my $report = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first; + ok $report, "Found the report"; + is $report->category, "Flytipping (off-road)", 'Report was recategorised correctly'; + + $mech->log_out_ok; +}; + +subtest 'Ex-district reports are sent to correct emails' => sub { FixMyStreet::Script::Reports::send(); + $mech->email_count_is(2); # one for council, one confirmation for user my @email = $mech->get_email; - is $email[0]->header('To'), 'Chiltern <flytipping@chiltern>'; - unlike $mech->get_text_body_from_email($email[1]), qr/Please note that Buckinghamshire County Council is not responsible/; - $report->discard_changes; - is $report->external_id, undef, 'Report has right external ID'; + is $email[0]->header('To'), 'Buckinghamshire <flytipping@chiltern>'; }; my ($report2) = $mech->create_problems_for_body(1, $body->id, 'Drainage problem', { category => 'Blocked drain', cobrand => 'fixmystreet', latitude => 51.812244, longitude => -0.827363, + dt => DateTime->now()->subtract(minutes => 8), }); subtest 'blocked drain sent to extra email' => sub { @@ -114,29 +156,6 @@ subtest 'blocked drain sent to extra email' => sub { $cobrand = FixMyStreet::Cobrand::Buckinghamshire->new(); -subtest 'Flytipping extra question used if necessary' => sub { - my $errors = { 'xroad-placement' => 'This field is required' }; - - $report->update({ bodies_str => $body->id }); - $cobrand->flytipping_body_fix($report, 'road', $errors); - is $errors->{'xroad-placement'}, 'This field is required', 'Error stays if sent to county'; - - $report->update({ bodies_str => $district->id }); - $report->discard_changes; # As e.g. ->bodies has been remembered. - $cobrand->flytipping_body_fix($report, 'road', $errors); - is $errors->{'xroad-placement'}, undef, 'Error removed if sent to district'; - - $report->update({ bodies_str => $body->id . ',' . $district->id }); - $report->discard_changes; # As e.g. ->bodies has been remembered. - $cobrand->flytipping_body_fix($report, 'road', $errors); - is $report->bodies_str, $body->id, 'Sent to both becomes sent to county on-road'; - - $report->update({ bodies_str => $district->id . ',' . $body->id }); - $report->discard_changes; # As e.g. ->bodies has been remembered. - $cobrand->flytipping_body_fix($report, 'off-road', $errors); - is $report->bodies_str, $district->id, 'Sent to both becomes sent to district off-road'; -}; - for my $test ( { desc => 'filters basic emails', diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t index 40e124d03..59f8b7b65 100644 --- a/t/open311/populate-service-list.t +++ b/t/open311/populate-service-list.t @@ -35,7 +35,7 @@ $bromley->body_areas->create({ } ); my $bucks = FixMyStreet::DB->resultset('Body')->create({ - name => 'Buckinghamshire County Council', + name => 'Buckinghamshire Council', }); $bucks->body_areas->create({ area_id => 2217 |