diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/admin.t | 347 | ||||
-rw-r--r-- | t/app/controller/alert_new.t | 190 | ||||
-rw-r--r-- | t/app/controller/around.t | 26 | ||||
-rw-r--r-- | t/app/controller/index.t | 19 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 31 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 69 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 45 | ||||
-rw-r--r-- | t/app/controller/reports.t | 42 | ||||
-rw-r--r-- | t/cobrand/closest.t | 2 | ||||
-rw-r--r-- | t/open311.t | 37 |
10 files changed, 651 insertions, 157 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 09d99cfdf..839bfd6b9 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -163,19 +163,32 @@ subtest 'check contact creation' => sub { $mech->get_ok('/admin/council_contacts/2650'); $mech->submit_form_ok( { with_fields => { - category => 'test category', - email => 'test@example.com', - note => 'test note', + category => 'test category', + email => 'test@example.com', + note => 'test note', + non_public => undef, } } ); $mech->content_contains( 'test category' ); $mech->content_contains( '<td>test@example.com' ); $mech->content_contains( '<td>test note' ); + $mech->content_contains( '<td>Public' ); + + $mech->submit_form_ok( { with_fields => { + category => 'private category', + email => 'test@example.com', + note => 'test note', + non_public => 'on', + } } ); + + $mech->content_contains( 'private category' ); + $mech->content_contains( '<td>Non Public' ); $mech->submit_form_ok( { with_fields => { category => 'test/category', email => 'test@example.com', note => 'test/note', + non_public => 'on', } } ); $mech->get_ok('/admin/council_edit/2650/test/category'); @@ -187,11 +200,21 @@ subtest 'check contact editing' => sub { $mech->submit_form_ok( { with_fields => { email => 'test2@example.com', note => 'test2 note', + non_public => undef, } } ); $mech->content_contains( 'test category' ); $mech->content_contains( '<td>test2@example.com' ); $mech->content_contains( '<td>test2 note' ); + $mech->content_contains( '<td>Public' ); + + $mech->submit_form_ok( { with_fields => { + email => 'test2@example.com', + note => 'test2 note', + non_public => 'on', + } } ); + + $mech->content_contains( '<td>Non Public' ); $mech->get_ok('/admin/council_edit/2650/test%20category'); $mech->content_contains( '<td><strong>test2@example.com' ); @@ -293,206 +316,229 @@ ok $report, "created test report - $report_id"; foreach my $test ( { description => 'edit report title', - fields => { - title => 'Report to Edit', - detail => 'Detail for Report to Edit', - state => 'confirmed', - name => 'Test User', - email => $user->email, - anonymous => 0, - flagged => undef, - }, - changes => { - title => 'Edited Report', + fields => { + title => 'Report to Edit', + detail => 'Detail for Report to Edit', + state => 'confirmed', + name => 'Test User', + email => $user->email, + anonymous => 0, + flagged => undef, + non_public => undef, }, - log_count => 1, - log_entries => [ qw/edit/ ], - resend => 0, + changes => { title => 'Edited Report', }, + log_count => 1, + log_entries => [qw/edit/], + resend => 0, }, { description => 'edit report description', - fields => { - title => 'Edited Report', - detail => 'Detail for Report to Edit', - state => 'confirmed', - name => 'Test User', - email => $user->email, - anonymous => 0, - flagged => undef, + fields => { + title => 'Edited Report', + detail => 'Detail for Report to Edit', + state => 'confirmed', + name => 'Test User', + email => $user->email, + anonymous => 0, + flagged => undef, + non_public => undef, }, - changes => { - detail => 'Edited Detail', - }, - log_count => 2, - log_entries => [ qw/edit edit/ ], - resend => 0, + changes => { detail => 'Edited Detail', }, + log_count => 2, + log_entries => [qw/edit edit/], + resend => 0, }, { description => 'edit report user name', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'confirmed', - name => 'Test User', - email => $user->email, - anonymous => 0, - flagged => undef, - }, - changes => { - name => 'Edited User', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Test User', + email => $user->email, + anonymous => 0, + flagged => undef, + non_public => undef, }, - log_count => 3, - log_entries => [ qw/edit edit edit/ ], - resend => 0, - user => $user, + changes => { name => 'Edited User', }, + log_count => 3, + log_entries => [qw/edit edit edit/], + resend => 0, + user => $user, }, { description => 'edit report set flagged true', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'confirmed', - name => 'Edited User', - email => $user->email, - anonymous => 0, - flagged => undef, + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user->email, + anonymous => 0, + flagged => undef, + non_public => undef, }, changes => { - flagged => 'on', + flagged => 'on', }, - log_count => 4, - log_entries => [ qw/edit edit edit edit/ ], - resend => 0, - user => $user, + log_count => 4, + log_entries => [qw/edit edit edit edit/], + resend => 0, + user => $user, }, { description => 'edit report user email', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'confirmed', - name => 'Edited User', - email => $user->email, - anonymous => 0, - flagged => 'on', - }, - changes => { - email => $user2->email, + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user->email, + anonymous => 0, + flagged => 'on', + non_public => undef, }, - log_count => 5, - log_entries => [ qw/edit edit edit edit edit/ ], - resend => 0, - user => $user2, + changes => { email => $user2->email, }, + log_count => 5, + log_entries => [qw/edit edit edit edit edit/], + resend => 0, + user => $user2, }, { description => 'change state to unconfirmed', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'confirmed', - name => 'Edited User', - email => $user2->email, - anonymous => 0, - flagged => 'on', - }, - changes => { - state => 'unconfirmed' + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + flagged => 'on', + non_public => undef, }, + changes => { state => 'unconfirmed' }, log_count => 6, - log_entries => [ qw/state_change edit edit edit edit edit/ ], - resend => 0, + log_entries => [qw/state_change edit edit edit edit edit/], + resend => 0, }, { description => 'change state to confirmed', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'unconfirmed', - name => 'Edited User', - email => $user2->email, - anonymous => 0, - flagged => 'on', - }, - changes => { - state => 'confirmed' + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'unconfirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + flagged => 'on', + non_public => undef, }, + changes => { state => 'confirmed' }, log_count => 7, - log_entries => [ qw/state_change state_change edit edit edit edit edit/ ], - resend => 0, + log_entries => [qw/state_change state_change edit edit edit edit edit/], + resend => 0, }, { description => 'change state to fixed', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'confirmed', - name => 'Edited User', - email => $user2->email, - anonymous => 0, - flagged => 'on', - }, - changes => { - state => 'fixed' + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + flagged => 'on', + non_public => undef, }, + changes => { state => 'fixed' }, log_count => 8, - log_entries => [ qw/state_change state_change state_change edit edit edit edit edit/ ], + log_entries => + [qw/state_change state_change state_change edit edit edit edit edit/], resend => 0, }, { description => 'change state to hidden', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'fixed', - name => 'Edited User', - email => $user2->email, - anonymous => 0, - flagged => 'on', - }, - changes => { - state => 'hidden' + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'fixed', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + flagged => 'on', + non_public => undef, }, - log_count => 9, - log_entries => [ qw/state_change state_change state_change state_change edit edit edit edit edit/ ], + changes => { state => 'hidden' }, + log_count => 9, + log_entries => [ + qw/state_change state_change state_change state_change edit edit edit edit edit/ + ], resend => 0, }, { description => 'edit and change state', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'hidden', - name => 'Edited User', - email => $user2->email, - anonymous => 0, - flagged => 'on', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'hidden', + name => 'Edited User', + email => $user2->email, + anonymous => 0, + flagged => 'on', + non_public => undef, }, changes => { - state => 'confirmed', + state => 'confirmed', anonymous => 1, }, - log_count => 11, - log_entries => [ qw/edit state_change state_change state_change state_change state_change edit edit edit edit edit/ ], + log_count => 11, + log_entries => [ + qw/edit state_change state_change state_change state_change state_change edit edit edit edit edit/ + ], resend => 0, }, { description => 'resend', - fields => { - title => 'Edited Report', - detail => 'Edited Detail', - state => 'confirmed', - name => 'Edited User', - email => $user2->email, - anonymous => 1, - flagged => 'on', - }, - changes => { + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 1, + flagged => 'on', + non_public => undef, }, - log_count => 12, - log_entries => [ qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit edit/ ], + changes => {}, + log_count => 12, + log_entries => [ + qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit edit/ + ], resend => 1, }, -) { + { + description => 'non public', + fields => { + title => 'Edited Report', + detail => 'Edited Detail', + state => 'confirmed', + name => 'Edited User', + email => $user2->email, + anonymous => 1, + flagged => 'on', + non_public => undef, + }, + changes => { + non_public => 'on', + }, + log_count => 13, + log_entries => [ + qw/edit resend edit state_change state_change state_change state_change state_change edit edit edit edit edit/ + ], + resend => 0, + }, + ) +{ subtest $test->{description} => sub { $log_entries->reset; $mech->get_ok("/admin/report_edit/$report_id"); @@ -523,6 +569,8 @@ foreach my $test ( } $test->{changes}->{flagged} = 1 if $test->{changes}->{flagged}; + $test->{changes}->{non_public} = 1 if $test->{changes}->{non_public}; + is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'email' } keys %{ $test->{changes} }; if ( $test->{user} ) { @@ -547,6 +595,7 @@ subtest 'change email to new user' => sub { email => $report->user->email, anonymous => 1, flagged => 'on', + non_public => 'on', }; is_deeply( $mech->visible_form_values(), $fields, 'initial form values' ); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index d66590c57..cb787d959 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -464,4 +464,194 @@ subtest "Test normal alert signups and that alerts are sent" => sub { $mech->delete_user($user2); }; +for my $test ( + { + desc => 'check non public reports are not included in council problems alerts', + alert_params => { + alert_type => 'council_problems', + parameter => '2651', + parameter2 => '2651', + } + }, + { + desc => 'check non public reports are not included in ward problems alerts', + alert_params => { + alert_type => 'ward_problems', + parameter => '2651', + parameter2 => '20728', + } + }, + { + desc => 'check non public reports are not included in local problems alerts', + alert_params => { + alert_type => 'local_problems', + parameter => '-3.189944', + parameter2 => '55.951963', + } + }, + { + desc => 'check non public reports are not included in area problems alerts', + alert_params => { + alert_type => 'area_problems', + parameter => '20728', + parameter2 => '20728', + } + }, +) { + subtest $test->{desc} => sub { + my $user1 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } ); + ok $user1, "created test user"; + $user1->alerts->delete; + + my $user2 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } ); + ok $user2, "created test user"; + $user2->alerts->delete; + + my $dt = DateTime->now->add( minutes => -30 ); + my $r_dt = $dt->clone->add( minutes => 20 ); + + my $alert_params = $test->{alert_params}; + $alert_params->{user} = $user1; + $alert_params->{whensubscribed} = $dt; + $alert_params->{confirmed} = 1; + + my $alert_user1 = FixMyStreet::App->model('DB::Alert')->create( $alert_params ); + ok $alert_user1, "alert created"; + + my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { + postcode => 'EH1 1BB', + council => '2651', + areas => ',11808,135007,14419,134935,2651,20728,', + category => 'Street lighting', + title => 'Alert test for non public reports', + detail => 'Testing Detail', + used_map => 1, + name => $user2->name, + anonymous => 0, + state => 'confirmed', + confirmed => $r_dt, + lastupdate => $r_dt, + whensent => $r_dt->clone->add( minutes => 5 ), + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 1, + latitude => '55.951963', + longitude => '-3.189944', + user_id => $user2->id, + non_public => 1, + } ); + + $mech->clear_emails_ok; + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + $mech->email_count_is(0); + + $report->update( { non_public => 0 } ); + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + $mech->email_count_is(1); + my $email = $mech->get_email; + like $email->body, qr/Alert\s+test\s+for\s+non\s+public\s+reports/, 'alert contains public report'; + + $mech->delete_user( $user1 ); + $mech->delete_user( $user2 ); + }; +} + +subtest 'check new updates alerts for non public reports only go to report owner' => sub { + my $user1 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } ); + ok $user1, "created test user"; + $user1->alerts->delete; + + my $user2 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } ); + ok $user2, "created test user"; + $user2->alerts->delete; + + my $user3 = FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'updates@example.com', name => 'Update User' } ); + ok $user3, "created test user"; + + my $dt = DateTime->now->add( minutes => -30 ); + my $r_dt = $dt->clone->add( minutes => 20 ); + + my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { + postcode => 'EH1 1BB', + council => '2651', + areas => ',11808,135007,14419,134935,2651,20728,', + category => 'Street lighting', + title => 'Alert test for non public reports', + detail => 'Testing Detail', + used_map => 1, + name => $user2->name, + anonymous => 0, + state => 'confirmed', + confirmed => $r_dt, + lastupdate => $r_dt, + whensent => $r_dt->clone->add( minutes => 5 ), + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 1, + latitude => '55.951963', + longitude => '-3.189944', + user_id => $user2->id, + non_public => 1, + } ); + + my $update = FixMyStreet::App->model('DB::Comment')->create( { + problem_id => $report->id, + user_id => $user3->id, + name => 'Anonymous User', + mark_fixed => 'false', + text => 'This is some more update text', + state => 'confirmed', + confirmed => $r_dt->clone->add( minutes => 8 ), + anonymous => 't', + } ); + + my $alert_user1 = FixMyStreet::App->model('DB::Alert')->create( { + user => $user1, + alert_type => 'new_updates', + parameter => $report->id, + confirmed => 1, + whensubscribed => $dt, + } ); + ok $alert_user1, "alert created"; + + + $mech->clear_emails_ok; + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + $mech->email_count_is(0); + + my $alert_user2 = FixMyStreet::App->model('DB::Alert')->create( { + user => $user2, + alert_type => 'new_updates', + parameter => $report->id, + confirmed => 1, + whensubscribed => $dt, + } ); + ok $alert_user2, "alert created"; + + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + $mech->email_count_is(1); + my $email = $mech->get_email; + like $email->body, qr/This is some more update text/, 'alert contains update text'; + + $mech->clear_emails_ok; + $report->update( { non_public => 0 } ); + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + $mech->email_count_is(1); + $email = $mech->get_email; + like $email->body, qr/This is some more update text/, 'alert contains update text'; + + $mech->delete_user( $user1 ); + $mech->delete_user( $user2 ); + $mech->delete_user( $user3 ); +}; + done_testing(); diff --git a/t/app/controller/around.t b/t/app/controller/around.t index db03e00f4..e1c76ff9f 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -78,4 +78,30 @@ foreach my $test ( }; } +subtest 'check non public reports are not displayed on around page' => sub { + my $params = { + postcode => 'EH99 1SP', + latitude => 55.9519637512, + longitude => -3.17492254484, + }; + my @edinburgh_problems = + $mech->create_problems_for_council( 5, 2651, 'Around page', $params ); + + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, + "good location" ); + $mech->content_contains( 'Around page Test 3 for 2651', + 'problem to be marked non public visible' ); + + my $private = $edinburgh_problems[2]; + ok $private->update( { non_public => 1 } ), 'problem marked non public'; + + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, + "good location" ); + $mech->content_lacks( 'Around page Test 3 for 2651', + 'problem marked non public is not visible' ); +}; + + done_testing(); diff --git a/t/app/controller/index.t b/t/app/controller/index.t index bf9124ee0..462b21064 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -55,4 +55,23 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub { } }; +$mech->delete_problems_for_council( 2651 ); + +my $problem_rs = FixMyStreet::App->model('DB::Problem'); +my $num = $problem_rs->count; + +my @edinburgh_problems = $mech->create_problems_for_council(5, 2651, 'Front page'); +is scalar @edinburgh_problems, 5, 'correct number of edinburgh problems created'; + +$mech->get_ok('/report/' . $edinburgh_problems[2]->id); +$mech->content_contains('Front page Test 3 for 2651', 'problem to be marked non public visible'); +is $problem_rs->count, $num+5; + +my $private = $edinburgh_problems[2]; +ok $private->update( { non_public => 1 } ), 'problem marked non public'; + +ok $mech->get('/report/' . $edinburgh_problems[2]->id); +is $mech->res->code, 403, 'page forbidden'; +is $problem_rs->count, $num+5; + done_testing(); diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 6c2733e36..3bb0913f1 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -16,6 +16,11 @@ my $user = ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); ok $user, "created test user"; +my $user2 = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test2@example.com', name => 'Other User' } ); +ok $user2, "created test user"; + my $dt = DateTime->new( year => 2011, month => 04, @@ -98,6 +103,32 @@ subtest "change report to hidden and check for 410 status" => sub { ok $report->update( { state => 'confirmed' } ), 'confirm report again'; }; +subtest "change report to non_public and check for 403 status" => sub { + ok $report->update( { non_public => 1 } ), 'make report non public'; + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->res->code, 403, "access denied"; + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + $mech->content_contains('That report cannot be viewed on FixMyStreet.'); + ok $report->update( { non_public => 0 } ), 'make report public'; +}; + +subtest "check owner of report can view non public reports" => sub { + ok $report->update( { non_public => 1 } ), 'make report non public'; + $mech->log_in_ok( $report->user->email ); + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->res->code, 200, "report can be viewed"; + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + $mech->log_out_ok; + + $mech->log_in_ok( $user2->email ); + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->res->code, 403, "access denied to user who is not report creator"; + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + $mech->content_contains('That report cannot be viewed on FixMyStreet.'); + $mech->log_out_ok; + ok $report->update( { non_public => 0 } ), 'make report public'; +}; + subtest "test a good report" => sub { $mech->get_ok("/report/$report_id"); is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 88236a1c3..2e7e60f75 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -788,6 +788,74 @@ foreach my $test ( } +subtest "test report creation for a category that is non public" => sub { + $mech->log_out_ok; + $mech->clear_emails_ok; + + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => $test_email } ); + ok $user, "test user does exist"; + + $contact1->update( { non_public => 1 } ); + + # submit initial pc form + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, + "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + $mech->submit_form_ok( + { + button => 'submit_register', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + email => 'test-2@example.com', + name => 'Joe Bloggs', + category => 'Street lighting', + } + }, + "submit good details" + ); + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # Check the report is not public + ok $report->non_public, 'report is not public'; + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the problem/i, "confirm the problem"; + + my ($url) = $email->body =~ m{(http://\S+)}; + ok $url, "extracted confirm url '$url'"; + + # confirm token + $mech->get_ok($url); + $report->discard_changes; + + is $report->state, 'confirmed', "Report is now confirmed"; + + $mech->logged_in_ok; + $mech->get_ok( '/report/' . $report->id, 'user can see own report' ); + + $mech->log_out_ok; + ok $mech->get("/report/" . $report->id), "fetched report"; + is $mech->res->code, 403, "access denied to report"; + + # cleanup + $mech->delete_user($user); + $contact1->update( { non_public => 0 } ); +}; + $contact2->category( "Pothol\xc3\xa9s" ); $contact2->update; $mech->get_ok( '/report/new/ajax?latitude=' . $saved_lat . '&longitude=' . $saved_lon ); @@ -970,6 +1038,7 @@ SKIP: { $mech->log_out_ok; $mech->get_ok('/around'); + $mech->content_contains( "Lichfield District Council FixMyStreet" ); $mech->submit_form_ok( { with_fields => { pc => 'WS13 7RD' } }, "submit location" ); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index cf6af16cb..82670d6cc 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -577,7 +577,12 @@ for my $test ( is $update->problem_state, $test->{state}, 'problem state set'; my $update_meta = $mech->extract_update_metas; - like $update_meta->[0], qr/marked as $test->{fields}->{state}$/, 'update meta includes state change'; + # setting it to confirmed shouldn't say anything + if ( $test->{fields}->{state} ne 'confirmed' ) { + like $update_meta->[0], qr/marked as $test->{fields}->{state}$/, 'update meta includes state change'; + } else { + like $update_meta->[0], qr/reopened$/, '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'); @@ -586,6 +591,44 @@ for my $test ( }; } +subtest 'check meta correct for comments marked confirmed but not marked open' => sub { + $report->comments->delete; + my $comment = FixMyStreet::App->model('DB::Comment')->create( + { + user => $user, + problem_id => $report->id, + text => 'update text', + confirmed => DateTime->now, + problem_state => 'confirmed', + anonymous => 0, + mark_open => 0, + mark_fixed => 0, + state => 'confirmed', + } + ); + + $mech->get_ok( "/report/" . $report->id ); + my $update_meta = $mech->extract_update_metas; + like $update_meta->[0], qr/reopened$/, + 'update meta does not say reopened'; + + $comment->update( { mark_open => 1, problem_state => undef } ); + $mech->get_ok( "/report/" . $report->id ); + $update_meta = $mech->extract_update_metas; + + unlike $update_meta->[0], qr/marked as open$/, + 'update meta does not says marked as open'; + like $update_meta->[0], qr/reopened$/, 'update meta does say reopened'; + + $comment->update( { mark_open => 0, problem_state => undef } ); + $mech->get_ok( "/report/" . $report->id ); + $update_meta = $mech->extract_update_metas; + + unlike $update_meta->[0], qr/marked as open$/, + 'update meta does not says marked as open'; + unlike $update_meta->[0], qr/reopened$/, 'update meta does not say reopened'; + }; + $user->from_council(0); $user->update; diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 801dbeddb..a4dab6597 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -1,10 +1,21 @@ use strict; use warnings; use Test::More; -use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; +use FixMyStreet::TestMech; use mySociety::MaPit; +use FixMyStreet::App; +use DateTime; -ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); +ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' ); + +$mech->delete_problems_for_council( 2504 ); +$mech->delete_problems_for_council( 2651 ); + +my @edinburgh_problems = $mech->create_problems_for_council(3, 2651, 'All reports'); +my @westminster_problems = $mech->create_problems_for_council(5, 2504, 'All reports'); + +is scalar @westminster_problems, 5, 'correct number of westminster problems created'; +is scalar @edinburgh_problems, 3, 'correct number of edinburgh problems created'; # Run the cron script that makes the data for /reports so we don't get an error. system( "bin/cron-wrapper update-all-reports" ); @@ -13,8 +24,35 @@ system( "bin/cron-wrapper update-all-reports" ); $mech->get_ok('/reports'); $mech->title_like(qr{Summary reports}); $mech->content_contains('Birmingham'); + +my $stats = $mech->extract_report_stats; + +is $stats->{'City of Edinburgh Council'}->[1], 3, 'correct number of reports for Edinburgh'; +is $stats->{'Westminster City Council'}->[1], 5, 'correct number of reports for Westminster'; + $mech->follow_link_ok( { text_regex => qr/Birmingham/ } ); +$mech->get_ok('/reports/Westminster'); +$mech->title_like(qr/Westminster City Council/); +$mech->content_contains('Westminster City Council'); +$mech->content_contains('All reports Test 3 for 2504', 'problem to be marked non public visible'); + +my $problems = $mech->extract_problem_list; +is scalar @$problems, 5, 'correct number of problems displayed'; + +my $private = $westminster_problems[2]; +ok $private->update( { non_public => 1 } ), 'problem marked non public'; + +$mech->get_ok('/reports/Westminster'); +$problems = $mech->extract_problem_list; +is scalar @$problems, 4, 'only public problems are displayed'; + +$mech->content_lacks('All reports Test 3 for 2504', 'non public problem is not visible'); + +$mech->get_ok('/reports'); +$stats = $mech->extract_report_stats; +is $stats->{'Westminster City Council'}->[1], 5, 'non public reports included in stats'; + SKIP: { skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 8 ) unless FixMyStreet::Cobrand->exists('emptyhomes'); diff --git a/t/cobrand/closest.t b/t/cobrand/closest.t index 02c979756..464c95e67 100644 --- a/t/cobrand/closest.t +++ b/t/cobrand/closest.t @@ -54,7 +54,7 @@ ok $report, "created test report - $report_id"; $report->geocode( undef ); -ok !$report->geocode, 'no gecode entry for report'; +ok !$report->geocode, 'no geocode entry for report'; my $near = $c->find_closest( $report->latitude, $report->longitude, $report ); diff --git a/t/open311.t b/t/open311.t index f082179ea..ce0a4ed90 100644 --- a/t/open311.t +++ b/t/open311.t @@ -37,9 +37,10 @@ my $p = FixMyStreet::App->model('DB::Problem')->new( { title => 'title', detail => 'detail', user => $u, + id => 1, } ); -my $expected_error = qr{.*request failed: 500 Can.t connect to 192.168.50.1:80 \([^)]*\).*}; +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'; @@ -410,20 +411,48 @@ for my $test ( }; } +subtest 'No request id in reponse' => sub { + my $results; + warning_like { + $results = make_service_req( + $problem, + { url => 'http://example.com/report/1' }, + $problem->category, + '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id></service_request_id></request></service_requests>' + ); + } qr/Failed to submit problem \d+ over Open311/, 'correct error message for missing request_id'; + + is $results->{ res }, 0, 'No request_id is a failure'; +}; + +subtest 'Bad data in request_id element in reponse' => sub { + my $results; + warning_like { + $results = make_service_req( + $problem, + { url => 'http://example.com/report/1' }, + $problem->category, + '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id><bad_data>BAD</bad_data></service_request_id></request></service_requests>' + ); + } qr/Failed to submit problem \d+ over Open311/, 'correct error message for bad data in request_id'; + + is $results->{ res }, 0, 'No request_id is a failure'; +}; + subtest 'No update id in reponse' => sub { my $results; warning_like { $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id></update_id></request_update></service_request_updates>' ) - } qr/Failed to submit comment \d+ over Open311/, 'correct error message'; + } qr/Failed to submit comment \d+ over Open311/, 'correct error message for missing update_id'; is $results->{ res }, 0, 'No update_id is a failure'; }; -subtest 'error reponse' => sub { +subtest 'error response' => sub { my $results; warning_like { $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><errors><error><code>400</code><description>There was an error</description</error></errors>' ) - } qr/Failed to submit comment \d+ over Open311.*There was an error/, 'correct error messages'; + } qr/Failed to submit comment \d+ over Open311.*There was an error/, 'correct error messages for general error'; is $results->{ res }, 0, 'error in response is a failure'; }; |