aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
Diffstat (limited to 't/app')
-rw-r--r--t/app/controller/alert_new.t229
-rw-r--r--t/app/controller/area_stats.t23
-rw-r--r--t/app/controller/around.t23
-rw-r--r--t/app/controller/auth_phone.t8
-rw-r--r--t/app/controller/report_inspect.t127
-rw-r--r--t/app/controller/reports.t12
6 files changed, 405 insertions, 17 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 97a19b3b8..4e8fd1b29 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -475,7 +475,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
$mech->delete_user($user2);
};
-subtest "Test alerts are correct for no-text updates" => sub {
+subtest "Test alerts are not sent for no-text updates" => sub {
$mech->delete_user( 'reporter@example.com' );
$mech->delete_user( 'alerts@example.com' );
@@ -513,6 +513,40 @@ subtest "Test alerts are correct for no-text updates" => sub {
my $report_id = $report->id;
ok $report, "created test report - $report_id";
+ my $report2 = FixMyStreet::App->model('DB::Problem')->create( {
+ postcode => 'EH1 1BB',
+ bodies_str => '1',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user1->name,
+ anonymous => 0,
+ state => 'fixed - user',
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user1->id,
+ } );
+ my $report2_id = $report2->id;
+ ok $report2, "created test report - $report2_id";
+
+ # Must be first
+ my $alert2 = FixMyStreet::App->model('DB::Alert')->create( {
+ parameter => $report2_id,
+ alert_type => 'new_updates',
+ user => $user2,
+ } )->confirm;
+ ok $alert2, 'created alert for other user';
+
my $alert = FixMyStreet::App->model('DB::Alert')->create( {
parameter => $report_id,
alert_type => 'new_updates',
@@ -533,6 +567,92 @@ subtest "Test alerts are correct for no-text updates" => sub {
my $update_id = $update->id;
ok $update, "created test update from staff user - $update_id";
+ my $update2 = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report2_id,
+ user_id => $user3->id,
+ name => 'Staff User',
+ mark_fixed => 'false',
+ text => 'This is a normal update',
+ state => 'confirmed',
+ confirmed => $dt->clone->add( hours => 9 ),
+ anonymous => 'f',
+ } );
+ my $update2_id = $update2->id;
+ ok $update2, "created test update from staff user - $update2_id";
+
+ $mech->clear_emails_ok;
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ FixMyStreet::Script::Alerts::send();
+ };
+
+ $mech->email_count_is(1);
+
+ $mech->delete_user($user1);
+ $mech->delete_user($user2);
+ $mech->delete_user($user3);
+};
+
+subtest "Test no marked as confirmed added to alerts" => sub {
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
+ my $user1 = $mech->create_user_ok('reporter@example.com', name => 'Reporter User' );
+ my $user2 = $mech->create_user_ok('alerts@example.com', name => 'Alert User' );
+ my $user3 = $mech->create_user_ok('staff@example.com', name => 'Staff User', from_body => $gloucester );
+ my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2);
+
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
+ my $report_time = '2011-03-01 12:00:00';
+ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
+ postcode => 'EH1 1BB',
+ bodies_str => '1',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user1->name,
+ anonymous => 0,
+ state => 'confirmed',
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user1->id,
+ } );
+ my $report_id = $report->id;
+ ok $report, "created test report - $report_id";
+
+ my $alert = FixMyStreet::App->model('DB::Alert')->create( {
+ parameter => $report_id,
+ alert_type => 'new_updates',
+ user => $user2,
+ } )->confirm;
+ ok $alert, 'created alert for other user';
+
+ my $update = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report_id,
+ user_id => $user3->id,
+ name => 'Staff User',
+ mark_fixed => 'false',
+ text => 'this is update',
+ state => 'confirmed',
+ problem_state => 'confirmed',
+ confirmed => $dt->clone->add( hours => 9 ),
+ anonymous => 'f',
+ } );
+ my $update_id = $update->id;
+ ok $update, "created test update from staff user - $update_id";
+
$mech->clear_emails_ok;
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
@@ -545,15 +665,116 @@ subtest "Test alerts are correct for no-text updates" => sub {
my $body = $mech->get_text_body_from_email($email);
like $body, qr/The following updates have been left on this report:/, 'email is about updates to existing report';
like $body, qr/Staff User/, 'Update comes from correct user';
-
- my @urls = $mech->get_link_from_email($email, 1);
- is $urls[0], "http://www.example.org/report/" . $report_id, "Correct report URL in email";
+ unlike $body, qr/State changed to: Open/s, 'no marked as confirmed text';
$mech->delete_user($user1);
$mech->delete_user($user2);
$mech->delete_user($user3);
};
+for my $test (
+ {
+ update_text => '',
+ problem_state => 'investigating',
+ expected_text => 'State changed to: Investigating',
+ desc => 'comment changing status included in email',
+ },
+ {
+ update_text => 'Category changed to Potholes',
+ problem_state => '',
+ expected_text => 'Category changed to Potholes',
+ desc => 'comment about category included',
+ },
+ {
+ update_text => 'Category changed to Potholes',
+ problem_state => 'investigating',
+ expected_text => 'Category changed to Potholes.*Investigating',
+ desc => 'comment about category and status change included',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
+ my $user1 = $mech->create_user_ok('reporter@example.com', name => 'Reporter User' );
+ my $user2 = $mech->create_user_ok('alerts@example.com', name => 'Alert User' );
+ my $user3 = $mech->create_user_ok('staff@example.com', name => 'Staff User', from_body => $gloucester );
+ my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2);
+
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
+ my $report_time = '2011-03-01 12:00:00';
+ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
+ postcode => 'EH1 1BB',
+ bodies_str => '1',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user1->name,
+ anonymous => 0,
+ state => 'confirmed',
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user1->id,
+ } );
+ my $report_id = $report->id;
+ ok $report, "created test report - $report_id";
+
+ my $alert = FixMyStreet::App->model('DB::Alert')->create( {
+ parameter => $report_id,
+ alert_type => 'new_updates',
+ user => $user2,
+ } )->confirm;
+ ok $alert, 'created alert for other user';
+
+ my $update = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report_id,
+ user_id => $user3->id,
+ name => 'Staff User',
+ mark_fixed => 'false',
+ text => $test->{update_text},
+ problem_state => $test->{problem_state},
+ state => 'confirmed',
+ confirmed => $dt->clone->add( hours => 9 ),
+ anonymous => 'f',
+ } );
+ my $update_id = $update->id;
+ ok $update, "created test update from staff user - $update_id";
+
+ $mech->clear_emails_ok;
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ FixMyStreet::Script::Alerts::send();
+ };
+
+ $mech->email_count_is(1);
+ my $expected_text = $test->{expected_text};
+ my $email = $mech->get_email;
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/The following updates have been left on this report:/, 'email is about updates to existing report';
+ like $body, qr/Staff User/, 'Update comes from correct user';
+ like $body, qr/$expected_text/s, 'Expected text present';
+
+ my @urls = $mech->get_link_from_email($email, 1);
+ is $urls[0], "http://www.example.org/report/" . $report_id, "Correct report URL in email";
+
+ $mech->delete_user($user1);
+ $mech->delete_user($user2);
+ $mech->delete_user($user3);
+ };
+}
+
subtest "Test signature template is used from cobrand" => sub {
$mech->delete_user( 'reporter@example.com' );
$mech->delete_user( 'alerts@example.com' );
diff --git a/t/app/controller/area_stats.t b/t/app/controller/area_stats.t
index 6ea03cabf..ce2e3d7d6 100644
--- a/t/app/controller/area_stats.t
+++ b/t/app/controller/area_stats.t
@@ -98,6 +98,8 @@ FixMyStreet::override_config {
$mech->text_contains('Potholes6');
$mech->text_contains('Traffic lights13');
+
+ $mech->text_contains('average time between issue being opened and set to another status was 0 days');
};
subtest 'shows correct stats to area user' => sub {
@@ -183,6 +185,17 @@ FixMyStreet::override_config {
$mech->text_contains('Traffic lights3730');
};
+ subtest 'ignores second state change if first was last month' => sub {
+ my $comment = $scheduled_problems[0]->comments->search({}, { order_by => { '-asc' => 'id' } } )->first;
+ $comment->update({ confirmed => DateTime->now->subtract(days => 40) });
+ $mech->get_ok("/admin/areastats/$body_id?area=20720");
+
+ $mech->content_contains('15 opened, 6 scheduled, 3 closed, 4 fixed');
+ $mech->text_contains('Potholes2004');
+ $mech->text_contains('Traffic lights3730');
+ $comment->update({ confirmed => DateTime->now });
+ };
+
subtest 'average is only to first state change' => sub {
for my $i (0..4) {
$scheduled_problems[$i]->comments->first->update({ confirmed => $scheduled_problems[$i]->confirmed });
@@ -201,6 +214,16 @@ FixMyStreet::override_config {
$mech->get_ok("/admin/areastats/$body_id?area=20720");
$mech->text_contains('average time between issue being opened and set to another status was 4 days');
};
+
+ subtest 'shows no problems changed state if no average' => sub {
+ for my $p (@scheduled_problems, @fixed_problems, @closed_problems) {
+ $p->comments->delete;
+ }
+
+ $mech->get_ok("/admin/areastats/$body_id?area=20720");
+ $mech->text_contains('17 opened, 0 scheduled, 0 closed, 0 fixed');
+ $mech->text_contains('no problems changed state');
+ }
};
END {
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index fbb4e76cd..cdaeaf363 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -92,15 +92,22 @@ foreach my $test (
};
}
-subtest 'check non public reports are not displayed on around page' => sub {
- my $params = {
- postcode => 'EH1 1BB',
- latitude => 55.9519637512,
- longitude => -3.17492254484,
- };
- my @edinburgh_problems =
- $mech->create_problems_for_body( 5, 2651, 'Around page', $params );
+my @edinburgh_problems = $mech->create_problems_for_body( 5, 2651, 'Around page', {
+ postcode => 'EH1 1BB',
+ latitude => 55.9519637512,
+ longitude => -3.17492254484,
+});
+subtest 'check lookup by reference' => sub {
+ $mech->get_ok('/');
+ $mech->submit_form_ok( { with_fields => { pc => 'ref:12345' } }, 'bad ref');
+ $mech->content_contains('Searching found no reports');
+ my $id = $edinburgh_problems[0]->id;
+ $mech->submit_form_ok( { with_fields => { pc => "ref:$id" } }, 'good ref');
+ is $mech->uri->path, "/report/$id", "redirected to report page";
+};
+
+subtest 'check non public reports are not displayed on around page' => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
diff --git a/t/app/controller/auth_phone.t b/t/app/controller/auth_phone.t
index 8673f5c62..435ea7552 100644
--- a/t/app/controller/auth_phone.t
+++ b/t/app/controller/auth_phone.t
@@ -47,7 +47,7 @@ subtest 'Log in using mobile, by text' => sub {
}, sub {
$mech->submit_form_ok({
form_name => 'general_auth',
- fields => { username => '+61491570156', password_register => 'secret' },
+ fields => { username => '+18165550100', password_register => 'secret' },
button => 'sign_in_by_code',
}, "sign in using mobile");
@@ -61,7 +61,7 @@ subtest 'Log in using mobile, by text' => sub {
with_fields => { code => $code }
}, 'submit correct code');
- my $user = FixMyStreet::App->model('DB::User')->find( { phone => '+61491570156' } );
+ my $user = FixMyStreet::App->model('DB::User')->find( { phone => '+18165550100' } );
ok $user, "user created";
is $mech->uri->path, '/my', "redirected to the 'my' section of site";
$mech->logged_in_ok;
@@ -76,13 +76,13 @@ subtest 'Log in using mobile, by password' => sub {
$mech->get_ok('/auth');
$mech->submit_form_ok({
form_name => 'general_auth',
- fields => { username => '+61491570156', password_sign_in => 'incorrect' },
+ fields => { username => '+18165550100', password_sign_in => 'incorrect' },
button => 'sign_in_by_password',
}, "sign in using wrong password");
$mech->content_contains('There was a problem');
$mech->submit_form_ok({
form_name => 'general_auth',
- fields => { username => '+61491570156', password_sign_in => 'secret' },
+ fields => { username => '+18165550100', password_sign_in => 'secret' },
button => 'sign_in_by_password',
}, "sign in using password");
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 45bb4f8a7..f74c94c34 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -11,10 +11,18 @@ my $rp = FixMyStreet::DB->resultset("ResponsePriority")->create({
body => $oxon,
name => 'High Priority',
});
+my $rp2 = FixMyStreet::DB->resultset("ResponsePriority")->create({
+ body => $oxon,
+ name => 'Low Priority',
+});
FixMyStreet::DB->resultset("ContactResponsePriority")->create({
contact => $contact,
response_priority => $rp,
});
+FixMyStreet::DB->resultset("ContactResponsePriority")->create({
+ contact => $contact3,
+ response_priority => $rp2,
+});
my $wodc = $mech->create_body_ok(2420, 'West Oxfordshire District Council');
$mech->create_contact_ok( body_id => $wodc->id, category => 'Horses', email => 'horses@example.net' );
@@ -254,7 +262,7 @@ FixMyStreet::override_config {
$mech->submit_form_ok({
button => 'save',
with_fields => {
- $test->{priority} ? (priority => 1) : (),
+ $test->{priority} ? (priority => $rp->id) : (),
$test->{category} ? (category => 'Cows') : (),
$test->{detailed} ? (detailed_information => 'Highland ones') : (),
}
@@ -262,6 +270,68 @@ FixMyStreet::override_config {
};
}
+ subtest "check priority not set for category with no priorities" => sub {
+ $report->discard_changes;
+ $report->update({ category => 'Cows', response_priority_id => undef });
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority not set';
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_category' });
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ priority => $rp->id,
+ category => 'Sheep',
+ }
+ });
+
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority not set';
+ };
+
+ subtest "check can set priority for category when changing from category with no priorities" => sub {
+ $report->discard_changes;
+ $report->update({ category => 'Sheep', response_priority_id => undef });
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority not set';
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_category' });
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ priority => $rp->id,
+ category => 'Cows',
+ }
+ });
+
+ $report->discard_changes;
+ is $report->response_priority->id, $rp->id, 'response priority set';
+ };
+
+ subtest "check can't set priority that isn't for a category" => sub {
+ $report->discard_changes;
+ $report->update({ category => 'Cows', response_priority_id => $rp->id });
+ $report->discard_changes;
+ is $report->response_priority->id, $rp->id, 'response priority set';
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_category' });
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ priority => $rp2->id,
+ }
+ });
+
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority set';
+ };
+
subtest "check nearest address display" => sub {
$mech->get_ok("/report/$report_id");
$mech->content_lacks('Nearest calculated address', 'No address displayed');
@@ -408,6 +478,61 @@ FixMyStreet::override_config {
};
FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ ALLOWED_COBRANDS => 'fixmystreet',
+}, sub {
+ subtest "test category not updated if fail to include public update" => sub {
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form(button => 'save', with_fields => { category => 'Badgers' });
+
+ $report->discard_changes;
+ is $report->category, "Cows", "Report in correct category";
+ $mech->content_contains('Badgers" selected', 'Changed category still selected');
+ };
+
+ subtest "test invalid form maintains Category and priority" => sub {
+ $mech->get_ok("/report/$report_id");
+ my $expected_fields = {
+ state => 'action scheduled',
+ category => 'Cows',
+ public_update => '',
+ priority => $rp->id,
+ include_update => '1',
+ detailed_information => 'XXX172XXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
+ defect_type => '',
+ traffic_information => ''
+ };
+ my $values = $mech->visible_form_values('report_inspect_form');
+ is_deeply $values, $expected_fields, 'correct form fields present';
+
+ $mech->submit_form(button => 'save', with_fields => { category => 'Badgers', priority => $rp2->id });
+
+ $expected_fields->{category} = 'Badgers';
+ $expected_fields->{priority} = $rp2->id;
+
+ my $new_values = $mech->visible_form_values('report_inspect_form');
+ is_deeply $new_values, $expected_fields, 'correct form fields present';
+ };
+
+ subtest "test changing category and leaving an update only creates one comment" => sub {
+ $report->comments->delete;
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form(
+ button => 'save',
+ with_fields => {
+ category => 'Badgers',
+ include_update => 1,
+ public_update => 'This is a public update',
+ });
+
+ $report->discard_changes;
+ is $report->category, "Badgers", "Report in correct category";
+ is $report->comments->count, 1, "Only leaves one update";
+ like $report->comments->first->text, qr/Category changed.*Badgers/, 'update text included category change';
+ };
+};
+
+FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'oxfordshire', 'fixmystreet' ],
BASE_URL => 'http://fixmystreet.site',
}, sub {
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index f3958a0a5..7773223dd 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -114,6 +114,18 @@ FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { body => $body_edin_id } }, 'Submitted dropdown okay' );
+ is $mech->uri->path, '/reports/City+of+Edinburgh+Council';
+
+ subtest "test ward pages" => sub {
+ $mech->get_ok('/reports/Birmingham/Bad-Ward');
+ is $mech->uri->path, '/reports/Birmingham+City+Council';
+ $mech->get_ok('/reports/Birmingham/Aston');
+ is $mech->uri->path, '/reports/Birmingham+City+Council/Aston';
+ $mech->get_ok('/reports/Birmingham/Aston|Bournville');
+ is $mech->uri->path, '/reports/Birmingham+City+Council/Aston%7CBournville';
+ $mech->content_contains('Aston, Bournville');
+ };
+
$mech->get_ok('/reports/Westminster');
};