aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model/problem.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/model/problem.t')
-rw-r--r--t/app/model/problem.t310
1 files changed, 237 insertions, 73 deletions
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 63204e05c..24ed959af 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -9,6 +9,7 @@ use FixMyStreet;
use FixMyStreet::App;
use FixMyStreet::TestMech;
use mySociety::Locale;
+use Sub::Override;
mySociety::Locale::gettext_domain('FixMyStreet');
@@ -32,10 +33,10 @@ my $problem = $problem_rs->new(
}
);
-is $problem->confirmed_local, undef, 'inflating null confirmed ok';
-is $problem->whensent_local, undef, 'inflating null confirmed ok';
-is $problem->lastupdate_local, undef, 'inflating null confirmed ok';
-is $problem->created_local, undef, 'inflating null confirmed ok';
+is $problem->confirmed, undef, 'inflating null confirmed ok';
+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 (
{
@@ -44,7 +45,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your name',
}
},
@@ -56,7 +57,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
}
},
@@ -68,7 +69,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
}
},
@@ -80,7 +81,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
@@ -90,7 +91,7 @@ for my $test (
},
errors => {
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
@@ -99,22 +100,22 @@ for my $test (
detail => 'Some information about the problem',
},
errors => {
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
- desc => 'incorrectly formatted council',
+ desc => 'incorrectly formatted body',
changed => {
- council => 'my council',
+ bodies_str => 'my body',
},
errors => {
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
- desc => 'correctly formatted council',
+ desc => 'correctly formatted body',
changed => {
- council => '1001',
+ bodies_str => '1001',
},
errors => {
}
@@ -167,6 +168,10 @@ $problem->insert;
my $tz_local = DateTime::TimeZone->new( name => 'local' );
+my $body = FixMyStreet::App->model('DB::Body')->new({
+ name => 'Edinburgh City Council'
+});
+
for my $test (
{
desc => 'request older than problem ignored',
@@ -174,9 +179,6 @@ for my $test (
request => {
updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local )->subtract( days => 2 ) ),
},
- council => {
- name => 'Edinburgh City Council',
- },
created => 0,
},
{
@@ -187,9 +189,6 @@ for my $test (
status => 'open',
status_notes => 'this is an update from the council',
},
- council => {
- name => 'Edinburgh City Council',
- },
created => 1,
state => 'confirmed',
mark_fixed => 0,
@@ -203,9 +202,6 @@ for my $test (
status => 'closed',
status_notes => 'the council have fixed this',
},
- council => {
- name => 'Edinburgh City Council',
- },
created => 1,
state => 'fixed',
mark_fixed => 1,
@@ -219,9 +215,6 @@ for my $test (
status => 'open',
status_notes => 'the council do not think this is fixed',
},
- council => {
- name => 'Edinburgh City Council',
- },
created => 1,
start_state => 'fixed',
state => 'fixed',
@@ -238,7 +231,7 @@ for my $test (
$problem->update;
my $w3c = DateTime::Format::W3CDTF->new();
- my $ret = $problem->update_from_open311_service_request( $test->{request}, $test->{council}, $user );
+ my $ret = $problem->update_from_open311_service_request( $test->{request}, $body, $user );
is $ret, $test->{created}, 'return value';
return unless $test->{created};
@@ -302,6 +295,13 @@ for my $test (
is_closed => 0,
},
{
+ state => 'action scheduled',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
state => 'in progress',
is_visible => 1,
is_fixed => 0,
@@ -309,6 +309,27 @@ for my $test (
is_closed => 0,
},
{
+ state => 'duplicate',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 1,
+ },
+ {
+ state => 'not responsible',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 1,
+ },
+ {
+ state => 'unable to fix',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 1,
+ },
+ {
state => 'fixed',
is_visible => 1,
is_fixed => 1,
@@ -355,42 +376,53 @@ my %contact_params = (
whenedited => \'ms_current_timestamp()',
note => 'Created for test',
);
+
+for my $body (
+ { id => 2651, name => 'City of Edinburgh Council' },
+ { id => 2226, name => 'Gloucestershire County Council' },
+ { id => 2326, name => 'Cheltenham Borough Council' },
+ { id => 2434, name => 'Lichfield District Council' },
+ { id => 2240, name => 'Staffordshire County Council' },
+ { id => 14279, name => 'Ballymoney Borough Council' },
+ { id => 2636, name => 'Isle of Wight Council' },
+ { id => 2649, name => 'Fife Council' },
+) {
+ $mech->create_body_ok($body->{id}, $body->{name});
+}
+
# Let's make some contacts to send things to!
-FixMyStreet::App->model('DB::Contact')->search( {
- email => { 'like', '%example.com' },
-} )->delete;
my @contacts;
for my $contact ( {
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'potholes',
email => 'test@example.org',
}, {
- area_id => 2226, # Gloucestershire
+ body_id => 2226, # Gloucestershire
category => 'potholes',
email => '2226@example.org',
}, {
- area_id => 2326, # Cheltenham
+ body_id => 2326, # Cheltenham
category => 'potholes',
email => '2326@example.org',
}, {
- area_id => 2434, # Lichfield
+ body_id => 2434, # Lichfield
category => 'potholes',
email => 'trees@example.com',
}, {
- area_id => 2240, # Staffordshire
+ body_id => 2240, # Staffordshire
category => 'potholes',
email => 'highways@example.com',
}, {
- area_id => 14279, # Ballymoney
+ body_id => 14279, # Ballymoney
category => 'Street lighting',
email => 'roads.western@drdni.example.org',
}, {
- area_id => 14279, # Ballymoney
+ body_id => 14279, # Ballymoney
category => 'Graffiti',
email => 'highways@example.com',
}, {
confirmed => 0,
- area_id => 2636, # Isle of Wight
+ body_id => 2636, # Isle of Wight
category => 'potholes',
email => '2636@example.com',
} ) {
@@ -410,21 +442,21 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear City of Edinburgh Council',
to => qr'City of Edinburgh Council',
- council => 2651,
+ body => 2651,
}, {
%common,
desc => 'no email sent if no unsent problems',
unset_whendef => 0,
email_count => 0,
- council => 2651,
+ body => 2651,
}, {
%common,
desc => 'email to two tier council',
unset_whendef => 1,
email_count => 1,
- to => qr'Gloucestershire County Council.*Cheltenham Borough Council',
- dear => qr'Dear Gloucestershire County Council and Cheltenham Borough',
- council => '2226,2326',
+ to => qr'Cheltenham Borough Council.*Gloucestershire County Council',
+ dear => qr'Dear Cheltenham Borough Council and Gloucestershire County',
+ body => '2226,2326',
multiple => 1,
}, {
%common,
@@ -433,7 +465,7 @@ foreach my $test ( {
email_count => 1,
to => qr'Gloucestershire County Council" <2226@example',
dear => qr'Dear Gloucestershire County Council,',
- council => '2226|2649',
+ body => '2226|2649',
missing => qr'problem might be the responsibility of Fife.*Council'ms,
}, {
%common,
@@ -442,7 +474,7 @@ foreach my $test ( {
email_count => 1,
to => qr'Lichfield District Council',
dear => qr'Dear Lichfield District Council,',
- council => '2434',
+ body => '2434',
cobrand => 'lichfielddc',
url => 'lichfielddc.',
}, {
@@ -452,9 +484,9 @@ foreach my $test ( {
email_count => 1,
to => qr'Staffordshire County Council" <highways@example',
dear => qr'Dear Staffordshire County Council,',
- council => '2240',
+ body => '2240',
cobrand => 'lichfielddc',
- url => '',
+ url => 'www.',
}, {
%common,
desc => 'directs NI correctly, 1',
@@ -462,7 +494,7 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear Ballymoney Borough Council',
to => qr'Ballymoney Borough Council',
- council => 14279,
+ body => 14279,
category => 'Graffiti',
}, {
%common,
@@ -471,7 +503,7 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear Roads Service \(Western\)',
to => qr'Roads Service \(Western\)" <roads',
- council => 14279,
+ body => 14279,
category => 'Street lighting',
}, {
%common,
@@ -479,12 +511,17 @@ foreach my $test ( {
unset_whendef => 1,
stays_unsent => 1,
email_count => 0,
- council => 2636,
+ body => 2636,
},
) {
subtest $test->{ desc } => sub {
- if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) {
- plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand';
+ my $override = {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ BASE_URL => 'http://www.fixmystreet.com',
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ };
+ if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ ) {
+ $override->{ALLOWED_COBRANDS} = [ 'lichfielddc' ];
}
$mech->clear_emails_ok;
@@ -497,7 +534,7 @@ foreach my $test ( {
$problem->discard_changes;
$problem->update( {
- council => $test->{ council },
+ bodies_str => $test->{ body },
state => 'confirmed',
confirmed => \'ms_current_timestamp()',
whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()',
@@ -506,7 +543,9 @@ foreach my $test ( {
cobrand => $test->{ cobrand } || 'fixmystreet',
} );
- FixMyStreet::App->model('DB::Problem')->send_reports();
+ FixMyStreet::override_config $override, sub {
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+ };
$mech->email_count_is( $test->{ email_count } );
if ( $test->{ email_count } ) {
@@ -519,15 +558,14 @@ foreach my $test ( {
like $email->body, $test->{ dear }, 'Salutation looks correct';
if ( $test->{multiple} ) {
- like $email->body, qr/This email has been sent to several councils /, 'multiple council text correct';
+ like $email->body, qr/This email has been sent to several councils /, 'multiple body text correct';
} elsif ( $test->{ missing } ) {
- like $email->body, $test->{ missing }, 'missing council information correct';
+ like $email->body, $test->{ missing }, 'missing body information correct';
}
if ( $test->{url} ) {
- (my $base_url = FixMyStreet->config('BASE_URL')) =~ s{http://}{};
my $id = $problem->id;
- like $email->body, qr[$test->{url}$base_url/report/$id], 'URL present is correct';
+ like $email->body, qr[$test->{url}fixmystreet.com/report/$id], 'URL present is correct';
}
$problem->discard_changes;
@@ -540,10 +578,57 @@ foreach my $test ( {
};
}
-subtest 'check can turn on report sent email alerts' => sub {
- eval 'use Test::MockModule; 1' or
- plan skip_all => 'Skipping tests that rely on Test::MockModule';
+subtest 'check can set mutiple emails as a single contact' => sub {
+ my $override = {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ BASE_URL => 'http://www.fixmystreet.com',
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ };
+
+ my $contact = {
+ body_id => 2651, # Edinburgh
+ category => 'trees',
+ email => '2636@example.com,2636-2@example.com',
+ };
+ my $new_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ %$contact } );
+ ok $new_contact, "created multiple email test contact";
+
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
+ $problem->discard_changes;
+ $problem->update( {
+ bodies_str => $contact->{ body_id },
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ category => 'trees',
+ name => 'Test User',
+ cobrand => 'fixmystreet',
+ send_fail_count => 0,
+ } );
+
+ FixMyStreet::override_config $override, sub {
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+ };
+
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ is $email->header('To'), '"City of Edinburgh Council" <2636@example.com>, "City of Edinburgh Council" <2636-2@example.com>', 'To contains two email addresses';
+};
+
+subtest 'check can turn on report sent email alerts' => sub {
+ my $send_confirmation_mail_override = Sub::Override->new(
+ "FixMyStreet::Cobrand::Default::report_sent_confirmation_email",
+ sub { return 1; }
+ );
$mech->clear_emails_ok;
FixMyStreet::App->model('DB::Problem')->search(
@@ -554,18 +639,16 @@ subtest 'check can turn on report sent email alerts' => sub {
$problem->discard_changes;
$problem->update( {
- council => 2651,
+ bodies_str => 2651,
state => 'confirmed',
confirmed => \'ms_current_timestamp()',
whensent => undef,
category => 'potholes',
name => 'Test User',
cobrand => 'fixmystreet',
+ send_fail_count => 0,
} );
- my $m = new Test::MockModule(
- 'FixMyStreet::Cobrand::FixMyStreet' );
- $m->mock( report_sent_confirmation_email => 1 );
FixMyStreet::App->model('DB::Problem')->send_reports();
$mech->email_count_is( 2 );
@@ -585,14 +668,95 @@ subtest 'check can turn on report sent email alerts' => sub {
$email = $emails[1];
like $email->header('Subject'), qr/Problem Report Sent/, 'report sent email title correct';
like $email->body, qr/Your report about/, 'report sent body correct';
+
+ $send_confirmation_mail_override->restore();
};
-$problem->comments->delete;
-$problem->delete;
-$user->delete;
-foreach (@contacts) {
- $_->delete;
-}
+subtest 'check iOS app store test reports not sent' => sub {
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
+
+ $problem->discard_changes;
+ $problem->update( {
+ bodies_str => 2651,
+ title => 'App store test',
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ category => 'potholes',
+ send_fail_count => 0,
+ } );
+
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+
+ $mech->email_count_is( 0 );
+
+ $problem->discard_changes();
+ is $problem->state, 'hidden', 'iOS test reports are hidden automatically';
+ is $problem->whensent, undef, 'iOS test reports are not sent';
+};
+
+subtest 'check reports from abuser not sent' => sub {
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
-done_testing();
+ $problem->discard_changes;
+ $problem->update( {
+ bodies_str => 2651,
+ title => 'Report',
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ category => 'potholes',
+ send_fail_count => 0,
+ } );
+
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+
+ $mech->email_count_is( 1 );
+
+ $problem->discard_changes();
+ ok $problem->whensent, 'Report has been sent';
+
+ $problem->update( {
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ } );
+
+ my $abuse = FixMyStreet::App->model('DB::Abuse')->create( { email => $problem->user->email } );
+
+ $mech->clear_emails_ok;
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+
+ $mech->email_count_is( 0 );
+
+ $problem->discard_changes();
+ is $problem->state, 'hidden', 'reports from abuse user are hidden automatically';
+ is $problem->whensent, undef, 'reports from abuse user are not sent';
+
+ ok $abuse->delete(), 'user removed from abuse table';
+};
+
+END {
+ $problem->comments->delete if $problem;
+ $problem->delete if $problem;
+ $mech->delete_user( $user ) if $user;
+
+ foreach (@contacts) {
+ $_->delete;
+ }
+
+ done_testing();
+}