diff options
Diffstat (limited to 't')
-rw-r--r-- | t/Mock/MapIt.pm | 1 | ||||
-rw-r--r-- | t/Mock/Tilma.pm | 39 | ||||
-rw-r--r-- | t/app/controller/admin/templates.t | 2 | ||||
-rw-r--r-- | t/cobrand/hounslow.t | 10 | ||||
-rw-r--r-- | t/cobrand/tfl.t | 130 |
5 files changed, 170 insertions, 12 deletions
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 96be429e4..cd441856a 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -39,6 +39,7 @@ my @PLACES = ( [ 'LE15 0GJ', 52.670447, -0.727877, 2600, 'Rutland County Council', 'CTY'], [ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ], [ 'BR1 3UH', 51.402096, 0.015784, 2482, 'Bromley Council', 'LBO' ], + [ 'BR1 3EF', 51.4039, 0.018697, 2482, 'Bromley Council', 'LBO' ], [ 'NN1 1NS', 52.236251, -0.892052, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ], [ 'NN1 2NS', 52.238301, -0.889992, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ], [ '?', 52.238827, -0.894970, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ], diff --git a/t/Mock/Tilma.pm b/t/Mock/Tilma.pm new file mode 100644 index 000000000..5a11209e3 --- /dev/null +++ b/t/Mock/Tilma.pm @@ -0,0 +1,39 @@ +package t::Mock::Tilma; + +use JSON::MaybeXS; +use Web::Simple; + +has json => ( + is => 'lazy', + default => sub { + JSON->new->utf8->pretty->allow_blessed->convert_blessed; + }, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /mapserver/tfl + ?*) { + my ($self, $args) = @_; + my $features = []; + if ($args->{Filter} =~ /540512,169141/) { + $features = [ + { type => "Feature", properties => { HA_ID => "19" }, geometry => { type => "Polygon", coordinates => [ [ + [ 539408.94, 170607.58 ], + [ 539432.81, 170627.93 ], + [ 539437.24, 170623.48 ], + [ 539408.94, 170607.58 ], + ] ] } } ]; + } + my $json = mySociety::Locale::in_gb_locale { + $self->json->encode({ + type => "FeatureCollection", + crs => { type => "name", properties => { name => "urn:ogc:def:crs:EPSG::27700" } }, + features => $features, + }); + }; + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, +} + +__PACKAGE__->run_if_script; diff --git a/t/app/controller/admin/templates.t b/t/app/controller/admin/templates.t index 200fbd727..ad5b3e77b 100644 --- a/t/app/controller/admin/templates.t +++ b/t/app/controller/admin/templates.t @@ -347,7 +347,7 @@ subtest "TfL cobrand only shows TfL templates" => sub { subtest "Bromley cobrand only shows Bromley templates" => sub { FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'bromley' ], + ALLOWED_COBRANDS => [ 'bromley', 'tfl' ], }, sub { $report->update({ category => $bromleycontact->category, bodies_str => $bromley->id }); $mech->log_in_ok( $bromleyuser->email ); diff --git a/t/cobrand/hounslow.t b/t/cobrand/hounslow.t index cb67ad397..91c1cb455 100644 --- a/t/cobrand/hounslow.t +++ b/t/cobrand/hounslow.t @@ -75,16 +75,6 @@ subtest "it shows the right things on an /around page" => sub { }; }; -subtest "does not show TfL traffic lights category" => sub { - FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.uk/', - ALLOWED_COBRANDS => 'fixmystreet', - }, sub { - my $json = $mech->get_ok_json('/report/new/ajax?latitude=51.482286&longitude=-0.328163'); - is $json->{by_category}{"Traffic lights"}, undef; - }; -}; - subtest "Shows external ID on report page to staff users only" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => 'hounslow', diff --git a/t/cobrand/tfl.t b/t/cobrand/tfl.t index a327a00ef..33506e8c4 100644 --- a/t/cobrand/tfl.t +++ b/t/cobrand/tfl.t @@ -8,6 +8,11 @@ END { FixMyStreet::App->log->enable('info'); } my $mech = FixMyStreet::TestMech->new; +use t::Mock::Tilma; +my $tilma = t::Mock::Tilma->new; +LWP::Protocol::PSGI->register($tilma->to_psgi_app, host => 'tilma.mysociety.org'); + + my $body = $mech->create_body_ok(2482, 'TfL'); FixMyStreet::DB->resultset('BodyArea')->find_or_create({ area_id => 2483, # Hounslow @@ -27,7 +32,26 @@ my $user = $mech->create_user_ok('londonresident@example.com'); my $bromley = $mech->create_body_ok(2482, 'Bromley'); my $bromleyuser = $mech->create_user_ok('bromleyuser@bromley.example.com', name => 'Bromley Staff', from_body => $bromley); +$mech->create_contact_ok( + body_id => $bromley->id, + category => 'Accumulated Litter', + email => 'litter-bromley@example.com', +); +my $bromley_flooding = $mech->create_contact_ok( + body_id => $bromley->id, + category => 'Flooding (Bromley)', + email => 'litter-bromley@example.com', +); +$bromley_flooding->set_extra_metadata(display_name => 'Flooding'); +$bromley_flooding->update; +my $bromley_flytipping = $mech->create_contact_ok( + body_id => $bromley->id, + category => 'Flytipping (Bromley)', + email => 'flytipping-bromley@example.com', +); +$bromley_flytipping->set_extra_metadata(group => [ 'Street cleaning' ]); +$bromley_flytipping->update; my $contact1 = $mech->create_contact_ok( body_id => $body->id, @@ -660,6 +684,106 @@ FixMyStreet::override_config { }, }, sub { +for my $test ( + { + host => 'www.fixmystreet.com', + name => "test red route categories", + lat => 51.4039, + lon => 0.018697, + expected => [ + 'Accumulated Litter', # Tests TfL->_cleaning_categories + 'Bus stops', + 'Flooding', + 'Flytipping (Bromley)', # In the 'Street cleaning' group + 'Grit bins', + 'Pothole', + 'Traffic lights', + 'Trees' + ], + }, + { + host => 'www.fixmystreet.com', + name => "test non-red route categories", + lat => 51.4021, + lon => 0.01578, + expected => [ + 'Accumulated Litter', # Tests TfL->_cleaning_categories + 'Bus stops', + 'Flooding (Bromley)', + 'Flytipping (Bromley)', # In the 'Street cleaning' group + 'Grit bins', + 'Traffic lights', + 'Trees' + ], + }, + { + host => 'tfl.fixmystreet.com', + name => "test red route categories", + lat => 51.4039, + lon => 0.018697, + expected => [ + 'Bus stops', + 'Flooding', + 'Grit bins', + 'Pothole', + 'Traffic lights', + 'Trees' + ], + }, + { + host => 'tfl.fixmystreet.com', + name => "test non-red route categories", + lat => 51.4021, + lon => 0.01578, + expected => [ + 'Bus stops', + 'Flooding', + 'Grit bins', + 'Pothole', + 'Traffic lights', + 'Trees' + ], + }, + { + host => 'bromley.fixmystreet.com', + name => "test red route categories", + lat => 51.4039, + lon => 0.018697, + expected => [ + 'Accumulated Litter', + 'Bus stops', + 'Flooding', + 'Flytipping (Bromley)', + 'Grit bins', + 'Pothole', + 'Traffic lights', + 'Trees' + ], + }, + { + host => 'bromley.fixmystreet.com', + name => "test non-red route categories", + lat => 51.4021, + lon => 0.01578, + expected => [ + 'Accumulated Litter', + 'Bus stops', + 'Flooding (Bromley)', + 'Flytipping (Bromley)', + 'Grit bins', + 'Traffic lights', + 'Trees' + ], + }, +) { + subtest $test->{name} . ' on ' . $test->{host} => sub { + $mech->host($test->{host}); + my $resp = $mech->get_ok_json( '/report/new/ajax?latitude=' . $test->{lat} . '&longitude=' . $test->{lon} ); + my @actual = sort keys %{ $resp->{by_category} }; + is_deeply \@actual, $test->{expected}; + }; +} + for my $host ( 'tfl.fixmystreet.com', 'www.fixmystreet.com', 'bromley.fixmystreet.com' ) { for my $test ( { @@ -673,6 +797,7 @@ for my $host ( 'tfl.fixmystreet.com', 'www.fixmystreet.com', 'bromley.fixmystree safety_critical => 'yes', category => "Pothole", subject => "Dangerous Pothole Report: Test Report", + pc => "BR1 3EF", # this is on a red route (according to Mock::MapIt and Mock::Tilma anyway) }, { name => "test category extra field - safety critical", @@ -682,6 +807,7 @@ for my $host ( 'tfl.fixmystreet.com', 'www.fixmystreet.com', 'bromley.fixmystree location => "carriageway", }, subject => "Dangerous Flooding Report: Test Report", + pc => "BR1 3EF", # this is on a red route (according to Mock::MapIt and Mock::Tilma anyway) }, { name => "test category extra field - non-safety critical", @@ -691,13 +817,15 @@ for my $host ( 'tfl.fixmystreet.com', 'www.fixmystreet.com', 'bromley.fixmystree location => "footway", }, subject => "Problem Report: Test Report", + pc => "BR1 3EF", # this is on a red route (according to Mock::MapIt and Mock::Tilma anyway) }, ) { subtest $test->{name} . ' on ' . $host => sub { $mech->log_in_ok( $user->email ); $mech->host($host); $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'BR1 3UH', } }, "submit location" ); + my $pc = $test->{pc} || 'BR1 3UH'; + $mech->submit_form_ok( { with_fields => { pc => $pc, } }, "submit location ($pc)" ); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( { |