aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Mock/Facebook.pm6
-rw-r--r--t/Mock/MapIt.pm100
-rw-r--r--t/app/controller/admin.t22
-rw-r--r--t/app/controller/admin_permissions.t4
-rw-r--r--t/app/controller/alert.t24
-rw-r--r--t/app/controller/alert_new.t22
-rw-r--r--t/app/controller/around.t20
-rw-r--r--t/app/controller/auth.t4
-rw-r--r--t/app/controller/auth_social.t9
-rw-r--r--t/app/controller/dashboard.t4
-rw-r--r--t/app/controller/index.t9
-rw-r--r--t/app/controller/moderate.t21
-rw-r--r--t/app/controller/my_planned.t16
-rw-r--r--t/app/controller/photo.t2
-rw-r--r--t/app/controller/questionnaire.t6
-rw-r--r--t/app/controller/report_as_other.t14
-rw-r--r--t/app/controller/report_display.t57
-rw-r--r--t/app/controller/report_import.t17
-rw-r--r--t/app/controller/report_inspect.t50
-rw-r--r--t/app/controller/report_new.t170
-rw-r--r--t/app/controller/report_new_mobile.t8
-rw-r--r--t/app/controller/report_new_open311.t9
-rw-r--r--t/app/controller/report_updates.t51
-rw-r--r--t/app/controller/reports.t63
-rw-r--r--t/app/controller/rss.t6
-rw-r--r--t/app/helpers/send_email.t5
-rw-r--r--t/app/model/alert_type.t6
-rw-r--r--t/app/model/defecttype.t67
-rw-r--r--t/app/model/problem.t122
-rw-r--r--t/app/model/user.t4
-rw-r--r--t/app/script/archive_old_enquiries.t163
-rw-r--r--t/app/sendreport/open311.t267
-rw-r--r--t/cobrand/bromley.t2
-rw-r--r--t/cobrand/fixamingata.t13
-rw-r--r--t/cobrand/form_extras.t2
-rw-r--r--t/cobrand/oxfordshire.t23
-rw-r--r--t/cobrand/seesomething.t87
-rw-r--r--t/cobrand/zurich.t12
-rw-r--r--t/cobrand/zurich_attachments.txt2
-rw-r--r--t/open311.t37
-rw-r--r--t/sendreport/open311.t2
-rw-r--r--t/utils.t14
-rw-r--r--t/utils/email.t3
43 files changed, 1113 insertions, 432 deletions
diff --git a/t/Mock/Facebook.pm b/t/Mock/Facebook.pm
index eb882af21..339eae536 100644
--- a/t/Mock/Facebook.pm
+++ b/t/Mock/Facebook.pm
@@ -20,14 +20,14 @@ has returns_email => (
sub dispatch_request {
my $self = shift;
- sub (GET + /v2.2/dialog/oauth + ?*) {
+ sub (GET + /v2.8/dialog/oauth + ?*) {
my ($self) = @_;
return [ 200, [ 'Content-Type' => 'text/html' ], [ 'FB login page' ] ];
},
- sub (GET + /v2.2/oauth/access_token + ?*) {
+ sub (GET + /v2.8/oauth/access_token + ?*) {
my ($self) = @_;
- return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'access_token=access_token&expires=never' ] ];
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ '{"access_token": "access_token"}' ] ];
},
sub (GET + /me + ?fields=) {
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index 9aa8b7e40..43d44d519 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -2,6 +2,7 @@ package t::Mock::MapIt;
use JSON::MaybeXS;
use Web::Simple;
+use LWP::Protocol::PSGI;
use mySociety::Locale;
@@ -12,42 +13,83 @@ has json => (
},
);
+sub output {
+ my ($self, $response) = @_;
+ # We must make sure we output correctly for testing purposes, we might
+ # be within a different locale here...
+ my $json = mySociety::Locale::in_gb_locale {
+ $self->json->encode($response) };
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+}
+
+my @PLACES = (
+ [ 'EH1 1BB', 55.952055, -3.189579, 2651, 'Edinburgh City Council', 'UTA', 20728, 'City Centre', 'UTE' ],
+ [ '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' ],
+ [ '?', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ],
+ [ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ],
+ [ '?', 50.78301, -0.646929 ],
+ [ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ],
+ [ 'WS1 4NH', 52.563074, -1.991032, 2535, 'Sandwell Borough Council', 'MTD' ],
+);
+
sub dispatch_request {
my $self = shift;
sub (GET + /postcode/*) {
my ($self, $postcode) = @_;
- my $response = $self->postcode($postcode);
- # We must make sure we output correctly for testing purposes, we might
- # be within a different locale here...
- my $json = mySociety::Locale::in_gb_locale {
- $self->json->encode($response) };
- return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ foreach (@PLACES) {
+ if ($postcode eq $_->[0] || $postcode eq $_->[0] =~ s/ //gr) {
+ return $self->output({wgs84_lat => $_->[1], wgs84_lon => $_->[2], postcode => $postcode, coordsyst => 'G'});
+ }
+ }
+ my $response = {
+ wgs84_lat => 51.5, wgs84_lon => -2.1, postcode => $postcode, coordsyst => 'G',
+ };
+ return $self->output($response);
},
- sub (GET + /point/**) {
+ sub (GET + /point/**.*) {
my ($self, $point) = @_;
+ foreach (@PLACES) {
+ if ($point eq "4326/$_->[2],$_->[1]") {
+ my %out;
+ for (my $i=3; $i<@$_; $i+=3) {
+ $out{"$_->[$i]"} = { id => $_->[$i], name => $_->[$i+1], type => $_->[$i+2] };
+ }
+ return $self->output(\%out);
+ }
+ }
my $response = {
"63999" => {"parent_area" => 2245, "generation_high" => 25, "all_names" => {}, "id" => 63999, "codes" => {"ons" => "00HYNS", "gss" => "E05008366", "unit_id" => "44025"}, "name" => "Kington", "country" => "E", "type_name" => "Unitary Authority electoral division (UTE)", "generation_low" => 12, "country_name" => "England", "type" => "UTE"},
- "65822" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 65822, "codes" => {"gss" => "E14000860", "unit_id" => "24903"}, "name" => "North Wiltshire", "country" => "E", "type_name" => "UK Parliament constituency", "generation_low" => 13, "country_name" => "England", "type" => "WMC"},
- "11814" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 11814, "codes" => {"ons" => "09", "gss" => "E15000009", "unit_id" => "41427"}, "name" => "South West", "country" => "E", "type_name" => "European region", "generation_low" => 1, "country_name" => "England", "type" => "EUR"},
"2245" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 2245, "codes" => {"ons" => "00HY", "gss" => "E06000054", "unit_id" => "43925"}, "name" => "Wiltshire Council", "country" => "E", "type_name" => "Unitary Authority", "generation_low" => 11, "country_name" => "England", "type" => "UTA"}
};
- # We must make sure we output correctly for testing purposes, we might
- # be within a different locale here...
- my $json = mySociety::Locale::in_gb_locale {
- $self->json->encode($response) };
- return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ return $self->output($response);
+ },
+
+ sub (GET + /areas/*) {
+ my ($self, $areas) = @_;
+ if ($areas eq 'Hart') {
+ $self->output({2333 => {parent_area => undef, id => 2333, name => "Hart District Council", type => "DIS"}});
+ } elsif ($areas eq 'Birmingham') {
+ $self->output({2514 => {parent_area => undef, id => 2514, name => "Birmingham City Council", type => "MTD"}});
+ } elsif ($areas eq 'Gloucestershire') {
+ $self->output({2226 => {parent_area => undef, id => 2226, name => "Gloucestershire County Council", type => "CTY"}});
+ } elsif ($areas eq 'Cheltenham') {
+ $self->output({2326 => {parent_area => undef, id => 2326, name => "Cheltenham Borough Council", type => "DIS"}});
+ } elsif ($areas eq 'Lansdown and Park') {
+ $self->output({22261 => {parent_area => 2226, id => 22261, name => "Lansdown and Park", type => "CED"}});
+ } elsif ($areas eq 'Lansdown') {
+ $self->output({23261 => {parent_area => 2326, id => 23261, name => "Lansdown", type => "DIW"}});
+ } elsif ($areas eq 'UTA') {
+ $self->output({2650 => {parent_area => undef, id => 2650, name => "Aberdeen Council", type => "UTA"}});
+ }
},
sub (GET + /area/*) {
my ($self, $area) = @_;
- my $response = {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 2245, "codes" => {"ons" => "00HY", "gss" => "E06000054", "unit_id" => "43925"}, "name" => "Wiltshire Council", "country" => "E", "type_name" => "Unitary Authority", "generation_low" => 11, "country_name" => "England", "type" => "UTA"};
- # We must make sure we output correctly for testing purposes, we might
- # be within a different locale here...
- my $json = mySociety::Locale::in_gb_locale {
- $self->json->encode($response) };
- return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ my $response = { "id" => $area, "name" => "Area $area", "type" => "UTA" };
+ return $self->output($response);
},
sub (GET + /area/*/children) {
@@ -56,19 +98,15 @@ sub dispatch_request {
"60705" => { "parent_area" => 2245, "generation_high" => 25, "all_names" => { }, "id" => 60705, "codes" => { "ons" => "00HY226", "gss" => "E04011842", "unit_id" => "17101" }, "name" => "Trowbridge", "country" => "E", "type_name" => "Civil parish/community", "generation_low" => 12, "country_name" => "England", "type" => "CPC" },
"62883" => { "parent_area" => 2245, "generation_high" => 25, "all_names" => { }, "id" => 62883, "codes" => { "ons" => "00HY026", "gss" => "E04011642", "unit_id" => "17205" }, "name" => "Bradford-on-Avon", "country" => "E", "type_name" => "Civil parish/community", "generation_low" => 12, "country_name" => "England", "type" => "CPC" },
};
- # We must make sure we output correctly for testing purposes, we might
- # be within a different locale here...
- my $json = mySociety::Locale::in_gb_locale {
- $self->json->encode($response) };
- return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ return $self->output($response);
},
-}
-sub postcode {
- my ($self, $postcode) = @_;
- return {
- wgs84_lat => 51.5, wgs84_lon => -2.1, postcode => $postcode, coordsyst => 'G',
- };
+ sub (GET + /area/*/example_postcode) {
+ my ($self, $area) = @_;
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ '"AB12 1AA"' ] ];
+ },
}
+LWP::Protocol::PSGI->register(t::Mock::MapIt->to_psgi_app, host => 'mapit.uk');
+
__PACKAGE__->run_if_script;
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 1ab0cb488..5f8abe5a6 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -1,9 +1,7 @@
use strict;
use warnings;
use Test::More;
-use LWP::Protocol::PSGI;
-use t::Mock::MapIt;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -148,7 +146,7 @@ subtest 'check summary counts' => sub {
# This override is wrapped around ALL the /admin/body tests
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
MAPIT_TYPES => [ 'UTA' ],
BASE_URL => 'http://www.example.org',
}, sub {
@@ -208,7 +206,7 @@ subtest 'check contact creation' => sub {
subtest 'check contact editing' => sub {
$mech->get_ok('/admin/body/' . $body->id .'/test%20category');
- $mech->submit_form_ok( { with_fields => {
+ $mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
note => 'test2 note',
non_public => undef,
@@ -220,7 +218,18 @@ subtest 'check contact editing' => sub {
$mech->content_contains( 'Private:&nbsp;No' );
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
- $mech->submit_form_ok( { with_fields => {
+ $mech->submit_form_ok( { with_fields => {
+ email => 'test2@example.com, test3@example.com',
+ note => 'test3 note',
+ } } );
+
+ $mech->content_contains( 'test2@example.com,test3@example.com' );
+
+ $mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->content_contains( '<td><strong>test2@example.com,test3@example.com' );
+
+ $mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
note => 'test2 note',
non_public => 'on',
@@ -580,7 +589,6 @@ foreach my $test (
}
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
ALLOWED_COBRANDS => 'fixmystreet',
}, sub {
@@ -1190,6 +1198,7 @@ my %default_perms = (
"permissions[report_instruct]" => undef,
"permissions[contribute_as_another_user]" => undef,
"permissions[contribute_as_body]" => undef,
+ "permissions[view_body_contribute_details]" => undef,
"permissions[user_edit]" => undef,
"permissions[user_manage_permissions]" => undef,
"permissions[user_assign_body]" => undef,
@@ -1203,7 +1212,6 @@ my %default_perms = (
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
}, sub {
- LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk');
for my $test (
{
desc => 'edit user name',
diff --git a/t/app/controller/admin_permissions.t b/t/app/controller/admin_permissions.t
index 4b05660cc..dd256173d 100644
--- a/t/app/controller/admin_permissions.t
+++ b/t/app/controller/admin_permissions.t
@@ -1,9 +1,7 @@
use strict;
use warnings;
use Test::More;
-use LWP::Protocol::PSGI;
-use t::Mock::MapIt;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -84,8 +82,6 @@ FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
ALLOWED_COBRANDS => [ 'oxfordshire' ],
}, sub {
- LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk');
-
my $user2_id = $user2->id;
$report->update({ bodies_str => $oxfordshire->id });
diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t
index c42eba6b8..cb5949b8f 100644
--- a/t/app/controller/alert.t
+++ b/t/app/controller/alert.t
@@ -17,7 +17,7 @@ $mech->content_contains('html class="no-js" lang="en-gb"');
# check that we can get list page
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
GEOCODER => '',
}, sub {
$mech->get_ok('/alert/list');
@@ -25,21 +25,21 @@ FixMyStreet::override_config {
$mech->content_contains('Local RSS feeds and email alerts');
$mech->content_contains('html class="no-js" lang="en-gb"');
- $mech->get_ok('/alert/list?pc=EH99 1SP');
+ $mech->get_ok('/alert/list?pc=EH1 1BB');
$mech->title_like(qr/^Local RSS feeds and email alerts/);
- $mech->content_contains('Here are the types of local problem alerts for &lsquo;EH99&nbsp;1SP&rsquo;');
+ $mech->content_contains('Here are the types of local problem alerts for &lsquo;EH1&nbsp;1BB&rsquo;');
$mech->content_contains('html class="no-js" lang="en-gb"');
$mech->content_contains('Problems within 10.0km');
- $mech->content_contains('rss/pc/EH991SP/2');
- $mech->content_contains('rss/pc/EH991SP/5');
- $mech->content_contains('rss/pc/EH991SP/10');
- $mech->content_contains('rss/pc/EH991SP/20');
- $mech->content_contains('Problems within City of Edinburgh');
+ $mech->content_contains('rss/pc/EH11BB/2');
+ $mech->content_contains('rss/pc/EH11BB/5');
+ $mech->content_contains('rss/pc/EH11BB/10');
+ $mech->content_contains('rss/pc/EH11BB/20');
+ $mech->content_contains('Problems within Edinburgh City');
$mech->content_contains('Problems within City Centre ward');
- $mech->content_contains('/rss/reports/City+of+Edinburgh');
- $mech->content_contains('/rss/reports/City+of+Edinburgh/City+Centre');
- $mech->content_contains('council:2651:City_of_Edinburgh');
- $mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre');
+ $mech->content_contains('/rss/reports/Edinburgh');
+ $mech->content_contains('/rss/reports/Edinburgh/City+Centre');
+ $mech->content_contains('council:2651:Edinburgh');
+ $mech->content_contains('ward:2651:20728:Edinburgh:City_Centre');
subtest "Test Nominatim lookup" => sub {
LWP::Protocol::PSGI->register(t::Mock::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org');
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 1b85adf7e..ea38f7c25 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -208,7 +208,7 @@ foreach my $test (
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/alert/list?pc=EH991SP');
};
@@ -312,7 +312,7 @@ subtest "Test two-tier council alerts" => sub {
) {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok( '/alert/list?pc=GL502PR' );
$mech->submit_form_ok( {
@@ -351,7 +351,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
$mech->get_ok( '/alert' );
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH11BB' } } );
$mech->submit_form_ok( {
@@ -371,7 +371,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
}
}
- my $dt = DateTime->now()->add( days => 2);
+ my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2);
my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
@@ -436,7 +436,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
ok $update, "created test update - $update_id";
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
FixMyStreet::App->model('DB::AlertType')->email_alerts();
};
@@ -447,7 +447,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
for (@emails) {
my $body = $mech->get_text_body_from_email($_);
$count++ if $body =~ /The following updates have been left on this report:/;
- $count++ if $body =~ /The following new FixMyStreet reports have been added in the City of\s+Edinburgh\s+Council area:/;
+ $count++ if $body =~ /The following new FixMyStreet reports have been added in the Area 2651 area:/;
$count++ if $body =~ /The following FixMyStreet reports have been made within the area you\s+specified:/;
$count++ if $body =~ /\s+-\s+Testing/;
}
@@ -486,7 +486,7 @@ subtest "Test signature template is used from cobrand" => sub {
my $user2 = $mech->create_user_ok('alerts@example.com', name => 'Alert User' );
- my $dt = DateTime->now()->add( days => 2);
+ my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2);
my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
@@ -542,7 +542,7 @@ subtest "Test signature template is used from cobrand" => sub {
$mech->clear_emails_ok;
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
}, sub {
FixMyStreet::App->model('DB::AlertType')->email_alerts();
@@ -570,7 +570,7 @@ subtest "Test signature template is used from cobrand" => sub {
$mech->clear_emails_ok;
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
}, sub {
FixMyStreet::App->model('DB::AlertType')->email_alerts();
@@ -665,7 +665,7 @@ for my $test (
$mech->clear_emails_ok;
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
FixMyStreet::App->model('DB::AlertType')->email_alerts();
};
@@ -673,7 +673,7 @@ for my $test (
$report->update( { non_public => 0 } );
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
FixMyStreet::App->model('DB::AlertType')->email_alerts();
};
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index 9e2e7c524..c8aca04aa 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -1,9 +1,7 @@
use strict;
use warnings;
use Test::More;
-use LWP::Protocol::PSGI;
-use t::Mock::MapIt;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -17,7 +15,7 @@ subtest "check that if no query we get sent back to the homepage" => sub {
subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub {
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/around?x=3281&y=1113');
};
@@ -73,8 +71,8 @@ foreach my $test (
foreach my $test (
{
pc => 'SW1A 1AA',
- latitude => '51.5',
- longitude => '-2.1',
+ latitude => '51.501009',
+ longitude => '-0.141588',
},
{
pc => 'TQ 388 773',
@@ -84,8 +82,6 @@ foreach my $test (
)
{
subtest "check lat/lng for '$test->{pc}'" => sub {
- LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk');
-
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
@@ -102,7 +98,7 @@ foreach my $test (
subtest 'check non public reports are not displayed on around page' => sub {
my $params = {
- postcode => 'EH99 1SP',
+ postcode => 'EH1 1BB',
latitude => 55.9519637512,
longitude => -3.17492254484,
};
@@ -112,9 +108,9 @@ subtest 'check non public reports are not displayed on around page' => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } },
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
$mech->content_contains( 'Around page Test 3 for 2651',
@@ -126,9 +122,9 @@ subtest 'check non public reports are not displayed on around page' => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } },
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
$mech->content_lacks( 'Around page Test 3 for 2651',
diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t
index 22ade6f4b..3a11cfc4a 100644
--- a/t/app/controller/auth.t
+++ b/t/app/controller/auth.t
@@ -56,6 +56,10 @@ for my $test (
is_deeply $mech->page_errors, [ $error_message ], 'errors match';
}
+# Email address parsing should pass from here
+my $resolver = Test::MockModule->new('Email::Valid');
+$resolver->mock('address', sub { $_[1] });
+
# create a new account
$mech->clear_emails_ok;
$mech->get_ok('/auth');
diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t
index f3eae32a7..09fdf22d3 100644
--- a/t/app/controller/auth_social.t
+++ b/t/app/controller/auth_social.t
@@ -1,13 +1,13 @@
use strict;
use warnings;
use Test::More;
+use Test::MockModule;
use LWP::Protocol::PSGI;
use LWP::Simple;
use JSON::MaybeXS;
use t::Mock::Facebook;
use t::Mock::Twitter;
-use t::Mock::MapIt;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -18,8 +18,6 @@ END { FixMyStreet::App->log->enable('info'); }
my ($report) = $mech->create_problems_for_body(1, '2345', 'Test');
-LWP::Protocol::PSGI->register(t::Mock::MapIt->to_psgi_app, host => 'mapit.uk');
-
FixMyStreet::override_config {
FACEBOOK_APP_ID => 'facebook-app-id',
TWITTER_KEY => 'twitter-key',
@@ -30,6 +28,9 @@ FixMyStreet::override_config {
my $fb_email = 'facebook@example.org';
my $fb_uid = 123456789;
+my $resolver = Test::MockModule->new('Email::Valid');
+$resolver->mock('address', sub { 'facebook@example.org' });
+
for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) {
for my $page ( 'my', 'report', 'update' ) {
subtest "test FB '$fb_state' login for page '$page'" => sub {
@@ -138,6 +139,8 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) {
}
}
+$resolver->mock('address', sub { 'twitter@example.org' });
+
my $tw_email = 'twitter@example.org';
my $tw_uid = 987654321;
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t
index 5ea5cb9f5..903affdcf 100644
--- a/t/app/controller/dashboard.t
+++ b/t/app/controller/dashboard.t
@@ -25,7 +25,7 @@ my $p_user = $mech->create_user_ok('p_user@example.com');
set_absolute_time('2014-03-01T12:00:00');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->not_logged_in_ok;
@@ -48,7 +48,7 @@ FixMyStreet::override_config {
with_fields => { email => $test_user, password_sign_in => $test_pass }
} );
- $mech->content_contains( 'City of Edinburgh' );
+ $mech->content_contains( 'Area 2651' );
FixMyStreet::App->model('DB::Contact')->search( { body_id => $body->id } )
->delete;
diff --git a/t/app/controller/index.t b/t/app/controller/index.t
index 6752d4d7e..6b28a03d2 100644
--- a/t/app/controller/index.t
+++ b/t/app/controller/index.t
@@ -12,12 +12,7 @@ subtest "check that the form goes to /around" => sub {
$mech->get_ok('/');
is $mech->uri->path, '/', "still on '/'";
- # submit form
- FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
- }, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } );
- };
+ $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } );
# check that we are at /around
is $mech->uri->path, '/around', "Got to /around";
@@ -52,7 +47,7 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub {
# get the uri and check for 302
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok($uri);
};
diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t
index 0ccfcf2c2..10287ab22 100644
--- a/t/app/controller/moderate.t
+++ b/t/app/controller/moderate.t
@@ -67,7 +67,8 @@ subtest 'Auth' => sub {
$mech->get_ok($REPORT_URL);
$mech->content_lacks('Moderat');
- $mech->get_ok('/contact?m=1&id=' . $report->id);
+ $mech->get('/contact?m=1&id=' . $report->id);
+ is $mech->res->code, 400;
$mech->content_lacks('Good bad bad bad');
};
@@ -100,6 +101,7 @@ subtest 'Problem moderation' => sub {
problem_detail => 'Good good improved',
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
+ $mech->content_like(qr/Moderated by Bromley Council/);
$report->discard_changes;
is $report->title, 'Good [...] good';
@@ -329,6 +331,23 @@ subtest 'Update 2' => sub {
is $update2->text, 'update good good [...] good',
};
+subtest 'Now stop being a staff user' => sub {
+ $user->update({ from_body => undef });
+ $mech->get_ok($REPORT_URL);
+ $mech->content_contains('Moderated by Bromley Council');
+};
+
+subtest 'And do it as a superuser' => sub {
+ $user->update({ is_superuser => 1 });
+ $mech->get_ok($REPORT_URL);
+ $mech->submit_form_ok({ with_fields => {
+ %problem_prepopulated,
+ problem_title => 'Good good',
+ problem_detail => 'Good good improved',
+ }});
+ $mech->content_contains('Moderated by a FixMyStreet administrator');
+};
+
$update->delete;
$update2->delete;
$report->moderation_original_data->delete;
diff --git a/t/app/controller/my_planned.t b/t/app/controller/my_planned.t
index 7bd1dd2cd..fa463e61e 100644
--- a/t/app/controller/my_planned.t
+++ b/t/app/controller/my_planned.t
@@ -40,11 +40,23 @@ $mech->content_contains('Test Title');
$mech->get_ok($problem->url);
$mech->content_contains('Shortlisted');
-$mech->submit_form_ok({ with_fields => { change => 'remove' } });
+$mech->submit_form_ok({ with_fields => { 'shortlist-remove' => 1 } });
$mech->content_contains('Shortlist');
-$mech->submit_form_ok({ with_fields => { change => 'add' } });
+$mech->submit_form_ok({ with_fields => { 'shortlist-add' => 1 } });
$mech->content_contains('Shortlisted');
+$mech->get_ok('/my/planned?sort=shortlist&ajax=1');
+$mech->content_contains('shortlist-up');
+$mech->content_contains('shortlist-down');
+
+$mech->get_ok('/my/planned?sort=created-desc&ajax=1');
+$mech->content_lacks('shortlist-up');
+$mech->content_lacks('shortlist-down');
+
+$mech->get_ok('/my/planned?ajax=1');
+$mech->content_contains('shortlist-up');
+$mech->content_contains('shortlist-down');
+
done_testing();
END {
diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t
index 69c2ae866..ad857b5e3 100644
--- a/t/app/controller/photo.t
+++ b/t/app/controller/photo.t
@@ -30,7 +30,7 @@ subtest "Check multiple upload worked" => sub {
# submit initial pc form
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
UPLOAD_DIR => $UPLOAD_DIR,
}, sub {
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index b05f74225..f42908a3e 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -87,16 +87,19 @@ foreach my $test (
desc => 'User goes to questionnaire URL with a bad token',
token_extra => 'BAD',
content => "Sorry, that wasn&rsquo;t a valid link",
+ code => 400,
},
{
desc => 'User goes to questionnaire URL for a now-hidden problem',
state => 'hidden',
content => "we couldn't locate your problem",
+ code => 400,
},
{
desc => 'User goes to questionnaire URL for an already answered questionnaire',
answered => \'current_timestamp',
content => 'already answered this questionnaire',
+ code => 400,
},
) {
subtest $test->{desc} => sub {
@@ -106,7 +109,8 @@ foreach my $test (
$questionnaire->update;
(my $token = $token->token);
$token .= $test->{token_extra} if $test->{token_extra};
- $mech->get_ok("/Q/$token");
+ $mech->get("/Q/$token");
+ is $mech->res->code, $test->{code}, "Right status received";
$mech->content_contains( $test->{content} );
# Reset, no matter what test did
$report->state( 'confirmed' );
diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t
index 505a1bf6b..551a59481 100644
--- a/t/app/controller/report_as_other.t
+++ b/t/app/controller/report_as_other.t
@@ -1,9 +1,7 @@
use strict;
use warnings;
use Test::More;
-use LWP::Protocol::PSGI;
-use t::Mock::MapIt;
use FixMyStreet::TestMech;
use FixMyStreet::App;
@@ -13,7 +11,7 @@ END { FixMyStreet::App->log->enable('info'); }
my $mech = FixMyStreet::TestMech->new;
-my $body = $mech->create_body_ok(2245, 'Wiltshire Council');
+my $body = $mech->create_body_ok(2237, 'Oxfordshire County Council');
my $contact1 = $mech->create_contact_ok( body_id => $body->id, category => 'Street lighting', email => 'highways@example.com' );
my $contact2 = $mech->create_contact_ok( body_id => $body->id, category => 'Potholes', email => 'potholes@example.com' );
@@ -38,7 +36,7 @@ subtest "Body user, has permission to add report as council" => sub {
detail => 'Test report details.',
category => 'Street lighting',
);
- is $report->name, 'Wiltshire Council', 'report name is body';
+ is $report->name, 'Oxfordshire County Council', 'report name is body';
is $report->user->name, 'Body User', 'user name unchanged';
is $report->user->id, $user->id, 'user matches';
is $report->anonymous, 0, 'report not anonymous';
@@ -59,7 +57,7 @@ subtest "Body user, has permission to add report as another user" => sub {
is $report->user->name, 'Another User', 'user name matches';
is $report->user->email, 'another@example.net', 'user email correct';
isnt $report->user->id, $user->id, 'user does not match';
- like $mech->get_text_body_from_email, qr/Your report to Wiltshire Council has been logged/;
+ like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/;
push @users, $report->user;
};
@@ -78,7 +76,7 @@ subtest "Body user, has permission to add report as another (existing) user" =>
is $report->user->name, 'Existing User', 'user name remains same';
is $report->user->email, 'existing@example.net', 'user email correct';
isnt $report->user->id, $user->id, 'user does not match';
- like $mech->get_text_body_from_email, qr/Your report to Wiltshire Council has been logged/;
+ like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/;
push @users, $report->user;
};
@@ -88,7 +86,7 @@ subtest "Body user, has permission to add update as council" => sub {
form_as => 'body',
update => 'Test Update',
);
- is $update->name, 'Wiltshire Council', 'update name is body';
+ is $update->name, 'Oxfordshire County Council', 'update name is body';
is $update->user->name, 'Body User', 'user name unchanged';
is $update->user->id, $user->id, 'user matches';
is $update->anonymous, 0, 'update not anonymous';
@@ -134,7 +132,6 @@ END {
sub start_report {
my $permission = shift;
- LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk');
$_->delete for $user->user_body_permissions;
$user->user_body_permissions->create({ body => $body, permission_type => $permission })
if $permission;
@@ -191,4 +188,3 @@ sub dropdown_shown {
my ($shown, $name) = @_;
is grep({ $_ eq 'form_as' } keys %{$mech->visible_form_values($name)}), $shown, "Dropdown shown = $shown";
}
-
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index fad8b2bbb..b35a4a026 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -210,13 +210,13 @@ foreach my $meta (
$report->update;
subtest "test correct problem meta information" => sub {
$mech->get_ok("/report/$report_id");
-
+
is $mech->extract_problem_meta, $meta->{meta};
};
}
-for my $test (
+for my $test (
{
description => 'new report',
date => DateTime->now,
@@ -385,7 +385,7 @@ for my $test (
my $body_westminster = $mech->create_body_ok(2504, 'Westminster City Council');
my $body_camden = $mech->create_body_ok(2505, 'Camden Borough Council');
-for my $test (
+for my $test (
{
desc => 'no state dropdown if user not from authority',
from_body => undef,
@@ -530,6 +530,57 @@ subtest "Zurich banners are displayed correctly" => sub {
};
};
+my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237);
+my $oxfordshireuser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $oxfordshire);
+
+subtest "check user details show when a user has correct permissions" => sub {
+ $report->update( {
+ name => 'Oxfordshire County Council',
+ user_id => $oxfordshireuser->id,
+ service => '',
+ anonymous => 'f',
+ bodies_str => $oxfordshire->id,
+ confirmed => '2012-01-10 15:17:00'
+ });
+
+ ok $oxfordshireuser->user_body_permissions->create({
+ body => $oxfordshire,
+ permission_type => 'view_body_contribute_details',
+ });
+
+ $mech->log_in_ok( $oxfordshireuser->email );
+ ok $mech->get("/report/$report_id"), "get '/report/$report_id'";
+ is $mech->extract_problem_meta,
+ 'Reported in the Roads category by Oxfordshire County Council (Council User) at 15:17, Tue 10 January 2012',
+ 'correct problem meta information';
+
+ ok $oxfordshireuser->user_body_permissions->delete_all, "Remove view_body_contribute_details permissions";
+
+ ok $mech->get("/report/$report_id"), "get '/report/$report_id'";
+ is $mech->extract_problem_meta,
+ 'Reported in the Roads category by Oxfordshire County Council at 15:17, Tue 10 January 2012',
+ 'correct problem meta information for user without relevant permissions';
+
+ $mech->log_out_ok;
+
+ ok $mech->get("/report/$report_id"), "get '/report/$report_id'";
+ is $mech->extract_problem_meta,
+ 'Reported in the Roads category by Oxfordshire County Council at 15:17, Tue 10 January 2012',
+ 'correct problem meta information for logged out user';
+
+};
+
+subtest "check brackets don't appear when username and report name are the same" => sub {
+ $report->update( {
+ name => 'Council User'
+ });
+
+ $mech->log_in_ok( $oxfordshireuser->email );
+ ok $mech->get("/report/$report_id"), "get '/report/$report_id'";
+ is $mech->extract_problem_meta,
+ 'Reported in the Roads category by Council User at 15:17, Tue 10 January 2012',
+ 'correct problem meta information';
+};
END {
$mech->delete_user('test@example.com');
diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t
index c8cbcf412..b956b61ae 100644
--- a/t/app/controller/report_import.t
+++ b/t/app/controller/report_import.t
@@ -1,13 +1,15 @@
use strict;
use warnings;
use Test::More;
-use LWP::Protocol::PSGI;
-use t::Mock::MapIt;
use FixMyStreet::TestMech;
use FixMyStreet::App;
use Web::Scraper;
use Path::Class;
+use LWP::Protocol::PSGI;
+use t::Mock::MapItZurich;
+
+LWP::Protocol::PSGI->register(t::Mock::MapItZurich->to_psgi_app, host => 'mapit.zurich');
my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/import');
@@ -92,8 +94,6 @@ subtest "Test creating bad partial entries" => sub {
};
subtest "Submit a correct entry" => sub {
- LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk');
-
$mech->get_ok('/import');
$mech->submit_form_ok( #
@@ -156,7 +156,6 @@ subtest "Submit a correct entry" => sub {
phone => '',
may_show_name => '1',
category => '-- Pick a category --',
- gender => undef,
},
"check imported fields are shown";
@@ -193,7 +192,6 @@ subtest "Submit a correct entry" => sub {
phone => '',
may_show_name => '1',
category => '-- Pick a category --',
- gender => undef,
},
"check imported fields are shown";
@@ -261,7 +259,7 @@ subtest "Submit a correct entry (with location)" => sub {
# go to the token url
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok($token_url);
};
@@ -281,14 +279,13 @@ subtest "Submit a correct entry (with location)" => sub {
phone => '',
may_show_name => '1',
category => '-- Pick a category --',
- gender => undef,
},
"check imported fields are shown";
# change the details
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( #
{
@@ -321,7 +318,7 @@ subtest "Submit a correct entry (with location)" => sub {
subtest "Submit a correct entry (with location) to cobrand" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'zurich' ],
- MAPIT_URL => 'http://global.mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.zurich/',
MAPIT_TYPES => [ 'O08' ],
MAPIT_ID_WHITELIST => [],
MAP_TYPE => 'Zurich,OSM',
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 4697cc9d1..69e43ad99 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -34,7 +34,7 @@ my $user = $mech->log_in_ok('test@example.com');
$user->update( { from_body => $oxon } );
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
ALLOWED_COBRANDS => 'fixmystreet',
}, sub {
subtest "test inspect page" => sub {
@@ -57,30 +57,33 @@ FixMyStreet::override_config {
};
subtest "test basic inspect submission" => sub {
- $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Planned' } });
+ $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Action Scheduled', include_update => undef } });
$report->discard_changes;
- is $report->state, 'planned', 'report state changed';
+ is $report->state, 'action scheduled', 'report state changed';
is $report->get_extra_metadata('traffic_information'), 'Yes', 'report data changed';
};
subtest "test inspect & instruct submission" => sub {
$report->unset_extra_metadata('inspected');
+ $report->state('confirmed');
$report->update;
- my $reputation = $report->user->get_extra_metadata("reputation") || 0;
+ $report->inspection_log_entry->delete;
+ my $reputation = $report->user->get_extra_metadata("reputation");
$mech->get_ok("/report/$report_id");
- $mech->submit_form_ok({ button => 'save', with_fields => { public_update => "This is a public update.", save_inspected => "1" } });
+ $mech->submit_form_ok({ button => 'save', with_fields => { public_update => "This is a public update.", include_update => "1", state => 'action scheduled' } });
$report->discard_changes;
is $report->comments->first->text, "This is a public update.", 'Update was created';
is $report->get_extra_metadata('inspected'), 1, 'report marked as inspected';
- is $report->user->get_extra_metadata('reputation'), $reputation+1, "User reputation was increased";
+ is $report->user->get_extra_metadata('reputation'), $reputation, "User reputation wasn't changed";
};
subtest "test update is required when instructing" => sub {
$report->unset_extra_metadata('inspected');
$report->update;
+ $report->inspection_log_entry->delete;
$report->comments->delete_all;
$mech->get_ok("/report/$report_id");
- $mech->submit_form_ok({ button => 'save', with_fields => { public_update => undef, save_inspected => "1" } });
+ $mech->submit_form_ok({ button => 'save', with_fields => { public_update => undef, include_update => "1" } });
is_deeply $mech->page_errors, [ "Please provide a public update for this report." ], 'errors match';
$report->discard_changes;
is $report->comments->count, 0, "Update wasn't created";
@@ -117,7 +120,7 @@ FixMyStreet::override_config {
$report->comments->delete_all;
$mech->get_ok("/report/$report_id");
- $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', duplicate_of => $report2->id, public_update => "This is a duplicate.", save_inspected => "1" } });
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', duplicate_of => $report2->id, public_update => "This is a duplicate.", include_update => "1" } });
$report->discard_changes;
is $report->state, 'duplicate', 'report marked as duplicate';
@@ -136,7 +139,7 @@ FixMyStreet::override_config {
state => 'Duplicate',
duplicate_of => $report2->id,
public_update => $update_text,
- save_inspected => "1",
+ include_update => "1",
}});
$report->discard_changes;
@@ -174,22 +177,43 @@ FixMyStreet::override_config {
};
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
ALLOWED_COBRANDS => 'oxfordshire',
}, sub {
subtest "test negative reputation" => sub {
- my $reputation = $report->user->get_extra_metadata("reputation");
+ my $reputation = $report->user->get_extra_metadata("reputation") || 0;
$mech->get_ok("/report/$report_id");
$mech->submit_form( button => 'remove_from_site' );
$report->discard_changes;
is $report->user->get_extra_metadata('reputation'), $reputation-1, "User reputation was decreased";
+ $report->update({ state => 'confirmed' });
};
+
+ subtest "test positive reputation" => sub {
+ $report->unset_extra_metadata('inspected');
+ $report->update;
+ $report->inspection_log_entry->delete if $report->inspection_log_entry;
+ my $reputation = $report->user->get_extra_metadata("reputation") || 0;
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'action scheduled', include_update => undef } });
+ $report->discard_changes;
+ is $report->get_extra_metadata('inspected'), 1, 'report marked as inspected';
+ is $report->user->get_extra_metadata('reputation'), $reputation+1, "User reputation was increased";
+ };
+
+ subtest "Oxfordshire-specific traffic management options are shown" => sub {
+ $report->update({ state => 'confirmed' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Signs and Cones', state => 'Action Scheduled', include_update => undef } });
+ $report->discard_changes;
+ is $report->state, 'action scheduled', 'report state changed';
+ is $report->get_extra_metadata('traffic_information'), 'Signs and Cones', 'report data changed';
+ };
+
};
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
ALLOWED_COBRANDS => [ 'oxfordshire', 'fixmystreet' ],
BASE_URL => 'http://fixmystreet.site',
}, sub {
@@ -201,7 +225,7 @@ FixMyStreet::override_config {
# which should cause it to be resent. We clear the host because
# otherwise testing stays on host() above.
$mech->clear_host;
- $mech->submit_form(button => 'save', with_fields => { category => 'Horses' });
+ $mech->submit_form(button => 'save', with_fields => { category => 'Horses', include_update => undef, });
$report->discard_changes;
is $report->category, "Horses", "Report in correct category";
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 6b4f40172..71090cd26 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -25,7 +25,7 @@ subtest "test that bare requests to /report/new get redirected" => sub {
is_deeply { $mech->uri->query_form }, {}, "query empty";
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/report/new?pc=SW1A%201AA');
};
@@ -476,7 +476,7 @@ foreach my $test (
# submit initial pc form
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
"submit location" );
@@ -498,7 +498,6 @@ foreach my $test (
my $new_values = {
%{ $test->{fields} }, # values added to form
%{ $test->{changes} }, # changes we expect
- gender => undef,
};
is_deeply $mech->visible_form_values, $new_values,
"values correctly changed";
@@ -550,7 +549,7 @@ foreach my $test (
$mech->get_ok('/around');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
"submit location" );
@@ -666,7 +665,7 @@ subtest "test password errors for a user who is signing in as they report" => su
$mech->get_ok('/around');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
"submit location" );
@@ -718,7 +717,7 @@ subtest "test report creation for a user who is signing in as they report" => su
$mech->get_ok('/around');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
"submit location" );
@@ -814,7 +813,7 @@ foreach my $test (
$mech->get_ok('/around');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } },
"submit location" );
@@ -836,7 +835,6 @@ foreach my $test (
photo2 => '',
photo3 => '',
category => '-- Pick a category --',
- gender => undef,
},
"user's details prefilled"
);
@@ -914,7 +912,7 @@ subtest "test report creation for a category that is non public" => sub {
$mech->get_ok('/around');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
"submit location" );
@@ -976,7 +974,7 @@ $contact2->update;
my $extra_details;
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=' . $saved_lat . '&longitude=' . $saved_lon );
};
@@ -985,7 +983,7 @@ ok !$extra_details->{titles_list}, 'Non Bromley does not send back list of title
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.4021&longitude=0.01578');
};
@@ -1005,7 +1003,7 @@ subtest "check that a lat/lon off coast leads to /around" => sub {
my $off_coast_longitude = -0.646929;
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok( #
"/report/new"
@@ -1027,7 +1025,7 @@ for my $test (
{
desc => 'user title not set if not bromley problem',
host => 'www.fixmystreet.com',
- postcode => 'EH99 1SP',
+ postcode => 'EH1 1BB',
fms_extra_title => '',
extra => [],
user_title => undef,
@@ -1078,7 +1076,7 @@ for my $test (
subtest $test->{desc} => sub {
my $override = {
ALLOWED_COBRANDS => [ $test->{host} =~ /bromley/ ? 'bromley' : 'fixmystreet' ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
};
$mech->host( $test->{host} );
@@ -1195,9 +1193,9 @@ subtest 'user title not reset if no user title in submission' => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
- $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP', } },
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
"submit location" );
$mech->follow_link_ok(
{ text_regex => qr/skip this step/i, },
@@ -1260,7 +1258,7 @@ subtest "test Hart" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'hart', 'fixmystreet' ],
BASE_URL => 'http://www.fixmystreet.com',
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/around');
$mech->content_contains( "Hart Council" );
@@ -1365,133 +1363,18 @@ subtest "test Hart" => sub {
}
};
-subtest "test SeeSomething" => sub {
- $mech->host('seesomething.fixmystreet.com');
- $mech->clear_emails_ok;
- $mech->log_out_ok;
-
- my $cobrand = FixMyStreet::Cobrand::SeeSomething->new();
-
- my $body_ss = $mech->create_body_ok(2535, 'Sandwell Borough Council', id => 2535);
- my $bus_contact = $mech->create_contact_ok(
- body_id => $body_ss->id,
- category => 'Bus',
- email => 'bus@example.com',
- non_public => 1,
- );
-
- for my $test ( {
- desc => 'report with no user details works',
- pc => 'WS1 4NH',
- fields => {
- detail => 'Test report details',
- category => 'Bus',
- subcategory => 'Smoking',
- },
- email => $cobrand->anonymous_account->{email},
- },
- {
- desc => 'report with user details works',
- pc => 'WS1 4NH',
- fields => {
- detail => 'Test report details',
- category => 'Bus',
- subcategory => 'Smoking',
- email => 'non_anon_user@example.com',
- name => 'Non Anon',
- },
- email => 'non_anon_user@example.com',
- },
- {
- desc => 'report with public category',
- pc => 'WS1 4NH',
- fields => {
- detail => 'Test report details',
- category => 'Bus',
- subcategory => 'Smoking',
- },
- email => $cobrand->anonymous_account->{email},
- public => 1,
- }
- ) {
- subtest $test->{desc} => sub {
- $mech->clear_emails_ok;
- my $user =
- FixMyStreet::App->model('DB::User')->find( { email => $test->{email} } );
-
- if ( $user ) {
- $user->alerts->delete;
- $user->problems->delete;
- $user->delete;
- }
-
- if ( $test->{public} ) {
- $bus_contact->non_public(0);
- $bus_contact->update;
- } else {
- $bus_contact->non_public(1);
- $bus_contact->update;
- }
-
- $mech->get_ok( '/around' );
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'seesomething' ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
- }, sub {
- $mech->submit_form_ok(
- {
- with_fields => {
- pc => $test->{pc},
- },
- },
- 'submit around form',
- );
- $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
-
- $mech->submit_form_ok(
- {
- with_fields => $test->{fields},
- },
- 'Submit form details with no user details',
- );
- };
- is_deeply $mech->page_errors, [], "check there were no errors";
-
- $user =
- FixMyStreet::App->model('DB::User')->find( { email => $test->{email} } );
- ok $user, "user found";
-
- my $report = $user->problems->first;
- ok $report, "Found the report";
-
- $mech->email_count_is(0);
-
- ok $report->confirmed, 'Report is confirmed automatically';
-
- is $mech->uri->path, '/report/new', 'stays on report/new page';
- $mech->content_contains( 'Your report has been sent', 'use report created template' );
-
- $user->alerts->delete;
- $user->problems->delete;
- $user->delete;
- };
- }
-
- $bus_contact->delete;
-};
-
subtest "categories from deleted bodies shouldn't be visible for new reports" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
- $mech->get_ok('/report/new/ajax?latitude=51.89&longitude=-2.09'); # Cheltenham
+ $mech->get_ok('/report/new/ajax?latitude=51.896268&longitude=-2.093063'); # Cheltenham
ok $mech->content_contains( $contact3->category );
# Delete the body which the contact belongs to.
$contact3->body->update( { deleted => 1 } );
- $mech->get_ok('/report/new/ajax?latitude=51.89&longitude=-2.09'); # Cheltenham
+ $mech->get_ok('/report/new/ajax?latitude=51.896268&longitude=-2.093063'); # Cheltenham
ok $mech->content_lacks( $contact3->category );
$contact3->body->update( { deleted => 0 } );
@@ -1501,12 +1384,12 @@ subtest "categories from deleted bodies shouldn't be visible for new reports" =>
subtest "unresponsive body handling works" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
# Test body-level send method
my $old_send = $contact1->body->send_method;
$contact1->body->update( { send_method => 'Refused' } );
- $mech->get_ok('/report/new/ajax?latitude=55.9&longitude=-3.2'); # Edinburgh
+ $mech->get_ok('/report/new/ajax?latitude=55.952055&longitude=-3.189579'); # Edinburgh
my $body_id = $contact1->body->id;
ok $mech->content_like( qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id} );
@@ -1555,8 +1438,8 @@ subtest "unresponsive body handling works" => sub {
phone => '07903 123 456',
category => 'Trees',
service => 'iOS',
- lat => 55.9,
- lon => -3.2,
+ lat => 55.952055,
+ lon => -3.189579,
pc => '',
used_map => '1',
submit_register => '1',
@@ -1582,7 +1465,7 @@ subtest "unresponsive body handling works" => sub {
# And test per-category refusing
my $old_email = $contact3->email;
$contact3->update( { email => 'REFUSED' } );
- $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.89&longitude=-2.09');
+ $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063');
ok $mech->content_like( qr/Cheltenham.*Trees.*unresponsive.*category=Trees/ );
$mech->get_ok('/around');
@@ -1616,7 +1499,6 @@ subtest "unresponsive body handling works" => sub {
subtest "unresponsive body page works" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
}, sub {
my $old_send = $contact1->body->send_method;
my $body_id = $contact1->body->id;
@@ -1643,7 +1525,7 @@ subtest "extra google analytics code displayed on logged in problem creation" =>
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
BASE_URL => 'https://www.fixmystreet.com',
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
# check that the user does not exist
my $test_email = 'test-2@example.com';
@@ -1672,7 +1554,7 @@ subtest "extra google analytics code displayed on logged in problem creation" =>
$mech->submit_form_ok(
{
with_fields => {
- title => "Test Report at café",
+ title => "Test Report at café",
detail => 'Test report details.',
photo1 => '',
name => 'Joe Bloggs',
@@ -1699,7 +1581,7 @@ subtest "extra google analytics code displayed on email confirmation problem cre
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
BASE_URL => 'https://www.fixmystreet.com',
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->log_out_ok;
$mech->clear_emails_ok;
diff --git a/t/app/controller/report_new_mobile.t b/t/app/controller/report_new_mobile.t
index 61cb14a1b..3dfb99b2f 100644
--- a/t/app/controller/report_new_mobile.t
+++ b/t/app/controller/report_new_mobile.t
@@ -1,5 +1,7 @@
use Test::More;
use FixMyStreet::TestMech;
+use LWP::Protocol::PSGI;
+use t::Mock::MapItZurich;
my $mech = FixMyStreet::TestMech->new;
@@ -7,10 +9,12 @@ my $mech = FixMyStreet::TestMech->new;
FixMyStreet::App->log->disable('info');
END { FixMyStreet::App->log->enable('info'); }
+LWP::Protocol::PSGI->register(t::Mock::MapItZurich->to_psgi_app, host => 'mapit.zurich');
+
subtest "Check signed up for alert when logged in" => sub {
FixMyStreet::override_config {
- MAPIT_URL => 'http://global.mapit.mysociety.org',
- MAPIT_TYPES => [ 'O06' ],
+ MAPIT_URL => 'http://mapit.zurich',
+ MAPIT_TYPES => [ 'O08' ],
}, sub {
$mech->log_in_ok('user@example.org');
$mech->post_ok( '/report/new/mobile', {
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index db6e07933..e3a464f88 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -12,7 +12,7 @@ END { FixMyStreet::App->log->enable('info'); }
my $mech = FixMyStreet::TestMech->new;
-my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council');
+my $body = $mech->create_body_ok(2245, 'Wiltshire Council');
$body->update({
endpoint => 'http://example.com/open311',
jurisdiction => 'mySociety',
@@ -27,7 +27,7 @@ my $contact1 = $mech->create_contact_ok(
extra => [ { description => 'Lamppost number', code => 'number', required => 'True' },
{ description => 'Lamppost type', code => 'type', required => 'False', values =>
{ value => [ { name => ['Gas'], key => ['old'] }, { name => [ 'Yellow' ], key => [ 'modern' ] } ] }
- }
+ }
],
);
my $contact1b = $mech->create_contact_ok(
@@ -117,7 +117,7 @@ foreach my $test (
# submit initial pc form
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
"submit location" );
@@ -139,7 +139,6 @@ foreach my $test (
my $new_values = {
%{ $test->{fields} }, # values added to form
%{ $test->{changes} }, # changes we expect
- gender => undef,
};
is_deeply $mech->visible_form_values, $new_values,
"values correctly changed";
@@ -159,7 +158,7 @@ foreach my $test (
};
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => $new_values } );
};
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index 5a88097fa..de153978b 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -131,6 +131,19 @@ for my $test (
};
}
+subtest "updates displayed on report with empty bodies_str" => sub {
+ my $old_bodies_str = $report->bodies_str;
+ $report->update({ bodies_str => undef });
+ $comment->update({ problem_state => 'fixed' , mark_open => 'false', mark_fixed => 'false' });
+
+ $mech->get_ok("/report/$report_id");
+
+ my $meta = $mech->extract_update_metas;
+ is scalar @$meta, 1, 'update displayed';
+
+ $report->update({ bodies_str => $old_bodies_str });
+};
+
subtest "unconfirmed updates not displayed" => sub {
$comment->state( 'unconfirmed' );
$comment->update;
@@ -594,7 +607,7 @@ for my $test (
name => $user->name,
may_show_name => 1,
update => 'Set state to unable to fix',
- state => 'unable to fix',
+ state => 'no further action',
},
state => 'unable to fix',
},
@@ -653,6 +666,18 @@ for my $test (
state => 'fixed - council',
report_bodies => $body->id . ',2505',
},
+ {
+ desc => 'from authority user show username for users with correct permissions',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ update => 'Set state to fixed',
+ state => 'fixed',
+ },
+ state => 'fixed - council',
+ report_bodies => $body->id . ',2505',
+ view_username => 1
+ },
) {
subtest $test->{desc} => sub {
$report->comments->delete;
@@ -662,6 +687,14 @@ for my $test (
}
$mech->log_in_ok( $user->email );
+
+ if ($test->{view_username}) {
+ ok $user->user_body_permissions->create({
+ body => $body,
+ permission_type => 'view_body_contribute_details'
+ }), 'Give user view_body_contribute_details permissions';
+ }
+
$user->from_body( $body->id );
$user->update;
@@ -690,8 +723,14 @@ for my $test (
} else {
like $update_meta->[0], qr/marked as $meta_state$/, 'update meta includes state change';
}
- like $update_meta->[0], qr{Test User \(Westminster City Council\)}, 'update meta includes council name';
- $mech->content_contains( 'Test User (<strong>Westminster City Council</strong>)', 'council name in bold');
+
+ if ($test->{view_username}) {
+ like $update_meta->[0], qr{Westminster City Council \(Test User\)}, 'update meta includes council and user name';
+ $user->user_body_permissions->delete_all;
+ } else {
+ like $update_meta->[0], qr{Westminster City Council}, 'update meta includes council name';
+ $mech->content_contains( '<strong>Westminster City Council</strong>', 'council name in bold');
+ }
$report->discard_changes;
is $report->state, $test->{state}, 'state set';
@@ -1829,7 +1868,8 @@ for my $test (
subtest 'check have to be logged in for creator fixed questionnaire' => sub {
$mech->log_out_ok();
- $mech->get_ok( "/questionnaire/submit?problem=$report_id&reported=Yes" );
+ $mech->get( "/questionnaire/submit?problem=$report_id&reported=Yes" );
+ is $mech->res->code, 400, "got 400";
$mech->content_contains( "I'm afraid we couldn't locate your problem in the database." )
};
@@ -1838,7 +1878,8 @@ subtest 'check cannot answer other user\'s creator fixed questionnaire' => sub {
$mech->log_out_ok();
$mech->log_in_ok( $user2->email );
- $mech->get_ok( "/questionnaire/submit?problem=$report_id&reported=Yes" );
+ $mech->get( "/questionnaire/submit?problem=$report_id&reported=Yes" );
+ is $mech->res->code, 400, "got 400";
$mech->content_contains( "I'm afraid we couldn't locate your problem in the database." )
};
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index 141269cd8..a21d3ad65 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -107,7 +107,7 @@ is $stats->{'Fife Council'}->[4], 3, 'correct number of fixed reports for Fife';
is $stats->{'Fife Council'}->[5], 1, 'correct number of older fixed reports for Fife';
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->follow_link_ok( { text_regex => qr/Birmingham/ } );
$mech->get_ok('/reports/Westminster');
@@ -121,7 +121,7 @@ my $problems = $mech->extract_problem_list;
is scalar @$problems, 5, 'correct number of problems displayed';
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/reports');
$mech->follow_link_ok({ url_regex => qr{/reports/Electricity_Gas\+Council} });
@@ -133,7 +133,7 @@ $problems = $mech->extract_problem_list;
is scalar @$problems, 2, 'correct number of new problems displayed';
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/reports/City+of+Edinburgh?t=older');
};
@@ -169,7 +169,7 @@ for my $test (
) {
subtest $test->{desc} => sub {
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/reports/Fife+Council?t=' . $test->{type});
};
@@ -183,7 +183,7 @@ my $private = $westminster_problems[2];
ok $private->update( { non_public => 1 } ), 'problem marked non public';
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/reports/Westminster');
};
@@ -213,7 +213,7 @@ subtest "test fiksgatami all reports page" => sub {
subtest "test greenwich all reports page" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'greenwich' ],
- MAPIT_URL => 'http://mapit.mysociety.org/'
+ MAPIT_URL => 'http://mapit.uk/'
}, sub {
my $body = $mech->create_body_ok(2493, 'Royal Borough of Greenwich');
my $deleted_contact = $mech->create_contact_ok(
@@ -233,5 +233,54 @@ subtest "test greenwich all reports page" => sub {
}
};
-done_testing();
+subtest "it lists shortlisted reports" => sub {
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/'
+ }, sub {
+ my $body = FixMyStreet::App->model('DB::Body')->find( $body_edin_id );
+ my $user = $mech->log_in_ok( 'test@example.com' );
+ $user->update({ from_body => $body });
+ $user->user_body_permissions->find_or_create({
+ body => $body,
+ permission_type => 'planned_reports',
+ });
+
+ my ($shortlisted_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Shortlisted report');
+ my ($unshortlisted_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Unshortlisted report');
+ my ($removed_from_shortlist_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Removed from shortlist report');
+
+ $user->add_to_planned_reports($shortlisted_problem);
+ $user->add_to_planned_reports($removed_from_shortlist_problem);
+ $user->remove_from_planned_reports($removed_from_shortlist_problem);
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council');
+ $mech->content_contains('<option value="shortlisted">Shortlisted</option>');
+ $mech->content_contains('<option value="unshortlisted">Unshortlisted</option>');
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council?status=shortlisted');
+
+ $mech->content_contains('Shortlisted report');
+ $mech->content_lacks('Unshortlisted report');
+ $mech->content_lacks('Removed from shortlist report');
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council?status=shortlisted,open');
+ $mech->content_contains('Shortlisted report');
+ $mech->content_lacks('Unshortlisted report');
+ $mech->content_lacks('Removed from shortlist report');
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council?status=unshortlisted,open');
+
+ $mech->content_contains('Unshortlisted report');
+ $mech->content_contains('Removed from shortlist report');
+ $mech->content_lacks('Shortlisted report');
+
+ $user->admin_user_body_permissions->delete;
+
+ $mech->get_ok('/reports/City+of+Edinburgh+Council');
+ $mech->content_lacks('<option value="shortlisted">Shortlisted</option>');
+ $mech->content_lacks('<option value="unshortlisted">Unshortlisted</option>');
+ };
+};
+
+done_testing();
diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t
index 4f737dda7..bec504760 100644
--- a/t/app/controller/rss.t
+++ b/t/app/controller/rss.t
@@ -44,7 +44,7 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
$mech->host('www.fixmystreet.com');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fixmystreet' ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok("/rss/pc/EH11BB/2");
};
@@ -118,7 +118,7 @@ $report->update();
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fixmystreet' ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok("/rss/pc/EH11BB/2");
};
@@ -186,7 +186,7 @@ subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" =
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'hart' ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok("/rss/area/Hart");
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('hart')->new();
diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t
index 3975002fa..66b771292 100644
--- a/t/app/helpers/send_email.t
+++ b/t/app/helpers/send_email.t
@@ -19,7 +19,6 @@ use Test::LongString;
use Catalyst::Test 'FixMyStreet::App';
-use Email::Send::Test;
use Path::Tiny;
use FixMyStreet::TestMech;
@@ -31,7 +30,7 @@ my $c = ctx_request("/");
$c->stash->{foo} = 'bar';
# clear the email queue
-Email::Send::Test->clear;
+$mech->clear_emails_ok;
# send the test email
FixMyStreet::override_config {
@@ -42,7 +41,7 @@ FixMyStreet::override_config {
};
# check it got templated and sent correctly
-my @emails = Email::Send::Test->emails;
+my @emails = $mech->get_email;
is scalar(@emails), 1, "caught one email";
# Get the email, check it has a date and then strip it out
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index 4e8817225..5e4fcec0a 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -188,7 +188,7 @@ subtest "correct text for title after URL" => sub {
}
)->delete;
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
FixMyStreet::DB->resultset('AlertType')->email_alerts();
};
@@ -324,7 +324,7 @@ foreach my $test (
$report->update();
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
FixMyStreet::DB->resultset('AlertType')->email_alerts();
};
@@ -432,7 +432,7 @@ subtest "check alerts from cobrand send main site url for alerts for different c
)->delete;
FixMyStreet::override_config {
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
FixMyStreet::DB->resultset('AlertType')->email_alerts();
};
diff --git a/t/app/model/defecttype.t b/t/app/model/defecttype.t
new file mode 100644
index 000000000..0f66ac684
--- /dev/null
+++ b/t/app/model/defecttype.t
@@ -0,0 +1,67 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FixMyStreet::App;
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237);
+my $potholes_contact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' );
+my $traffic_lights_contact =$mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' );
+
+my $potholes_defect_type = FixMyStreet::App->model('DB::DefectType')->find_or_create(
+ {
+ body_id => 2237,
+ name => 'Potholes',
+ description => 'This defect type is to do with potholes'
+ }
+);
+$potholes_defect_type->contact_defect_types->find_or_create({
+ contact_id => $potholes_contact->id,
+});
+
+my $general_defect_type = FixMyStreet::App->model('DB::DefectType')->find_or_create(
+ {
+ body_id => 2237,
+ name => 'All categories',
+ description => 'This defect type is for all categories'
+ }
+);
+
+
+subtest 'for_bodies returns correct results' => sub {
+ my $defect_types = FixMyStreet::App->model('DB::DefectType')->for_bodies(
+ [ $oxfordshire->id ],
+ 'Potholes'
+ );
+
+ is $defect_types->count, 2, 'Both defect types are included for Potholes category';
+
+ $defect_types = FixMyStreet::App->model('DB::DefectType')->for_bodies(
+ [ $oxfordshire->id ],
+ 'Traffic lights'
+ );
+
+ is $defect_types->count, 1, 'Only 1 defect type is included for Traffic lights category';
+ is $defect_types->first->name, $general_defect_type->name, 'Correct defect type is returned for Traffic lights category';
+};
+
+subtest 'Problem->defect_types behaves correctly' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Test', {
+ category => 'Potholes',
+ });
+
+ is $problem->defect_types->count, 2, 'Both defect types are available for the problem';
+
+ $problem->update({ category => 'Traffic lights' });
+ is $problem->defect_types->count, 1, 'Only 1 defect type is included for Traffic lights category';
+ is $problem->defect_types->first->name, $general_defect_type->name, 'Correct defect type is returned for Traffic lights category';
+};
+
+
+END {
+ $mech->delete_body( $oxfordshire );
+
+ done_testing();
+}
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 1130078c0..6b1be0a76 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -5,6 +5,7 @@ use Test::More;
use FixMyStreet::TestMech;
use FixMyStreet;
+use FixMyStreet::App;
use FixMyStreet::DB;
use mySociety::Locale;
use Sub::Override;
@@ -53,7 +54,7 @@ is $problem->whensent, undef, 'inflating null confirmed ok';
is $problem->lastupdate, undef, 'inflating null confirmed ok';
is $problem->created, undef, 'inflating null confirmed ok';
-for my $test (
+for my $test (
{
desc => 'more or less empty problem',
changed => {},
@@ -147,7 +148,7 @@ for my $test (
my $user = FixMyStreet::DB->resultset('User')->find_or_create(
{
- email => 'system_user@example.com'
+ email => 'system_user@example.net'
}
);
@@ -242,12 +243,13 @@ for my $test (
};
}
-for my $test (
+for my $test (
{
state => 'partial',
is_visible => 0,
is_fixed => 0,
is_open => 0,
+ is_in_progress => 0,
is_closed => 0,
},
{
@@ -255,6 +257,7 @@ for my $test (
is_visible => 0,
is_fixed => 0,
is_open => 0,
+ is_in_progress => 0,
is_closed => 0,
},
{
@@ -262,6 +265,7 @@ for my $test (
is_visible => 0,
is_fixed => 0,
is_open => 0,
+ is_in_progress => 0,
is_closed => 0,
},
{
@@ -269,6 +273,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 1,
+ is_in_progress => 0,
is_closed => 0,
},
{
@@ -276,6 +281,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 1,
+ is_in_progress => 1,
is_closed => 0,
},
{
@@ -283,6 +289,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 1,
+ is_in_progress => 1,
is_closed => 0,
},
{
@@ -290,6 +297,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 1,
+ is_in_progress => 1,
is_closed => 0,
},
{
@@ -297,6 +305,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 1,
+ is_in_progress => 1,
is_closed => 0,
},
{
@@ -304,6 +313,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 0,
+ is_in_progress => 0,
is_closed => 1,
},
{
@@ -311,6 +321,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 0,
+ is_in_progress => 0,
is_closed => 1,
},
{
@@ -318,6 +329,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 0,
+ is_in_progress => 0,
is_closed => 1,
},
{
@@ -325,6 +337,7 @@ for my $test (
is_visible => 1,
is_fixed => 1,
is_open => 0,
+ is_in_progress => 0,
is_closed => 0,
},
{
@@ -332,6 +345,7 @@ for my $test (
is_visible => 1,
is_fixed => 1,
is_open => 0,
+ is_in_progress => 0,
is_closed => 0,
},
{
@@ -339,6 +353,7 @@ for my $test (
is_visible => 1,
is_fixed => 1,
is_open => 0,
+ is_in_progress => 0,
is_closed => 0,
},
{
@@ -346,6 +361,7 @@ for my $test (
is_visible => 1,
is_fixed => 0,
is_open => 0,
+ is_in_progress => 0,
is_closed => 1,
},
) {
@@ -355,6 +371,7 @@ for my $test (
is $problem->is_fixed, $test->{is_fixed}, 'is_fixed';
is $problem->is_closed, $test->{is_closed}, 'is_closed';
is $problem->is_open, $test->{is_open}, 'is_open';
+ is $problem->is_in_progress, $test->{is_in_progress}, 'is_in_progress';
};
}
@@ -411,7 +428,7 @@ for my $contact ( {
}, {
body_id => $body_ids{14279}[0], # Ballymoney
category => 'Graffiti',
- email => 'highways@example.com',
+ email => 'highways@example.net',
}, {
confirmed => 0,
body_id => $body_ids{2636}, # Isle of Wight
@@ -422,7 +439,7 @@ for my $contact ( {
}
my %common = (
- email => 'system_user@example.com',
+ email => 'system_user@example.net',
name => 'Andrew Smith',
);
foreach my $test ( {
@@ -488,6 +505,9 @@ foreach my $test ( {
body => $body_ids{14279}[0],
category => 'Graffiti',
longitude => -6.5,
+ # As Ballmoney contact has same domain as reporter, the From line will
+ # become a unique reply address and Reply-To will become the reporter
+ reply_to => 1,
}, {
%common,
desc => 'directs NI correctly, 2',
@@ -546,7 +566,12 @@ foreach my $test ( {
if ( $test->{ email_count } ) {
my $email = $mech->get_email;
like $email->header('To'), $test->{ to }, 'to line looks correct';
- is $email->header('From'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'from line looks correct';
+ if ($test->{reply_to}) {
+ is $email->header('Reply-To'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'Reply-To line looks correct';
+ like $email->header('From'), qr/"$test->{name}" <fms-report-\d+-\w+\@example.org>/, 'from line looks correct';
+ } else {
+ is $email->header('From'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'from line looks correct';
+ }
like $email->header('Subject'), qr/A Title/, 'subject line looks correct';
my $body = $mech->get_text_body_from_email($email);
like $body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
@@ -654,7 +679,7 @@ subtest 'check can turn on report sent email alerts' => sub {
my $email = $emails[0];
like $email->header('To'),qr/City of Edinburgh Council/, 'to line looks correct';
- is $email->header('From'), '"Test User" <system_user@example.com>', 'from line looks correct';
+ is $email->header('From'), '"Test User" <system_user@example.net>', 'from line looks correct';
like $email->header('Subject'), qr/A Title/, 'subject line looks correct';
my $body = $mech->get_text_body_from_email($email);
like $body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
@@ -774,6 +799,89 @@ subtest 'check duplicate reports' => sub {
is $problem2->duplicates->[0]->title, $problem1->title, 'problem2 includes problem1 in duplicates';
};
+subtest 'generates a tokenised url for a user' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE');
+ my $url = $problem->tokenised_url($user);
+ (my $token = $url) =~ s/\/M\///g;
+
+ like $url, qr/\/M\//, 'problem generates tokenised url';
+
+ my $token_obj = FixMyStreet::App->model('DB::Token')->find( {
+ scope => 'email_sign_in', token => $token
+ } );
+ is $token, $token_obj->token, 'token is generated in database with correct scope';
+ is $token_obj->data->{r}, $problem->url, 'token has correct redirect data';
+};
+
+subtest 'stores params in a token' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE');
+ my $url = $problem->tokenised_url($user, { foo => 'bar', baz => 'boo'});
+ (my $token = $url) =~ s/\/M\///g;
+
+ my $token_obj = FixMyStreet::App->model('DB::Token')->find( {
+ scope => 'email_sign_in', token => $token
+ } );
+
+ is_deeply $token_obj->data->{p}, { foo => 'bar', baz => 'boo'}, 'token has correct params';
+};
+
+subtest 'get report time ago in appropriate format' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE');
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( minutes => 2)
+ } );
+ is $problem->time_ago, '2 minutes', 'problem returns time ago in minutes';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( hours => 18)
+ } );
+ is $problem->time_ago, '18 hours', 'problem returns time ago in hours';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( days => 4)
+ } );
+ is $problem->time_ago, '4 days', 'problem returns time ago in days';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( weeks => 3 )
+ } );
+ is $problem->time_ago, '3 weeks', 'problem returns time ago in weeks';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( months => 4 )
+ } );
+ is $problem->time_ago, '4 months', 'problem returns time ago in months';
+
+ $problem->update( {
+ confirmed => DateTime->now->subtract( years => 2 )
+ } );
+ is $problem->time_ago, '2 years', 'problem returns time ago in years';
+};
+
+subtest 'time ago works with other dates' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE');
+
+ $problem->update( {
+ lastupdate => DateTime->now->subtract( days => 4)
+ } );
+ is $problem->time_ago('lastupdate'), '4 days', 'problem returns last updated time ago in days';
+};
+
+subtest 'return how many days ago a problem was reported' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE');
+ $problem->update( {
+ confirmed => DateTime->now->subtract( weeks => 2 )
+ } );
+ is $problem->days_ago, 14, 'days_ago returns the amount of days';
+
+ $problem->update( {
+ lastupdate => DateTime->now->subtract( days => 4)
+ } );
+
+ is $problem->days_ago('lastupdate'), 4, 'days_ago allows other dates to be specified';
+};
+
END {
$problem->comments->delete if $problem;
$problem->delete if $problem;
diff --git a/t/app/model/user.t b/t/app/model/user.t
index bf73a9d09..d4115d586 100644
--- a/t/app/model/user.t
+++ b/t/app/model/user.t
@@ -14,7 +14,7 @@ is $problem->user->latest_anonymity, 0, "User's last report was not anonymous";
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/around?pc=sw1a1aa');
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
@@ -32,7 +32,7 @@ is $problem->user->latest_anonymity, 1, "User's last update was anonymous";
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/around?pc=sw1a1aa');
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
diff --git a/t/app/script/archive_old_enquiries.t b/t/app/script/archive_old_enquiries.t
new file mode 100644
index 000000000..e87d6a0f8
--- /dev/null
+++ b/t/app/script/archive_old_enquiries.t
@@ -0,0 +1,163 @@
+use strict;
+use warnings;
+use Test::More;
+use FixMyStreet::TestMech;
+use FixMyStreet::Script::ArchiveOldEnquiries;
+
+mySociety::Locale::gettext_domain( 'FixMyStreet' );
+
+my $mech = FixMyStreet::TestMech->new();
+
+$mech->clear_emails_ok;
+
+my $opts = {
+ commit => 1,
+};
+
+my $user = $mech->create_user_ok('test@example.com', name => 'Test User');
+my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237);
+my $west_oxon = $mech->create_body_ok(2420, 'West Oxfordshire District Council', id => 2420);
+
+subtest 'sets reports to the correct status' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'oxfordshire' ],
+ }, sub {
+ my ($report) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Test', {
+ areas => ',2237,',
+ user_id => $user->id,
+ });
+
+ my ($report1) = $mech->create_problems_for_body(1, $oxfordshire->id . "," .$west_oxon->id, 'Test', {
+ areas => ',2237,',
+ lastupdate => '2015-12-01 07:00:00',
+ user => $user,
+ });
+
+ my ($report2) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Test 2', {
+ areas => ',2237,',
+ lastupdate => '2015-12-01 08:00:00',
+ user => $user,
+ state => 'investigating',
+ });
+
+ my ($report3, $report4) = $mech->create_problems_for_body(2, $oxfordshire->id, 'Test', {
+ areas => ',2237,',
+ lastupdate => '2014-12-01 07:00:00',
+ user => $user,
+ });
+
+ my ($report5) = $mech->create_problems_for_body(1, $oxfordshire->id . "," .$west_oxon->id, 'Test', {
+ areas => ',2237,',
+ lastupdate => '2014-12-01 07:00:00',
+ user => $user,
+ state => 'in progress'
+ });
+
+ FixMyStreet::Script::ArchiveOldEnquiries::archive($opts);
+
+ $report->discard_changes;
+ $report1->discard_changes;
+ $report2->discard_changes;
+ $report3->discard_changes;
+ $report4->discard_changes;
+ $report5->discard_changes;
+
+ is $report1->state, 'closed', 'Report 1 has been set to closed';
+ is $report2->state, 'closed', 'Report 2 has been set to closed';
+ is $report3->state, 'closed', 'Report 3 has been set to closed';
+ is $report4->state, 'closed', 'Report 4 has been set to closed';
+ is $report5->state, 'closed', 'Report 5 has been set to closed';
+
+ is $report->state, 'confirmed', 'Recent report has been left alone';
+ };
+};
+
+subtest 'sends emails to a user' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'oxfordshire' ],
+ }, sub {
+ $mech->clear_emails_ok;
+ $mech->email_count_is(0);
+
+ $mech->create_problems_for_body(1, $oxfordshire->id, 'Shiny new report', {
+ areas => ',2237,',
+ user => $user,
+ });
+
+ $mech->create_problems_for_body(1, $oxfordshire->id, 'Problem the first', {
+ areas => ',2237,',
+ lastupdate => '2015-12-01 07:00:00',
+ user => $user,
+ });
+
+ $mech->create_problems_for_body(1, $oxfordshire->id, 'Problem the second', {
+ areas => ',2237,',
+ lastupdate => '2015-12-01 07:00:00',
+ user => $user,
+ });
+
+ $mech->create_problems_for_body(1, $oxfordshire->id, 'Problem the third', {
+ areas => ',2237,',
+ lastupdate => '2015-12-01 07:00:00',
+ user => $user,
+ });
+
+ $mech->create_problems_for_body(1, $oxfordshire->id, 'Really old report', {
+ areas => ',2237,',
+ lastupdate => '2014-12-01 07:00:00',
+ user => $user,
+ });
+
+ FixMyStreet::Script::ArchiveOldEnquiries::archive($opts);
+
+ my @emails = $mech->get_email;
+ $mech->email_count_is(1);
+
+ my $email = $emails[0];
+ my $body = $mech->get_text_body_from_email($email);
+
+ like $body, qr/Problem the first/, 'Email body matches report name';
+ like $body, qr/Problem the second/, 'Email body matches report name';
+ like $body, qr/Problem the third/, 'Email body matches report name';
+
+ unlike $body, qr/Shiny new report/, 'Email body does not have new report';
+ unlike $body, qr/Really old report/, 'Email body does not have old report';
+ };
+};
+
+subtest 'user with old reports does not get email' => sub {
+ $mech->clear_emails_ok;
+ $mech->email_count_is(0);
+
+ $mech->create_problems_for_body(4, $oxfordshire->id, 'Really old report', {
+ areas => ',2237,',
+ lastupdate => '2014-12-01 07:00:00',
+ user => $user,
+ });
+
+ FixMyStreet::Script::ArchiveOldEnquiries::archive($opts);
+
+ my @emails = $mech->get_email;
+ $mech->email_count_is(0);
+};
+
+subtest 'user with new reports does not get email' => sub {
+ $mech->clear_emails_ok;
+ $mech->email_count_is(0);
+
+ $mech->create_problems_for_body(4, $oxfordshire->id, 'Shiny new report', {
+ areas => ',2237,',
+ user => $user,
+ });
+
+ FixMyStreet::Script::ArchiveOldEnquiries::archive($opts);
+
+ $mech->email_count_is(0);
+};
+
+done_testing();
+
+END {
+ $mech->delete_user($user);
+ $mech->delete_body($oxfordshire);
+}
diff --git a/t/app/sendreport/open311.t b/t/app/sendreport/open311.t
new file mode 100644
index 000000000..c4c17577c
--- /dev/null
+++ b/t/app/sendreport/open311.t
@@ -0,0 +1,267 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Deep;
+
+use Open311;
+use FixMyStreet::SendReport::Open311;
+use FixMyStreet::DB;
+
+use Data::Dumper;
+
+package main;
+sub test_overrides; # defined below
+
+use constant TEST_USER_EMAIL => 'fred@example.com';
+
+my %standard_open311_parameters = (
+ 'use_extended_updates' => 0,
+ 'send_notpinpointed' => 0,
+ 'extended_description' => 1,
+ 'use_service_as_deviceid' => 0,
+ 'extended_statuses' => 0,
+ 'always_send_latlong' => 1,
+ 'debug' => 0,
+ 'error' => '',
+ 'endpoints' => {
+ 'requests' => 'requests.xml',
+ 'service_request_updates' => 'servicerequestupdates.xml',
+ 'services' => 'services.xml',
+ 'update' => 'servicerequestupdates.xml',
+ },
+);
+
+test_overrides oxfordshire =>
+ {
+ body_name => 'Oxfordshire',
+ body_id => 2237,
+ row_data => {
+ postcode => 'OX1 1AA',
+ },
+ extra => {
+ northing => 100,
+ easting => 100,
+ closest_address => '49 St Giles',
+ },
+ },
+ superhashof({
+ handler => isa('FixMyStreet::Cobrand::Oxfordshire'),
+ discard_changes => 1,
+ 'open311' => noclass(superhashof({
+ %standard_open311_parameters,
+ 'extended_description' => 'oxfordshire',
+ 'endpoints' => {
+ 'requests' => 'open311_service_request.cgi'
+ },
+ })),
+ problem_extra => bag(
+ { name => 'northing', value => 100 },
+ { name => 'easting', value => 100 },
+ { name => 'closest_address' => value => '49 St Giles' },
+ { name => 'external_id', value => re('[0-9]+') },
+ ),
+ });
+
+my $bromley_check =
+ superhashof({
+ handler => isa('FixMyStreet::Cobrand::Bromley'),
+ discard_changes => 1,
+ 'open311' => noclass(superhashof({
+ %standard_open311_parameters,
+ 'send_notpinpointed' => 1,
+ 'extended_description' => 0,
+ 'use_service_as_deviceid' => 0,
+ 'always_send_latlong' => 0,
+ })),
+ problem_extra => bag(
+ { name => 'report_url' => value => 'http://example.com/1234' },
+ { name => 'report_title', value => 'Problem' },
+ { name => 'public_anonymity_required', value => 'TRUE' },
+ { name => 'email_alerts_requested', value => 'FALSE' },
+ { name => 'requested_datetime', value => re(qr/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) },
+ { name => 'email', value => TEST_USER_EMAIL },
+ { name => 'last_name', value => 'Bloggs' },
+ ),
+ });
+
+test_overrides bromley =>
+ {
+ body_name => 'Bromley',
+ body_id => 2482,
+ row_data => {
+ postcode => 'BR1 1AA',
+ extra => [ { name => 'last_name', value => 'Bloggs' } ],
+ },
+ extra => {
+ northing => 100,
+ easting => 100,
+ url => 'http://example.com/1234',
+ },
+ },
+ $bromley_check;
+
+test_overrides fixmystreet =>
+ {
+ body_name => 'Bromley',
+ body_id => 2482,
+ row_data => {
+ postcode => 'BR1 1AA',
+ # NB: we don't pass last_name here, as main cobrand doesn't know to do this!
+ },
+ extra => {
+ northing => 100,
+ easting => 100,
+ url => 'http://example.com/1234',
+ },
+ },
+ $bromley_check;
+
+test_overrides greenwich =>
+ {
+ body_name => 'Greenwich',
+ body_id => 2493,
+ },
+ superhashof({
+ handler => isa('FixMyStreet::Cobrand::Greenwich'),
+ 'open311' => noclass(superhashof({
+ %standard_open311_parameters,
+ })),
+ problem_extra => bag(
+ { name => 'external_id', value => re('[0-9]+') },
+ ),
+ });
+
+test_overrides fixmystreet =>
+ {
+ body_name => 'West Berkshire',
+ body_id => 2619,
+ row_data => {
+ postcode => 'RG1 1AA',
+ },
+ },
+ superhashof({
+ handler => isa('FixMyStreet::Cobrand::WestBerkshire'),
+ 'open311' => noclass(superhashof({
+ %standard_open311_parameters,
+ 'endpoints' => {
+ 'requests' => 'Requests',
+ 'services' => 'Services',
+ },
+ })),
+ });
+
+sub test_overrides {
+ # NB: Open311 and ::SendReport::Open311 are mocked below in BEGIN { ... }
+ my ($cobrand, $input, $expected_data) = @_;
+ subtest "$cobrand ($input->{body_name}) overrides" => sub {
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => ['fixmystreet', 'oxfordshire', 'bromley', 'westberkshire', 'greenwich'],
+ }, sub {
+ my $db = FixMyStreet::DB->storage->schema;
+ $db->txn_begin;
+
+ my $params = { id => $input->{body_id}, name => $input->{body_name} };
+ my $body = $db->resultset('Body')->find_or_create($params);
+ $body->body_areas->create({ area_id => $input->{body_id} });
+ ok $body, "found/created body " . $input->{body_name};
+ $body->update({ can_be_devolved => 1 });
+
+ my $contact = $body->contacts->find_or_create(
+ confirmed => 1,
+ email => 'ZZ',
+ category => 'ZZ',
+ deleted => 0,
+ editor => 'test suite',
+ note => '',
+ whenedited => DateTime->now,
+ jurisdiction => '1234',
+ api_key => 'SEEKRIT',
+ body_id => $input->{body_id},
+ );
+ $contact->update({ send_method => 'Open311', endpoint => 'http://example.com/open311' });
+
+ my $user = $db->resultset('User')->create( {
+ name => 'Fred Bloggs',
+ email => TEST_USER_EMAIL,
+ password => 'dummy',
+ });
+
+ my $row = $db->resultset('Problem')->create( {
+ title => 'Problem',
+ detail => 'A big problem',
+ used_map => 1,
+ name => 'Fred Bloggs',
+ anonymous => 1,
+ state => 'unconfirmed',
+ bodies_str => $input->{body_id},
+ areas => (sprintf ',%d,', $input->{body_id}),
+ category => 'ZZ',
+ cobrand => $cobrand,
+ user => $user,
+ postcode => 'ZZ1 1AA',
+ latitude => 100,
+ longitude => 100,
+ confirmed => DateTime->now(),
+ %{ $input->{row_data} || {} },
+ } );
+
+ my $sr = FixMyStreet::SendReport::Open311->new;
+ $sr->add_body($body, $contact);
+ $sr->send( $row, $input->{extra} || {} );
+
+ cmp_deeply (Open311->_get_test_data, $expected_data, 'Data as expected')
+ or diag Dumper( Open311->_get_test_data );
+
+ Open311->_reset_test_data();
+ $db->txn_rollback;
+ };
+ }
+}
+
+BEGIN {
+ # Prepare the %data variable to write data from Open311 calls to...
+ my %data;
+ package Open311;
+ use Class::Method::Modifiers;
+ around new => sub {
+ my $orig = shift;
+ my ($class, %params) = @_;
+ my $self = $class->$orig(%params);
+ $data{open311} = $self;
+ $self;
+ };
+ around send_service_request => sub {
+ my $orig = shift;
+ my ($self, $problem, $extra, $service_code) = @_;
+ $data{problem} = { $problem->get_columns };
+ $data{extra} = $extra;
+ $data{problem_extra} = $problem->get_extra_fields;
+ $data{problem_user} = { $problem->user->get_columns };
+ $data{service_code} = $service_code;
+ # don't actually send the service request!
+ };
+
+ sub _get_test_data { return +{ %data } }
+ sub _reset_test_data { %data = () }
+
+ package FixMyStreet::DB::Result::Problem;
+ use Class::Method::Modifiers; # is marked as immutable by Moose
+ sub discard_changes {
+ $data{discard_changes}++;
+ # no need to actually discard, as we're in transaction anyway
+ };
+
+ package FixMyStreet::DB::Result::Body;
+ use Class::Method::Modifiers; # is marked as immutable by Moose
+ around get_cobrand_handler => sub {
+ my $orig = shift;
+ my ($self) = @_;
+ my $handler = $self->$orig();
+ $data{handler} = $handler;
+ $handler;
+ };
+}
+
+done_testing();
diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t
index 43d936684..a7cc563dc 100644
--- a/t/cobrand/bromley.t
+++ b/t/cobrand/bromley.t
@@ -55,7 +55,7 @@ subtest 'testing special Open311 behaviour', sub {
$body->update( { send_method => 'Open311', endpoint => 'http://bromley.endpoint.example.com', jurisdiction => 'FMS', api_key => 'test' } );
my $test_data;
FixMyStreet::override_config {
- SEND_REPORTS_ON_STAGING => 1,
+ STAGING_FLAGS => { send_reports => 1 },
ALLOWED_COBRANDS => [ 'fixmystreet', 'bromley' ],
}, sub {
$test_data = FixMyStreet::DB->resultset('Problem')->send_reports();
diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t
index 2ef3c09b4..d6a1c2b34 100644
--- a/t/cobrand/fixamingata.t
+++ b/t/cobrand/fixamingata.t
@@ -1,19 +1,22 @@
use strict;
use warnings;
use Test::More;
-use LWP::Protocol::PSGI;
+use Test::MockModule;
BEGIN {
use FixMyStreet;
FixMyStreet->test_mode(1);
}
-use t::Mock::MapIt;
use mySociety::Locale;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
+# Closest road reverse geocode mock
+my $resolver = Test::MockModule->new('LWP::Simple');
+$resolver->mock('get', sub($) { "<result></result>" });
+
# Front page test
ok $mech->host("www.fixamingata.se"), "change host to FixaMinGata";
@@ -101,13 +104,9 @@ subtest "Test ajax decimal points" => sub {
# 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::Mock::MapIt->run_if_script, host => 'mapit.sweden');
-
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fixamingata' ],
- MAPIT_URL => 'http://mapit.sweden/'
+ MAPIT_URL => 'http://mapit.uk/'
}, sub {
$mech->get_ok('/ajax/lookup_location?term=12345');
# We want an actual decimal point in a JSON response...
diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t
index c6f6976d5..22a86ef21 100644
--- a/t/cobrand/form_extras.t
+++ b/t/cobrand/form_extras.t
@@ -29,7 +29,7 @@ my $mech = FixMyStreet::TestMech->new;
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { tester => '.' } ],
- MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t
index d9f880d07..b0fad3b56 100644
--- a/t/cobrand/oxfordshire.t
+++ b/t/cobrand/oxfordshire.t
@@ -45,6 +45,29 @@ subtest 'check /ajax defaults to open reports only' => sub {
}
};
+my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1);
+
+subtest 'Exor RDI download appears on Oxfordshire cobrand admin' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'oxfordshire' => '.' } ],
+ }, sub {
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok('/admin');
+ $mech->content_contains("Download Exor RDI");
+ }
+};
+
+subtest 'Exor RDI download doesn’t appear outside of Oxfordshire cobrand admin' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ }, sub {
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok('/admin');
+ $mech->content_lacks("Download Exor RDI");
+ }
+};
+
# Clean up
+$mech->delete_user( $superuser );
$mech->delete_problems_for_body( 2237 );
done_testing();
diff --git a/t/cobrand/seesomething.t b/t/cobrand/seesomething.t
deleted file mode 100644
index 4da1c9c6e..000000000
--- a/t/cobrand/seesomething.t
+++ /dev/null
@@ -1,87 +0,0 @@
-use strict;
-use warnings;
-use DateTime;
-use Test::More;
-
-use FixMyStreet;
-use FixMyStreet::TestMech;
-
-my $EMAIL = 'seesomething@example.com';
-
-my $mech = FixMyStreet::TestMech->new;
-my $db = FixMyStreet::DB->storage->schema;
-my $dt_parser = $db->storage->datetime_parser;
-
-$db->txn_begin;
-
-$db->resultset('Comment')->delete;
-$db->resultset('Problem')->delete;
-
-my $user = $mech->create_user_ok( $EMAIL );
-
-my $body = $mech->create_body_ok( 2520, 'Coventry City Council', id => 2520 );
-$mech->create_body_ok( 2522, 'Dudley Borough Council' );
-$mech->create_body_ok( 2514, 'Birmingham City Council' );
-$mech->create_body_ok( 2546, 'Walsall Borough Council' );
-$mech->create_body_ok( 2519, 'Wolverhampton City Council' );
-$mech->create_body_ok( 2538, 'Solihull Borough Council' );
-$mech->create_body_ok( 2535, 'Sandwell Borough Council' );
-
-$user->update({ from_body => $body });
-
-my $date = $dt_parser->format_datetime(DateTime->now);
-
-my $report = FixMyStreet::DB->resultset('Problem')->find_or_create( {
- postcode => 'EH1 1BB',
- bodies_str => '2520',
- areas => ',2520,',
- service => 'Android',
- category => 'Bus',
- subcategory => 'Loud Music',
- title => 'Loud Music',
- detail => 'Loud Music',
- used_map => 1,
- name => 'SeeSomething Test User',
- anonymous => 0,
- state => 'confirmed',
- confirmed => $date,
- lang => 'en-gb',
- cobrand => 'default',
- cobrand_data => '',
- send_questionnaire => 1,
- latitude => '52.4081',
- longitude => '-1.5106',
- user_id => $user->id,
-} );
-
-subtest 'admin/stats' => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'seesomething' ],
- }, sub {
- my $user = $mech->log_in_ok( $EMAIL );
-
- $mech->get( '/admin/stats' );
- if (ok $mech->success) {
-
- $date =~s/ /&nbsp;/;
- $date =~s/\+0000//;
- my $xml = <<EOXML;
- <tr>
- <td>Android</td>
- <td>Bus</td>
- <td class="nowrap">Loud Music</td>
- <td class="nowrap">Coventry </td>
- <td class="nowrap">$date</td>
- </tr>
-EOXML
- $mech->content_contains($xml);
- }
- else {
- diag $mech->content;
- diag $mech->status;
- };
- }
-};
-
-$db->txn_rollback;
-done_testing;
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index ddaae1f90..0a84d2d03 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -28,12 +28,12 @@ ok $sample_file->exists, "sample file $sample_file exists";
my $sample_photo = $sample_file->slurp_raw;
# 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, and
+# correctly set - notably STAGING_FLAGS send_reports needs to be true, and
# zurich must be allowed cobrand if we want to be able to call cobrand
# methods on it.
sub send_reports_for_zurich {
FixMyStreet::override_config {
- SEND_REPORTS_ON_STAGING => 1,
+ STAGING_FLAGS => { send_reports => 1 },
ALLOWED_COBRANDS => ['zurich']
}, sub {
# Actually send the report
@@ -82,7 +82,7 @@ $subdivision->endpoint( 'subdivision@example.org' );
$subdivision->update;
my $external_body = $mech->create_body_ok( 4, 'External Body' );
$external_body->send_method( 'Zurich' );
-$external_body->endpoint( 'external_body@example.org' );
+$external_body->endpoint( 'external_body@example.net' );
$external_body->update;
sub get_export_rows_count {
@@ -563,7 +563,7 @@ subtest "external report triggers email" => sub {
send_reports_for_zurich();
$email = $mech->get_email;
like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay';
- like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct';
+ like $email->header('To'), qr/external_body\@example.net/, 'to line looks correct';
like $email->body, qr/External Body/, 'body has right name';
like $email->body, qr/$EXTERNAL_MESSAGE/, 'external_message was passed on';
unlike $email->body, qr/test\@example.com/, 'body does not contain email address';
@@ -599,7 +599,7 @@ subtest "external report triggers email" => sub {
send_reports_for_zurich();
$email = $mech->get_email;
like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay';
- like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct';
+ like $email->header('To'), qr/external_body\@example.net/, 'to line looks correct';
like $email->body, qr/External Body/, 'body has right name';
like $email->body, qr/test\@example.com/, 'body does contain email address';
$mech->clear_emails_ok;
@@ -630,7 +630,7 @@ subtest "external report triggers email" => sub {
send_reports_for_zurich();
$email = $mech->get_email;
like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay';
- like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct';
+ like $email->header('To'), qr/external_body\@example.net/, 'to line looks correct';
like $email->body, qr/External Body/, 'body has right name';
like $email->body, qr/$EXTERNAL_MESSAGE/, 'external_message was passed on';
like $email->body, qr/test\@example.com/, 'body contains email address';
diff --git a/t/cobrand/zurich_attachments.txt b/t/cobrand/zurich_attachments.txt
index bf8d6872b..25a1bacf0 100644
--- a/t/cobrand/zurich_attachments.txt
+++ b/t/cobrand/zurich_attachments.txt
@@ -1,7 +1,7 @@
MIME-Version: 1.0
Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID
Content-Type: multipart/mixed; boundary="BOUNDARY"
-To: "External Body" <external_body@example.org>
+To: "External Body" <external_body@example.net>
Content-Transfer-Encoding: 7bit
From: "FixMyStreet" <division@example.org>
diff --git a/t/open311.t b/t/open311.t
index cbf305a36..e6ea9b6fc 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -30,20 +30,26 @@ my $o2 = Open311->new( endpoint => 'http://127.0.0.1/open311/', jurisdiction =>
my $u = FixMyStreet::DB->resultset('User')->new( { email => 'test@example.org', name => 'A User' } );
-my $p = FixMyStreet::DB->resultset('Problem')->new( {
- latitude => 1,
- longitude => 1,
- title => 'title',
- detail => 'detail',
- user => $u,
- id => 1,
- name => 'A User',
- cobrand => 'fixmystreet',
-} );
-
-my $expected_error = qr{Failed to submit problem 1 over Open311}ism;
-
-warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 )} $expected_error, 'warning generated on failed call';
+for my $sfc (0..2) {
+ my $p = FixMyStreet::DB->resultset('Problem')->new( {
+ latitude => 1,
+ longitude => 1,
+ title => 'title',
+ detail => 'detail',
+ user => $u,
+ id => 1,
+ name => 'A User',
+ cobrand => 'fixmystreet',
+ send_fail_count => $sfc,
+ } );
+ my $expected_error = qr{Failed to submit problem 1 over Open311}ism;
+
+ if ($sfc == 2) {
+ warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 )} $expected_error, 'warning generated on failed call';
+ } else {
+ warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 )} undef, 'no warning generated on failed call';
+ }
+}
my $dt = DateTime->now();
@@ -572,6 +578,9 @@ for my $test (
};
}
+$problem->send_fail_count(2);
+$comment->send_fail_count(2);
+
subtest 'No request id in reponse' => sub {
my $results;
warning_like {
diff --git a/t/sendreport/open311.t b/t/sendreport/open311.t
index 636faba31..c40b64d12 100644
--- a/t/sendreport/open311.t
+++ b/t/sendreport/open311.t
@@ -26,7 +26,7 @@ subtest 'testing Open311 behaviour', sub {
$body->update( { send_method => 'Open311', endpoint => 'http://endpoint.example.com', jurisdiction => 'FMS', api_key => 'test' } );
my $test_data;
FixMyStreet::override_config {
- SEND_REPORTS_ON_STAGING => 1,
+ STAGING_FLAGS => { send_reports => 1 },
ALLOWED_COBRANDS => [ 'fixmystreet' ],
}, sub {
$test_data = FixMyStreet::DB->resultset('Problem')->send_reports();
diff --git a/t/utils.t b/t/utils.t
index ac9eb1a4a..f989580c8 100644
--- a/t/utils.t
+++ b/t/utils.t
@@ -78,7 +78,11 @@ if ($dt->day_of_week == 7) { # Sunday
}
is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %A");
-$dt = DateTime->now->subtract(days => 100);
+if ($dt->month == 1) { # January
+ $dt = DateTime->now->add(days => 30);
+} else {
+ $dt = DateTime->now->subtract(days => 30);
+}
is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %A %e %B %Y");
is Utils::prettify_dt($dt, "date"), $dt->strftime("%A %e %B %Y");
is Utils::prettify_dt($dt, "zurich"), $dt->strftime("%H:%M, %e. %B %Y");
@@ -87,10 +91,18 @@ is Utils::prettify_dt($dt, 1), $dt->strftime("%H:%M, %e %b %Y");
$dt = DateTime->now->subtract(days => 400);
is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %a %e %B %Y");
+is Utils::prettify_duration(12*5*7*86400+3600+60+1, 'year'), '1 year';
+is Utils::prettify_duration(25*5*7*86400+3600+60+1, 'year'), '2 years';
+is Utils::prettify_duration(5*7*86400+3600+60+1, 'month'), '1 month';
is Utils::prettify_duration(7*86400+3600+60+1, 'week'), '1 week';
is Utils::prettify_duration(86400+3600+60+1, 'day'), '1 day';
is Utils::prettify_duration(86400+3600+60+1, 'hour'), '1 day, 1 hour';
is Utils::prettify_duration(86400+3600+60+1, 'minute'), '1 day, 1 hour, 1 minute';
is Utils::prettify_duration(20, 'minute'), 'less than a minute';
+# prettify_duration should choose a $nearest sensibly if it's not given
+is Utils::prettify_duration(12*5*7*86400+3600+60+1), '1 year';
+is Utils::prettify_duration(7*86400+3600+60+1), '1 week';
+is Utils::prettify_duration(14*86400+3600+60+1), '2 weeks';
+is Utils::prettify_duration(1800), '30 minutes';
done_testing();
diff --git a/t/utils/email.t b/t/utils/email.t
index 23814c1d7..9e556a865 100644
--- a/t/utils/email.t
+++ b/t/utils/email.t
@@ -31,4 +31,7 @@ is Utils::Email::test_dmarc('BAD'), undef;
is Utils::Email::test_dmarc('test@yahoo.com'), 1;
is Utils::Email::test_dmarc('test@example.net'), undef;
+is Utils::Email::same_domain(['test@example.net', ''], [ ['to@example.net', ''], ['to@example.com', ''] ]), 1;
+is Utils::Email::same_domain(['test@example.org', ''], [ ['to@example.net', ''] ]), '';
+
done_testing();