diff options
Diffstat (limited to 't/cobrand')
-rw-r--r-- | t/cobrand/bromley.t | 20 | ||||
-rw-r--r-- | t/cobrand/fixamingata.t | 32 | ||||
-rw-r--r-- | t/cobrand/fixmybarangay.t | 20 | ||||
-rw-r--r-- | t/cobrand/get_body_sender.t | 3 | ||||
-rw-r--r-- | t/cobrand/oxfordshire.t | 50 | ||||
-rw-r--r-- | t/cobrand/zurich.t | 20 |
6 files changed, 109 insertions, 36 deletions
diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t index 6437ba3bd..fdded5606 100644 --- a/t/cobrand/bromley.t +++ b/t/cobrand/bromley.t @@ -8,6 +8,11 @@ my $mech = FixMyStreet::TestMech->new; # Create test data my $user = $mech->create_user_ok( 'bromley@example.com' ); my $body = $mech->create_body_ok( 2482, 'Bromley', id => 2482 ); +$mech->create_contact_ok( + body_id => $body->id, + category => 'Other', + email => 'LIGHT', +); my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', { cobrand => 'bromley', @@ -36,6 +41,21 @@ $mech->content_contains( 'marked as in progress' ); $mech->content_contains( 'marks it as unable to fix' ); $mech->content_contains( 'marked as no further action' ); +subtest 'testing special Open311 behaviour', sub { + $report->set_extra_fields(); + $report->update; + $body->update( { send_method => 'Open311', endpoint => 'http://bromley.endpoint.example.com', jurisdiction => 'FMS', api_key => 'test' } ); + FixMyStreet::override_config { + SEND_REPORTS_ON_STAGING => 1, + }, sub { + FixMyStreet::App->model('DB::Problem')->send_reports(); + }; + $report->discard_changes; + ok $report->whensent, 'Report marked as sent'; + is $report->send_method_used, 'Open311', 'Report sent via Open311'; + is $report->external_id, 248, 'Report has right external ID'; +}; + # Clean up $mech->delete_user($user); $mech->delete_problems_for_body( $body->id ); diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t index 105847576..3c818474d 100644 --- a/t/cobrand/fixamingata.t +++ b/t/cobrand/fixamingata.t @@ -1,12 +1,16 @@ use strict; use warnings; use Test::More; +use LWP::Protocol::PSGI; BEGIN { use FixMyStreet; FixMyStreet->test_mode(1); } +use t::MapIt; +use mySociety::Locale; + use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -21,16 +25,11 @@ FixMyStreet::override_config { $mech->content_like( qr/FixaMinGata/ ); my $body = $mech->create_body_ok( 1, 'Body' ); -FixMyStreet::App->model('DB::Contact')->find_or_create({ +$mech->create_contact_ok( body => $body, category => "Other", email => "other\@example.org", - confirmed => 1, - deleted => 0, - editor => "Editor", - whenedited => \'now()', - note => 'Note', -}); +); my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', { cobrand => 'fixamingata', @@ -96,6 +95,25 @@ like $email->header('Content-Type'), qr/iso-8859-1/, 'encoding looks okay'; like $email->body, qr/V=E4nligen,/, 'signature looks correct'; $mech->clear_emails_ok; +subtest "Test ajax decimal points" => sub { + # The following line is so we are definitely not in Swedish before + # requesting the page, so that the code performs a full switch to Swedish + mySociety::Locale::push('en-gb'); + + # A note to the future - the run_if_script line must be within a subtest + # otherwise it fails to work + LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.sweden'); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixamingata' ], + MAPIT_URL => 'http://mapit.sweden/' + }, sub { + $mech->get_ok('/ajax/lookup_location?term=12345'); + # We want an actual decimal point in a JSON response... + $mech->content_contains('51.5'); + }; +}; + END { $mech->delete_problems_for_body(1); ok $mech->host("www.fixmystreet.com"), "change host back"; diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t index edb14fe3d..316739dfa 100644 --- a/t/cobrand/fixmybarangay.t +++ b/t/cobrand/fixmybarangay.t @@ -37,28 +37,16 @@ FixMyStreet::App->model('DB::BodyArea')->find_or_create({ area_id => 2, body_id # TODO: log in as a Bgy user, and create a report using the front end, # testing that the drop-down has the right things in it, and so on. -my %contact_params = ( - confirmed => 1, - deleted => 0, - editor => 'Test', - whenedited => \'current_timestamp', - note => 'Created for test', -); -FixMyStreet::App->model('DB::Contact')->search( { - email => { 'like', '%example.com' }, -} )->delete; -my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +$mech->create_contact_ok( body_id => $luz->id, category => 'Streetlight (BGY)', email => 'bgy@example.com', -} ); -my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +); +$mech->create_contact_ok( body_id => $dps->id, category => 'Streetlight (DPS)', email => 'LIGHT', -} ); +); # Create a couple of reports diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t index 964f5c0e4..a9ba49479 100644 --- a/t/cobrand/get_body_sender.t +++ b/t/cobrand/get_body_sender.t @@ -26,9 +26,8 @@ FixMyStreet::override_config { MAPIT_URL => 'http://mapit.mysociety.org/', }, sub { is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email'; - $body_area->update({ area_id => 2481 }); # Croydon LBO - is_deeply $c->get_body_sender( $body ), { method => 'London' }, 'returns london report it if London borough'; + is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'still email if London borough'; }; $body->send_method( 'TestMethod' ); diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t new file mode 100644 index 000000000..d9f880d07 --- /dev/null +++ b/t/cobrand/oxfordshire.t @@ -0,0 +1,50 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +subtest 'check /ajax defaults to open reports only' => sub { + my $categories = [ 'Bridges', 'Fences', 'Manhole' ]; + my $params = { + postcode => 'OX28 4DS', + latitude => 51.7847208192, + longitude => -1.49445264029, + }; + my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01) + . ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01); + + # Create one open and one fixed report in each category + foreach my $category ( @$categories ) { + foreach my $state ( 'confirmed', 'fixed' ) { + my %report_params = ( + %$params, + category => $category, + state => $state, + ); + $mech->create_problems_for_body( 1, 2237, 'Around page', \%report_params ); + } + } + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'oxfordshire' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + my $json = $mech->get_ok_json( '/ajax?status=all&bbox=' . $bbox ); + my $pins = $json->{pins}; + is scalar @$pins, 6, 'correct number of reports created'; + + $json = $mech->get_ok_json( '/ajax?bbox=' . $bbox ); + $pins = $json->{pins}; + is scalar @$pins, 3, 'correct number of reports returned with no filters'; + + $json = $mech->get_ok_json( '/ajax?filter_category=Fences&bbox=' . $bbox ); + $pins = $json->{pins}; + is scalar @$pins, 1, 'only one Fences report by default'; + } +}; + +# Clean up +$mech->delete_problems_for_body( 2237 ); +done_testing(); diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 8dbc43464..90a92fb44 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -17,13 +17,16 @@ use JSON; # commonlib/bin/gettext-makemo FixMyStreet use FixMyStreet; +my $c = FixMyStreet::App->new(); +my $cobrand = FixMyStreet::Cobrand::Zurich->new({ c => $c }); +$c->stash->{cobrand} = $cobrand; # This is a helper method that will send the reports but with the config # correctly set - notably SEND_REPORTS_ON_STAGING needs to be true. sub send_reports_for_zurich { FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1 }, sub { # Actually send the report - FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); + $c->model('DB::Problem')->send_reports('zurich'); }; } sub reset_report_state { @@ -137,16 +140,11 @@ $mech->content_contains( 'Erfasst' ); subtest "changing of categories" => sub { # create a few categories (which are actually contacts) foreach my $name ( qw/Cat1 Cat2/ ) { - FixMyStreet::App->model('DB::Contact')->find_or_create({ + $mech->create_contact_ok( body => $division, category => $name, email => "$name\@example.org", - confirmed => 1, - deleted => 0, - editor => "editor", - whenedited => DateTime->now(), - note => "note for $name", - }); + ); } # put report into known category @@ -290,9 +288,9 @@ subtest "report_edit" => sub { is ( $report->extra->{closed_overdue}, 0, 'Marking hidden from scratch also set closed_overdue' ); is get_moderated_count(), 1; - is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'sanity check'); + is ($cobrand->get_or_check_overdue($report), 0, 'sanity check'); $report->update({ created => $created->clone->subtract(days => 10) }); - is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'overdue call not increased'); + is ($cobrand->get_or_check_overdue($report), 0, 'overdue call not increased'); reset_report_state($report, $created); }; @@ -653,7 +651,7 @@ subtest "test stats" => sub { my $export_count = get_export_rows_count($mech); if (defined $export_count) { is $export_count - $EXISTING_REPORT_COUNT, 3, 'Correct number of reports'; - $mech->content_contains(',fixed - council,'); + $mech->content_contains('fixed - council'); $mech->content_contains(',hidden,'); } |