aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/report_inspect.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/report_inspect.t')
-rw-r--r--t/app/controller/report_inspect.t164
1 files changed, 85 insertions, 79 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index ef05288c7..8deb2667e 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -8,14 +8,6 @@ my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council', { can_be_de
my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Cows', email => 'cows@example.net' );
my $contact2 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Sheep', email => 'SHEEP', send_method => 'Open311' );
my $contact3 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Badgers', email => 'badgers@example.net' );
-my $dt = FixMyStreet::DB->resultset("DefectType")->create({
- body => $oxon,
- name => 'Small Defect', description => "Teeny",
-});
-FixMyStreet::DB->resultset("ContactDefectType")->create({
- contact => $contact,
- defect_type => $dt,
-});
my $rp = FixMyStreet::DB->resultset("ResponsePriority")->create({
body => $oxon,
name => 'High Priority',
@@ -87,6 +79,87 @@ FixMyStreet::override_config {
$mech->content_lacks('/admin/report_edit/'.$report_id.'">admin</a>)');
};
+ for my $test (
+ {
+ name => "categories only",
+ area_ids => [],
+ categories => [ $contact->id ],
+ destination => "/reports/Oxfordshire",
+ previous => "/my/inspector_redirect",
+ query_form => { filter_category => $contact->category },
+ good_link => "/my/inspector_redirect",
+ bad_link => "/reports",
+ },
+ {
+ name => "categories and areas",
+ area_ids => [60705],
+ categories => [ $contact->id ],
+ destination => "/reports/Oxfordshire/Trowbridge",
+ previous => "/my/inspector_redirect",
+ query_form => { filter_category => $contact->category },
+ good_link => "/my/inspector_redirect",
+ bad_link => "/reports",
+ },
+ {
+ name => "areas only",
+ area_ids => [60705],
+ categories => undef,
+ destination => "/reports/Oxfordshire/Trowbridge",
+ previous => "/my/inspector_redirect",
+ query_form => {},
+ good_link => "/my/inspector_redirect",
+ bad_link => "/reports",
+ },
+ {
+ name => "no categories or areas",
+ area_ids => undef,
+ categories => undef,
+ destination => "/my",
+ query_form => {},
+ good_link => "/reports",
+ bad_link => "/my/inspector_redirect",
+ },
+ {
+ name => "categories but no from_body",
+ area_ids => undef,
+ categories => [ $contact->id ],
+ destination => "/my",
+ query_form => {},
+ good_link => "/reports",
+ bad_link => "/my/inspector_redirect",
+ unset_from_body => 1,
+ },
+ ) {
+ subtest "login destination and top-level nav for inspectors with " . $test->{name} => sub {
+ $mech->log_out_ok;
+
+ $user->area_ids($test->{area_ids});
+ $user->set_extra_metadata('categories', $test->{categories});
+ $user->from_body(undef) if $test->{unset_from_body};
+ $user->update;
+
+ # Can't use log_in_ok, as the call to logged_in_ok clobbers our post-login
+ # redirect.
+ $mech->get_ok('/auth');
+ $mech->submit_form_ok(
+ { with_fields => { username => $user->email, password_sign_in => 'secret' } },
+ "sign in using form" );
+ is $mech->res->code, 200, "got 200";
+ is $mech->uri->path, $test->{destination}, 'redirected to correct destination';
+ is_deeply { $mech->uri->query_form }, $test->{query_form}, 'destination query params set correctly';
+ if ($test->{previous}) {
+ is $mech->res->previous->code, 302, "got 302 for post-login redirect";
+ is $mech->res->previous->base->path, $test->{previous}, "previous URI correct";
+ }
+
+ $mech->get_ok("/");
+ ok $mech->find_link( text => 'All reports', url => $test->{good_link} );
+ ok !$mech->find_link( text => 'All reports', url => $test->{bad_link} );
+
+ $user->update( { from_body => $oxon } ) if $test->{unset_from_body};
+ };
+ }
+
subtest "council staff can't see admin report edit link on FMS.com" => sub {
my $report_edit_permission = $user->user_body_permissions->create({
body => $oxon, permission_type => 'report_edit' });
@@ -109,7 +182,7 @@ FixMyStreet::override_config {
$mech->get_ok("/report/$report_id");
$mech->submit_form_ok({ button => 'save', with_fields => { non_public => 1 } });
$report->discard_changes;
- my $alert = FixMyStreet::App->model('DB::Alert')->find(
+ my $alert = FixMyStreet::DB->resultset('Alert')->find(
{ user => $user, alert_type => 'new_updates', confirmed => 1, }
);
@@ -126,7 +199,7 @@ FixMyStreet::override_config {
$mech->get_ok("/report/$report_id");
$mech->submit_form_ok({ button => 'save', with_fields => { traffic_information => 'Yes', state => 'Action scheduled', include_update => undef } });
$report->discard_changes;
- my $alert = FixMyStreet::App->model('DB::Alert')->find(
+ my $alert = FixMyStreet::DB->resultset('Alert')->find(
{ user => $user, alert_type => 'new_updates', confirmed => 1, }
);
@@ -140,11 +213,10 @@ FixMyStreet::override_config {
$user->user_body_permissions->create({ body => $oxon, permission_type => 'planned_reports' });
$report->state('confirmed');
$report->update;
- 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.", include_update => "1",
- state => 'action scheduled', raise_defect => 1,
+ state => 'action scheduled',
} });
$mech->get_ok("/report/$report_id");
$mech->submit_form_ok({ with_fields => {
@@ -153,28 +225,22 @@ FixMyStreet::override_config {
$report->discard_changes;
my $comment = ($report->comments( undef, { order_by => { -desc => 'id' } } )->all)[1]->text;
is $comment, "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, "User reputation wasn't changed";
$mech->get_ok("/report/$report_id");
my $meta = $mech->extract_update_metas;
like $meta->[0], qr/State changed to: Action scheduled/, 'First update mentions action scheduled';
- like $meta->[2], qr/Posted by .*defect raised/, 'Update mentions defect raised';
$user->unset_extra_metadata('categories');
$user->update;
};
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, 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";
- is $report->get_extra_metadata('inspected'), undef, 'report not marked as inspected';
};
subtest "test location changes" => sub {
@@ -305,7 +371,7 @@ FixMyStreet::override_config {
$mech->get_ok("/report/$report_id");
$mech->submit_form_ok({ button => 'save', with_fields => { state => 'Investigating', public_update => "We're investigating.", include_update => "1" } });
- my $alert_count = FixMyStreet::App->model('DB::Alert')->search(
+ my $alert_count = FixMyStreet::DB->resultset('Alert')->search(
{ user_id => $user->id, alert_type => 'new_updates', confirmed => 1, parameter => $report_id }
)->count();
@@ -448,24 +514,6 @@ FixMyStreet::override_config {
is $report->response_priority->id, $rp->id, 'response priority set';
};
- subtest "check can set defect type for category when changing from category with no defect types" => sub {
- $report->update({ category => 'Sheep', defect_type_id => undef });
- $user->user_body_permissions->delete;
- $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' });
- $mech->get_ok("/report/$report_id");
- $mech->submit_form_ok({
- button => 'save',
- with_fields => {
- include_update => 0,
- defect_type => $dt->id,
- category => 'Cows',
- }
- });
- $report->discard_changes;
- is $report->defect_type->id, $dt->id, 'defect type set';
- $report->update({ defect_type_id => undef });
- };
-
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 });
@@ -614,47 +662,6 @@ FixMyStreet::override_config {
return $perms;
});
- subtest "test negative reputation" => sub {
- 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 {
- $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_instruct' });
- $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 => 'in progress', include_update => undef,
- } });
- $report->discard_changes;
- is $report->get_extra_metadata('inspected'), undef, 'report not marked as inspected';
-
- $mech->submit_form_ok({ button => 'save', with_fields => {
- state => 'action scheduled', include_update => undef,
- } });
- $report->discard_changes;
- is $report->get_extra_metadata('inspected'), undef, 'report not marked as inspected';
- is $report->user->get_extra_metadata('reputation'), $reputation+1, "User reputation was increased";
-
- $mech->submit_form_ok({ button => 'save', with_fields => {
- state => 'action scheduled', include_update => undef,
- raise_defect => 1,
- } });
- $report->discard_changes;
- is $report->get_extra_metadata('inspected'), 1, 'report marked as inspected';
- $mech->get_ok("/report/$report_id");
- my $meta = $mech->extract_update_metas;
- like $meta->[-1], qr/Updated by .*defect raised/, 'Update mentions defect raised';
- };
subtest "Oxfordshire-specific traffic management options are shown" => sub {
$report->update({ state => 'confirmed' });
@@ -697,7 +704,6 @@ FixMyStreet::override_config {
priority => $rp->id,
include_update => '1',
detailed_information => 'XXX164XXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
- defect_type => '',
traffic_information => ''
};
my $values = $mech->visible_form_values('report_inspect_form');