diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/admin_defecttypes.t | 193 | ||||
-rw-r--r-- | t/app/controller/report_inspect.t | 16 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 42 | ||||
-rw-r--r-- | t/app/controller/reports.t | 79 |
4 files changed, 329 insertions, 1 deletions
diff --git a/t/app/controller/admin_defecttypes.t b/t/app/controller/admin_defecttypes.t new file mode 100644 index 000000000..e7d0e42af --- /dev/null +++ b/t/app/controller/admin_defecttypes.t @@ -0,0 +1,193 @@ +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +FixMyStreet::override_config { ALLOWED_COBRANDS => ['bromley'], }, sub { + subtest 'check defecttypes menu not available' => sub { + my $body = $mech->create_body_ok( 2482, 'Bromley Council' ); + + my $user = $mech->create_user_ok( + 'bromley@example.com', + name => 'Test User', + from_body => $body + ); + + $mech->log_in_ok( $user->email ); + + $mech->get_ok('/admin'); + $mech->content_lacks('Defect Types'); + + is $mech->get('/admin/defecttypes')->code, 404, '404 if no permission'; + is $mech->get('/admin/defecttypes/' . $body->id)->code, 404, '404 if no permission'; + + $mech->log_out_ok(); + }; +}; + +FixMyStreet::override_config { ALLOWED_COBRANDS => ['oxfordshire'], }, sub { + + my $body = $mech->create_body_ok( 2237, 'Oxfordshire County Council' ); + + my $user = $mech->create_user_ok( + 'oxford@example.com', + name => 'Test User', + from_body => $body + ); + + $mech->log_in_ok( $user->email ); + + my $contact = $mech->create_contact_ok( + body_id => $body->id, + category => 'Traffic lights', + email => 'lights@example.com' + ); + + subtest 'check defecttypes menu not available without permissions' => sub { + $mech->get_ok('/admin'); + $mech->content_lacks('Defect Types'); + + is $mech->get('/admin/defecttypes')->code, 404, '404 if no permission'; + is $mech->get('/admin/defecttypes/' . $body->id)->code, 404, '404 if no permission'; + }; + + $user->user_body_permissions->create( { + body => $body, + permission_type => 'defect_type_edit', + } ); + + subtest 'check defecttypes menu available with permissions' => sub { + $mech->get_ok('/admin'); + $mech->content_contains('Defect Types'); + $mech->get_ok('/admin/defecttypes'); + is $mech->res->previous->code, 302, 'index redirects...'; + is $mech->uri->path, '/admin/defecttypes/' . $body->id, '...to body page'; + }; + + subtest 'check missing defect type is 404' => sub { + is $mech->get( '/admin/defecttypes/' . $body->id . '/299')->code, 404; + }; + + subtest 'check adding a defect type' => sub { + $mech->get_ok( '/admin/defecttypes/' . $body->id . '/new' ); + + $mech->content_contains('Traffic lights'); + + $mech->submit_form_ok( { + with_fields => { + name => 'A defect', + description => 'This is a new defect', + } } ); + + $mech->content_contains('New defect'); + }; + + subtest 'check editing a defect type' => sub { + my $defect = FixMyStreet::App->model('DB::DefectType')->search( { + name => 'A defect', + body_id => $body->id + } )->first; + + $mech->get_ok( '/admin/defecttypes/' . $body->id . '/' . $defect->id ); + + $mech->submit_form_ok( { + with_fields => { + name => 'Updated defect', + description => 'This is a new defect', + } + }, + 'submitted form' + ); + + $mech->content_lacks('A defect'); + $mech->content_contains('Updated defect'); + + my $defects = FixMyStreet::App->model('DB::DefectType')->search( { + body_id => $body->id + } ); + + is $defects->count, 1, 'only 1 defect'; + }; + + subtest 'check adding a category to a defect' => sub { + my $defect = FixMyStreet::App->model('DB::DefectType')->search( { + name => 'Updated defect', + body_id => $body->id + } )->first; + + is $defect->contact_defect_types->count, 0, + 'defect has no contact types'; + + $mech->get_ok( '/admin/defecttypes/' . $body->id . '/' . $defect->id ); + + $mech->submit_form_ok( { + with_fields => { + name => 'Updated defect', + description => 'This is a new defect', + categories => [ $contact->id ], + } + }, + 'submitted form' + ); + + $mech->content_contains('Traffic lights'); + + $defect->discard_changes; + is $defect->contact_defect_types->count, 1, 'defect has a contact type'; + is $defect->contact_defect_types->first->contact->category, + 'Traffic lights', 'defect has correct contact type'; + }; + + subtest 'check removing category from a defect' => sub { + my $defect = FixMyStreet::App->model('DB::DefectType')->search( { + name => 'Updated defect', + body_id => $body->id + } )->first; + + is $defect->contact_defect_types->count, 1, + 'defect has one contact types'; + + $mech->get_ok( '/admin/defecttypes/' . $body->id . '/' . $defect->id ); + + $mech->submit_form_ok( { + with_fields => { + name => 'Updated defect', + description => 'This is a new defect', + categories => '', + } + }, + 'submitted form' + ); + + $mech->content_lacks('Traffic lights'); + + $defect->discard_changes; + is $defect->contact_defect_types->count, 0, + 'defect has no contact type'; + }; + + subtest 'check adding codes to a defect' => sub { + my $defect = FixMyStreet::App->model('DB::DefectType')->search( { + name => 'Updated defect', + body_id => $body->id + } )->first; + + $mech->get_ok( '/admin/defecttypes/' . $body->id . '/' . $defect->id ); + + $mech->submit_form_ok( { + with_fields => { + name => 'Updated defect', + description => 'This is a new defect', + 'extra[activity_code]' => 1, + 'extra[defect_code]' => 2, + } + }, + 'submitted form' + ); + + $defect->discard_changes; + is_deeply $defect->get_extra_metadata, + { activity_code => 1, defect_code => 2 }, 'defect codes set'; + }; +}; + +done_testing(); diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index e668fddbf..33486aa28 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -79,10 +79,21 @@ FixMyStreet::override_config { public_update => "This is a public update.", include_update => "1", state => 'action scheduled', raise_defect => 1, } }); + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok({ with_fields => { + update => "This is a second public update, of normal update form, no actual change.", + } }); $report->discard_changes; - is $report->comments->first->text, "This is a public update.", 'Update was created'; + 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/Updated by .*action scheduled/, 'First update mentions action scheduled'; + like $meta->[1], qr/Posted by .*defect raised/, 'Update mentions defect raised'; + unlike $meta->[2], qr/Posted by .*action scheduled/, 'Update does not mention action scheduled'; + $user->unset_extra_metadata('categories'); $user->update; }; @@ -245,6 +256,9 @@ FixMyStreet::override_config { } }); $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 { diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 81174181c..4cb035bac 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -928,6 +928,48 @@ subtest 'check meta correct for second comment marking as reopened' => sub { like $update_meta->[1], qr/reopened/, 'update meta says reopened'; }; +subtest "check first comment with status change but no text is displayed" => sub { + $user->from_body( $body->id ); + $user->update; + + $report->comments->delete; + + my $comment = FixMyStreet::App->model('DB::Comment')->create( + { + user => $user, + name => $user->from_body->name, + problem_id => $report->id, + text => '', + confirmed => DateTime->now( time_zone => 'local'), + problem_state => 'investigating', + anonymous => 0, + mark_open => 0, + mark_fixed => 0, + state => 'confirmed', + } + ); + $mech->log_in_ok( $user->email ); + + $mech->get_ok("/report/$report_id"); + + my $update_meta = $mech->extract_update_metas; + like $update_meta->[0], qr/Updated by/, 'updated by meta if no text'; + unlike $update_meta->[0], qr/Test User/, 'commenter name not included'; + like $update_meta->[0], qr/investigating/, 'update meta includes state change'; + + ok $user->user_body_permissions->create({ + body => $body, + permission_type => 'view_body_contribute_details' + }), 'Give user view_body_contribute_details permissions'; + + $mech->get_ok("/report/$report_id"); + $update_meta = $mech->extract_update_metas; + like $update_meta->[0], qr/Updated by/, 'updated by meta if no text'; + like $update_meta->[0], qr/Test User/, 'commenter name included if user has view contribute permission'; + like $update_meta->[0], qr/investigating/, 'update meta includes state change'; +}; + + $user->from_body(undef); $user->update; diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 9f28a6c89..f3958a0a5 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -277,6 +277,85 @@ subtest "it lists shortlisted reports" => sub { }; }; +subtest "it allows body users to filter by subtypes" => 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 }); + + my ($investigating_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'Investigating report'); + my ($scheduled_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'A Scheduled report'); + my ($in_progress_problem) = $mech->create_problems_for_body(1, $body_edin_id, 'In progress report'); + + $investigating_problem->update({ state => 'investigating' }); + $scheduled_problem->update({ state => 'action scheduled' }); + $in_progress_problem->update({ state => 'in progress' }); + + $mech->get_ok('/reports/City+of+Edinburgh+Council'); + $mech->content_contains('<option value="investigating">Investigating</option>'); + $mech->content_contains('<option value="in progress">In progress</option>'); + $mech->content_contains('<option value="action scheduled">Action scheduled</option>'); + $mech->content_contains('<option value="unable to fix">No further action</option>'); + $mech->content_contains('<option value="not responsible">Not responsible</option>'); + $mech->content_contains('<option value="internal referral">Internal referral</option>'); + $mech->content_contains('<option value="duplicate">Duplicate</option>'); + + $mech->get_ok('/reports/City+of+Edinburgh+Council?status=investigating'); + + $in_progress_problem->discard_changes(); + + $mech->content_contains('Investigating report'); + $mech->content_lacks('In progress report'); + $mech->content_lacks('A Scheduled report'); + + $mech->get_ok('/reports/City+of+Edinburgh+Council?status=in progress'); + + $mech->content_lacks('Investigating report'); + $mech->content_contains('In progress report'); + $mech->content_lacks('A Scheduled report'); + }; +}; + +subtest "it does not allow non body users to filter by subtypes" => sub { + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/' + }, sub { + my $user = $mech->log_in_ok( 'test@example.com' ); + $user->update({ from_body => undef }); + + $mech->get_ok('/reports/City+of+Edinburgh+Council'); + $mech->content_lacks('<option value="investigating">Investigating</option>'); + $mech->content_lacks('<option value="in progress">In progress</option>'); + $mech->content_lacks('<option value="action scheduled">Action scheduled</option>'); + $mech->content_lacks('<option value="unable to fix">No further action</option>'); + $mech->content_lacks('<option value="not responsible">Not responsible</option>'); + $mech->content_lacks('<option value="internal referral">Internal referral</option>'); + $mech->content_lacks('<option value="duplicate">Duplicate</option>'); + }; +}; + +subtest "it does not allow body users to filter subcategories for other bodies" => sub { + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/' + }, sub { + my $body = FixMyStreet::App->model('DB::Body')->find( $body_west_id ); + my $user = $mech->log_in_ok( 'test@example.com' ); + $user->update({ from_body => $body }); + + $mech->get_ok('/reports/City+of+Edinburgh+Council'); + + $mech->content_lacks('<option value="investigating">Investigating</option>'); + $mech->content_lacks('<option value="in progress">In progress</option>'); + $mech->content_lacks('<option value="action scheduled">Action scheduled</option>'); + $mech->content_lacks('<option value="unable to fix">No further action</option>'); + $mech->content_lacks('<option value="not responsible">Not responsible</option>'); + $mech->content_lacks('<option value="internal referral">Internal referral</option>'); + $mech->content_lacks('<option value="duplicate">Duplicate</option>'); + }; +}; + subtest "can use translated body name" => sub { FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', |