diff options
Diffstat (limited to 't/cobrand')
-rw-r--r-- | t/cobrand/bathnes.t | 197 | ||||
-rw-r--r-- | t/cobrand/bromley.t | 83 | ||||
-rw-r--r-- | t/cobrand/closest.t | 16 | ||||
-rw-r--r-- | t/cobrand/fixmystreet.t | 6 | ||||
-rw-r--r-- | t/cobrand/form_extras.t | 35 | ||||
-rw-r--r-- | t/cobrand/oxfordshire.t | 60 | ||||
-rw-r--r-- | t/cobrand/rutland.t | 61 | ||||
-rw-r--r-- | t/cobrand/zurich.t | 156 |
8 files changed, 500 insertions, 114 deletions
diff --git a/t/cobrand/bathnes.t b/t/cobrand/bathnes.t new file mode 100644 index 000000000..e0ad07c16 --- /dev/null +++ b/t/cobrand/bathnes.t @@ -0,0 +1,197 @@ +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +my $body = $mech->create_body_ok(2551, 'Bath and North East Somerset Council'); +my @cats = ('Litter', 'Other', 'Potholes', 'Traffic lights'); +for my $contact ( @cats ) { + $mech->create_contact_ok(body_id => $body->id, category => $contact, email => "$contact\@example.org"); +} +my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1); +my $counciluser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $body); +my $normaluser = $mech->create_user_ok('normaluser@example.com', name => 'Normal User'); +$normaluser->update({ phone => "+447123456789" }); + +$mech->create_problems_for_body(1, $body->id, 'Title', { + areas => ",2651,", category => 'Potholes', cobrand => 'fixmystreet', + user => $normaluser, service => 'iOS', extra => { + _fields => [ + { + description => 'Width of pothole?', + name => "width", + value => "10cm" + }, + { + description => 'Depth of pothole?', + name => "depth", + value => "25cm" + }, + ] + } +}); +$mech->create_problems_for_body(1, $body->id, 'Title', { + areas => ",2651,", category => 'Traffic lights', cobrand => 'bathnes', + user => $counciluser, extra => { + contributed_as => 'body', + } +}); +$mech->create_problems_for_body(1, $body->id, 'Title', { + areas => ",2651,", category => 'Litter', cobrand => 'bathnes', + user => $normaluser, extra => { + contributed_as => 'another_user', + contributed_by => $counciluser->id, + } +}); +$mech->create_problems_for_body(1, $body->id, 'Title', { + areas => ",2651,", category => 'Other', cobrand => 'bathnes', + user => $counciluser, extra => { + contributed_as => 'anonymous_user', + } +}); + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'bathnes' ], + MAPIT_URL => 'http://mapit.uk/', +}, sub { + +subtest 'cobrand displays council name' => sub { + ok $mech->host("bathnes.fixmystreet.com"), "change host to bathnes"; + $mech->get_ok('/'); + $mech->content_like( qr/Bath and North East Somerset\b/ ); +}; + +subtest 'extra CSV columns are absent if permission not granted' => sub { + $mech->log_in_ok( $counciluser->email ); + + $mech->get_ok('/dashboard?export=1'); + + open my $data_handle, '<', \$mech->content; + my $csv = Text::CSV->new( { binary => 1 } ); + my @rows; + while ( my $row = $csv->getline( $data_handle ) ) { + push @rows, $row; + } + is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; + + is scalar @{$rows[0]}, 18, '18 columns present'; + + is_deeply $rows[0], + [ + 'Report ID', + 'Title', + 'Detail', + 'User Name', + 'Category', + 'Created', + 'Confirmed', + 'Acknowledged', + 'Fixed', + 'Closed', + 'Status', + 'Latitude', + 'Longitude', + 'Query', + 'Ward', + 'Easting', + 'Northing', + 'Report URL', + ], + 'Column headers look correct'; +}; + +subtest "Custom CSV fields permission can be granted" => sub { + $mech->log_in_ok( $superuser->email ); + + is $counciluser->user_body_permissions->count, 0, 'counciluser has no permissions'; + + $mech->get_ok("/admin/user_edit/" . $counciluser->id); + $mech->content_contains('Extra columns in CSV export'); + + $mech->submit_form_ok( { with_fields => { + name => $counciluser->name, + email => $counciluser->email, + body => $counciluser->from_body->id, + phone => '', + flagged => undef, + "permissions[export_extra_columns]" => 'on', + } } ); + + ok $counciluser->has_body_permission_to("export_extra_columns"), "counciluser has been granted CSV extra fields permission"; +}; + +subtest 'extra CSV columns are present if permission granted' => sub { + $mech->log_in_ok( $counciluser->email ); + + $mech->get_ok('/dashboard?export=1'); + + open my $data_handle, '<', \$mech->content; + my $csv = Text::CSV->new( { binary => 1 } ); + my @rows; + while ( my $row = $csv->getline( $data_handle ) ) { + push @rows, $row; + } + is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; + + is scalar @{$rows[0]}, 24, '24 columns present'; + + is_deeply $rows[0], + [ + 'Report ID', + 'Title', + 'Detail', + 'User Name', + 'Category', + 'Created', + 'Confirmed', + 'Acknowledged', + 'Fixed', + 'Closed', + 'Status', + 'Latitude', + 'Longitude', + 'Query', + 'Ward', + 'Easting', + 'Northing', + 'Report URL', + 'User Email', + 'User Phone', + 'Reported As', + 'Staff User', + 'Attribute Data', + 'Site Used', + ], + 'Column headers look correct'; + + is $rows[1]->[18], 'normaluser@example.com', 'User email is correct'; + is $rows[1]->[19], '+447123456789', 'User phone number is correct'; + is $rows[1]->[20], '', 'Reported As is empty if not made on behalf of another user/body'; + is $rows[1]->[21], '', 'Staff User is empty if not made on behalf of another user'; + is $rows[1]->[22], 'width = 10cm; depth = 25cm', 'Attribute Data is correct'; + is $rows[1]->[23], 'iOS', 'Site Used shows whether report made via app'; + + is $rows[2]->[18], 'counciluser@example.com', 'User email is correct'; + is $rows[2]->[19], '', 'User phone number is correct'; + is $rows[2]->[20], 'body', 'Reported As is correct if made on behalf of body'; + is $rows[2]->[21], '', 'Staff User is empty if not made on behalf of another user'; + is $rows[2]->[22], '', 'Attribute Data is correct'; + is $rows[2]->[23], 'bathnes', 'Site Used shows correct cobrand'; + + is $rows[3]->[18], 'normaluser@example.com', 'User email is correct'; + is $rows[3]->[19], '+447123456789', 'User phone number is correct'; + is $rows[3]->[20], 'another_user', 'Reported As is set if reported on behalf of another user'; + is $rows[3]->[21], 'counciluser@example.com', 'Staff User is correct if made on behalf of another user'; + is $rows[3]->[22], '', 'Attribute Data is correct'; + is $rows[3]->[23], 'bathnes', 'Site Used shows correct cobrand'; + + is $rows[4]->[18], 'counciluser@example.com', 'User email is correct'; + is $rows[4]->[19], '', 'User phone number is correct'; + is $rows[4]->[20], 'anonymous_user', 'Reported As is set if reported on behalf of another user'; + is $rows[4]->[21], '', 'Staff User is empty if not made on behalf of another user'; + is $rows[4]->[22], '', 'Attribute Data is correct'; + is $rows[4]->[23], 'bathnes', 'Site Used shows correct cobrand'; +}; + + +}; + +done_testing(); diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t index 41e351dea..b3fb3564b 100644 --- a/t/cobrand/bromley.t +++ b/t/cobrand/bromley.t @@ -46,29 +46,68 @@ $mech->content_contains( 'State changed to: In progress' ); $mech->content_contains( 'marks it as unable to fix' ); $mech->content_contains( 'State changed to: No further action' ); -subtest 'testing special Open311 behaviour', sub { - $report->set_extra_fields(); - $report->update; - $body->update( { send_method => 'Open311', endpoint => 'http://bromley.endpoint.example.com', jurisdiction => 'FMS', api_key => 'test', send_comments => 1 } ); - my $test_data; - FixMyStreet::override_config { - STAGING_FLAGS => { send_reports => 1 }, - ALLOWED_COBRANDS => [ 'fixmystreet', 'bromley' ], - }, sub { - $test_data = FixMyStreet::Script::Reports::send(); - }; - $report->discard_changes; - ok $report->whensent, 'Report marked as sent'; - is $report->send_method_used, 'Open311', 'Report sent via Open311'; - is $report->external_id, 248, 'Report has right external ID'; +for my $test ( + { + desc => 'testing special Open311 behaviour', + updates => {}, + expected => { + 'attribute[easting]' => 529025, + 'attribute[northing]' => 179716, + 'attribute[service_request_id_ext]' => $report->id, + 'attribute[report_title]' => 'Test Test 1 for ' . $body->id, + 'jurisdiction_id' => 'FMS', + address_id => undef, + }, + }, + { + desc => 'testing Open311 behaviour with no map click or postcode', + updates => { + used_map => 0, + postcode => '' + }, + expected => { + 'attribute[easting]' => 529025, + 'attribute[northing]' => 179716, + 'attribute[service_request_id_ext]' => $report->id, + 'jurisdiction_id' => 'FMS', + 'address_id' => '#NOTPINPOINTED#', + }, + }, + { + desc => 'asset ID', + feature_id => '1234', + expected => { + 'attribute[service_request_id_ext]' => $report->id, + 'attribute[report_title]' => 'Test Test 1 for ' . $body->id . ' | ID: 1234', + }, + }, +) { + subtest $test->{desc}, sub { + $report->$_($test->{updates}->{$_}) for keys %{$test->{updates}}; + $report->$_(undef) for qw/ whensent send_method_used external_id /; + $report->set_extra_fields({ name => 'feature_id', value => $test->{feature_id} }) + if $test->{feature_id}; + $report->update; + $body->update( { send_method => 'Open311', endpoint => 'http://bromley.endpoint.example.com', jurisdiction => 'FMS', api_key => 'test', send_comments => 1 } ); + my $test_data; + FixMyStreet::override_config { + STAGING_FLAGS => { send_reports => 1 }, + ALLOWED_COBRANDS => [ 'fixmystreet', 'bromley' ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $test_data = FixMyStreet::Script::Reports::send(); + }; + $report->discard_changes; + ok $report->whensent, 'Report marked as sent'; + is $report->send_method_used, 'Open311', 'Report sent via Open311'; + is $report->external_id, 248, 'Report has right external ID'; - my $req = $test_data->{test_req_used}; - my $c = CGI::Simple->new($req->content); - is $c->param('attribute[easting]'), 529025, 'Request had easting'; - is $c->param('attribute[northing]'), 179716, 'Request had northing'; - is $c->param('attribute[service_request_id_ext]'), $report->id, 'Request had correct ID'; - is $c->param('jurisdiction_id'), 'FMS', 'Request had correct jurisdiction'; -}; + my $req = $test_data->{test_req_used}; + my $c = CGI::Simple->new($req->content); + is $c->param($_), $test->{expected}->{$_}, "Request had correct $_" + for keys %{$test->{expected}}; + }; +} for my $test ( { diff --git a/t/cobrand/closest.t b/t/cobrand/closest.t index 36fe78a01..6d28bb6f1 100644 --- a/t/cobrand/closest.t +++ b/t/cobrand/closest.t @@ -72,8 +72,18 @@ FixMyStreet::override_config { $near = $c->find_closest_address_for_rss($report); ok !$near, 'no closest address for RSS if not cached'; + + my $json = $mech->get_ok_json('/ajax/closest?lat=55&lon=-1'); + is_deeply $json, {"road"=> "Constitution Hill","full_address"=>"Constitution Hill, London, SW1A"}; +}; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => 'fixmystreet', + MAPIT_URL => 'http://mapit.uk/', + BING_MAPS_API_KEY => 'test', +}, sub { + my $json = $mech->get_ok_json('/ajax/closest?lat=55.952055&lon=-3.189579'); + is_deeply $json, {"road"=> "Constitution Hill","full_address"=>"Constitution Hill, London, SW1A"}; }; -END { - done_testing(); -} +done_testing(); diff --git a/t/cobrand/fixmystreet.t b/t/cobrand/fixmystreet.t index 30d5765a2..57ab51198 100644 --- a/t/cobrand/fixmystreet.t +++ b/t/cobrand/fixmystreet.t @@ -18,6 +18,9 @@ FixMyStreet::override_config { $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard($body); }; +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', TEST_DASHBOARD_DATA => $data, @@ -29,8 +32,7 @@ FixMyStreet::override_config { is $mech->uri->path, '/about/council-dashboard'; $mech->submit_form_ok({ with_fields => { username => 'someone@somewhere.example.org' }}); - $mech->content_contains('We will be in touch'); - # XXX Check email arrives + $mech->content_contains('did not recognise your email'); $mech->log_in_ok('someone@somewhere.example.org'); $mech->get_ok('/reports/Birmingham/summary'); diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t index 84ded5bc1..df76ccbe1 100644 --- a/t/cobrand/form_extras.t +++ b/t/cobrand/form_extras.t @@ -2,7 +2,10 @@ package FixMyStreet::Cobrand::Tester; use parent 'FixMyStreet::Cobrand::FixMyStreet'; sub report_form_extras { - ( { name => 'address', required => 1 }, { name => 'passport', required => 0 } ) + ( + { name => 'address', required => 1 }, + { name => 'passport', required => 0, validator => sub { die "Invalid number\n" if $_[0] && $_[0] !~ /^P/; return $_[0] } }, + ) } # To allow a testing template override @@ -30,6 +33,7 @@ FixMyStreet::override_config { $mech->get_ok('/around'); $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); $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 => { @@ -38,13 +42,24 @@ FixMyStreet::override_config { name => 'Joe Bloggs', may_show_name => '1', username => 'test-1@example.com', - passport => '123456', password_register => '', } }, - "submit details without address, with passport", + "submit details without address or passport", ); $mech->content_like(qr{<label for="form_address">Address</label>\s*<p class='form-error'>This information is required</p>}, 'Address is required'); + $mech->content_lacks("<p class='form-error'>Invalid number", 'Passport is optional'); + + $mech->submit_form_ok( { + button => 'submit_register', + with_fields => { + passport => '123456', + } + }, + "submit details with bad passport", + ); + $mech->content_like(qr{<label for="form_address">Address</label>\s*<p class='form-error'>This information is required</p>}, 'Address is required'); + $mech->content_like(qr{<p class='form-error'>Invalid number}, 'Passport format wrong'); $mech->content_contains('value="123456" name="passport"', 'Passport number reshown'); $mech->submit_form_ok( { @@ -55,11 +70,23 @@ FixMyStreet::override_config { }, "submit details, now with address", ); + $mech->content_lacks('This information is required', 'Address is present'); + $mech->content_like(qr{<p class='form-error'>Invalid number}, 'Passport format wrong'); + $mech->content_contains('value="123456" name="passport"', 'Passport number reshown'); + + $mech->submit_form_ok( { + button => 'submit_register', + with_fields => { + passport => 'P123456', + } + }, + "submit details with correct passport", + ); $mech->content_contains('Now check your email'); my $problem = FixMyStreet::DB->resultset('Problem')->search({}, { order_by => '-id' })->first; is $problem->get_extra_metadata('address'), 'My address', 'Address is stored'; - is $problem->get_extra_metadata('passport'), '123456', 'Passport number is stored'; + is $problem->get_extra_metadata('passport'), 'P123456', 'Passport number is stored'; }; END { diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t index ee30e7e0b..19a82742a 100644 --- a/t/cobrand/oxfordshire.t +++ b/t/cobrand/oxfordshire.t @@ -81,8 +81,8 @@ subtest 'Exor file looks okay' => sub { $mech->log_in_ok( $superuser->email ); $mech->get_ok('/admin/exordefects'); $mech->submit_form_ok( { with_fields => { - start_date => '05/05/2017', - end_date => '05/05/2017', + start_date => '2017-05-05', + end_date => '2017-05-05', user_id => $inspector->id, } }, 'submit download'); $mech->content_contains("No inspections by that inspector in the selected date range"); @@ -120,8 +120,8 @@ subtest 'Exor file looks okay' => sub { $i++; } $mech->submit_form_ok( { with_fields => { - start_date => '05/05/2017', - end_date => '05/05/2017', + start_date => '2017-05-05', + end_date => '2017-05-05', user_id => $inspector->id, } }, 'submit download'); (my $rdi = $mech->content) =~ s/\r\n/\n/g; @@ -159,6 +159,7 @@ EOF subtest 'Reports are marked as inspected correctly' => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'oxfordshire' ], + MAPIT_URL => 'http://mapit.uk/', }, sub { my $date = DateTime->new(year => 2017, month => 5, day => 5, hour => 12); @@ -185,57 +186,6 @@ subtest 'Reports are marked as inspected correctly' => sub { }; }; -subtest 'response times messages displayed' => sub { - my $oxfordshire = $mech->create_body_ok( - 2237, 'Oxfordshire County Council' - ); - my $contact = $mech->create_contact_ok( - body_id => $oxfordshire->id, - category => 'Pothole', - email => 'pothole@example.com', - ); - - FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'oxfordshire' ], - MAPIT_URL => 'http://mapit.uk/', - }, sub { - $mech->log_out_ok; - $mech->clear_emails_ok; - - $mech->get_ok('/around'); - $mech->submit_form_ok( { - with_fields => { pc => 'OX20 1SZ' } - }, - "submit_location" - ); - - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); - - $mech->submit_form_ok( - { - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo1 => '', - username => 'test-2@example.com', - name => 'Test User', - category => 'Pothole', - } - }, - "submit details" - ); - - $mech->text_contains('Problems in the Pothole category are generally responded'); - my $email = $mech->get_email; - ok $email, 'got and email'; - like $mech->get_text_body_from_email, qr/Problems in the Pothole category/, 'emails contains response time message'; - my $url = $mech->get_link_from_email($email); - $mech->get_ok($url); - $mech->text_contains('Problems in the Pothole category are generally responded') - }; -}; - END { done_testing(); } diff --git a/t/cobrand/rutland.t b/t/cobrand/rutland.t new file mode 100644 index 000000000..4d3c4befd --- /dev/null +++ b/t/cobrand/rutland.t @@ -0,0 +1,61 @@ +use CGI::Simple; +use FixMyStreet::TestMech; +use FixMyStreet::Script::Reports; +my $mech = FixMyStreet::TestMech->new; + +# Create test data +my $user = $mech->create_user_ok( 'rutland@example.com' ); +my $body = $mech->create_body_ok( 2482, 'Rutland County Council'); +my $contact = $mech->create_contact_ok( + body_id => $body->id, + category => 'Other', + email => 'LIGHT', +); +$contact->update; + +my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', { + cobrand => 'rutland', + user => $user, +}); +my $report = $reports[0]; + +for my $update ('in progress', 'unable to fix') { + FixMyStreet::DB->resultset('Comment')->find_or_create( { + problem_state => $update, + problem_id => $report->id, + user_id => $user->id, + name => 'User', + mark_fixed => 'f', + text => "This update marks it as $update", + state => 'confirmed', + confirmed => 'now()', + anonymous => 'f', + } ); +} + +subtest 'testing special Open311 behaviour', sub { + $report->set_extra_fields(); + $report->update; + $body->update( { send_method => 'Open311', endpoint => 'http://rutland.endpoint.example.com', jurisdiction => 'FMS', api_key => 'test', send_comments => 1 } ); + my $test_data; + FixMyStreet::override_config { + STAGING_FLAGS => { send_reports => 1 }, + ALLOWED_COBRANDS => [ 'fixmystreet', 'rutland' ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $test_data = FixMyStreet::Script::Reports::send(); + }; + $report->discard_changes; + ok $report->whensent, 'Report marked as sent'; + is $report->send_method_used, 'Open311', 'Report sent via Open311'; + is $report->external_id, 248, 'Report has right external ID'; + + my $req = $test_data->{test_req_used}; + my $c = CGI::Simple->new($req->content); + is $c->param('attribute[title]'), $report->title, 'Request had title'; + is $c->param('attribute[description]'), $report->detail, 'Request had description'; + is $c->param('attribute[external_id]'), $report->id, 'Request had correct ID'; + is $c->param('jurisdiction_id'), 'FMS', 'Request had correct jurisdiction'; +}; + +done_testing(); diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 385f7f077..eccb0c8eb 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -23,6 +23,7 @@ my $mech = FixMyStreet::TestMech->new; use FixMyStreet; my $cobrand = FixMyStreet::Cobrand::Zurich->new(); +$cobrand->db_state_migration; my $sample_file = path(__FILE__)->parent->parent->child("app/controller/sample.jpg"); ok $sample_file->exists, "sample file $sample_file exists"; @@ -48,7 +49,7 @@ sub reset_report_state { $report->unset_extra_metadata('closed_overdue'); $report->unset_extra_metadata('closure_status'); $report->whensent(undef); - $report->state('unconfirmed'); + $report->state('submitted'); $report->created($created) if $created; $report->update; } @@ -109,7 +110,7 @@ subtest "set up superuser" => sub { }; my @reports = $mech->create_problems_for_body( 1, $division->id, 'Test', { - state => 'unconfirmed', + state => 'submitted', confirmed => undef, cobrand => 'zurich', areas => ',423017,', @@ -125,6 +126,89 @@ FixMyStreet::override_config { $mech->content_contains('Überprüfung ausstehend') or die $mech->content; +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + MAP_TYPE => 'Zurich,OSM', +}, sub { + my $json = $mech->get_ok_json( '/report/ajax/' . $report->id ); + is $json->{report}->{title}, "Überprüfung ausstehend", "correct title"; + is $json->{report}->{state}, "submitted", "correct state"; +}; + +subtest "Banners are displayed correctly" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + MAP_TYPE => 'Zurich,OSM', + }, sub { + for my $test ( + { + description => 'new report', + state => 'submitted', + banner_id => 'closed', + banner_text => 'Erfasst' + }, + { + description => 'confirmed report', + state => 'confirmed', + banner_id => 'closed', + banner_text => 'Aufgenommen', + }, + { + description => 'fixed report', + state => 'fixed - council', + banner_id => 'fixed', + banner_text => 'Beantwortet', + }, + { + description => 'closed report', + state => 'external', + banner_id => 'closed', + banner_text => 'Extern', + }, + { + description => 'in progress report', + state => 'in progress', + banner_id => 'progress', + banner_text => 'In Bearbeitung', + }, + { + description => 'planned report', + state => 'feedback pending', + banner_id => 'progress', + banner_text => 'In Bearbeitung', + }, + { + description => 'jurisdiction unknown', + state => 'jurisdiction unknown', + banner_id => 'fixed', + banner_text => 'Zust\x{e4}ndigkeit unbekannt', + }, + ) { + subtest "banner for $test->{description}" => sub { + $report->state( $test->{state} ); + $report->update; + + $mech->get_ok("/report/" . $report->id); + is $mech->uri->path, "/report/" . $report->id, "at /report/" . $report->id; + my $banner = $mech->extract_problem_banner; + if ( $banner->{text} ) { + $banner->{text} =~ s/^ //g; + $banner->{text} =~ s/ $//g; + } + + is $banner->{id}, $test->{banner_id}, 'banner id'; + if ($test->{banner_text}) { + like_string( $banner->{text}, qr/$test->{banner_text}/i, 'banner text is ' . $test->{banner_text} ); + } else { + is $banner->{text}, $test->{banner_text}, 'banner text'; + } + + }; + } + $report->update({ state => 'submitted' }); + }; +}; + # Check logging in to deal with this report FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'zurich' ], @@ -158,7 +242,7 @@ subtest "changing of categories" => sub { ); } - # full Categories dropdown is hidden for unconfirmed reports + # full Categories dropdown is hidden for submitted reports $report->update({ state => 'confirmed' }); # put report into known category @@ -269,17 +353,18 @@ subtest "report_edit" => sub { $mech->get_ok( '/admin/report_edit/' . $report->id ); $mech->submit_form_ok( { with_fields => { state => 'hidden' } } ); - $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->get_ok( '/report/' . $report->id, 'still visible as response not published yet' ); $report->discard_changes; is ( $report->get_extra_metadata('moderated_overdue'), 0, 'Still marked moderated_overdue' ); is ( $report->get_extra_metadata('closed_overdue'), undef, "Marking hidden doesn't set closed_overdue..." ); - is ( $report->state, 'planned', 'Marking hidden actually sets state to planned'); + is ( $report->state, 'feedback pending', 'Marking hidden actually sets state to feedback pending'); is ( $report->get_extra_metadata('closure_status'), 'hidden', 'Marking hidden sets closure_status to hidden'); is get_moderated_count(), 1, 'Check still counted moderated' or diag $report->get_column('extra'); # publishing actually sets hidden + $mech->get_ok( '/admin/report_edit/' . $report->id ); $mech->form_with_fields( 'status_update' ); $mech->submit_form_ok( { button => 'publish_response' } ); $mech->get_ok( '/admin/report_edit/' . $report->id ); @@ -289,6 +374,12 @@ subtest "report_edit" => sub { is ( $report->state, 'hidden', 'Closing as hidden sets state to hidden'); is ( $report->get_extra_metadata('closure_status'), undef, 'Closing as hidden unsets closure_status'); + $mech->submit_form_ok( { with_fields => { new_internal_note => 'Initial internal note.' } } ); + $report->discard_changes; + is ( $report->state, 'hidden', 'Another internal note does not reopen'); + + $mech->get( '/report/' . $report->id); + is $mech->res->code, 410; reset_report_state($report); is ( $report->get_extra_metadata('moderated_overdue'), undef, 'Sanity check' ); @@ -404,6 +495,12 @@ subtest 'SDM' => sub { $mech->submit_form_ok( { button => 'no_more_updates' } ); is $mech->uri->path, '/admin/summary', "redirected now finished with report."; + # Can still view the edit page but can't change anything + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->content_contains('<input disabled'); + $mech->submit_form_ok( { with_fields => { status_update => 'This is a disallowed update.' } } ); + $mech->content_lacks('This is a disallowed update'); + $mech->get_ok( '/report/' . $report->id ); $mech->content_contains('In Bearbeitung'); $mech->content_contains('Test Test'); @@ -416,7 +513,7 @@ subtest 'SDM' => sub { $mech->clear_emails_ok; $report->discard_changes; - is $report->state, 'planned', 'Report now in planned state'; + is $report->state, 'feedback pending', 'Report now in feedback pending state'; subtest 'send_back' => sub { FixMyStreet::override_config { @@ -441,8 +538,8 @@ subtest 'SDM' => sub { $mech->get_ok( '/admin/report_edit/' . $report->id ); $mech->submit_form_ok( { button => 'not_contactable', form_number => 2 } ); $report->discard_changes; - is $report->state, 'planned', 'Report sent back to Rueckmeldung ausstehend state'; - is $report->get_extra_metadata('closure_status'), 'partial', 'Report sent back to partial (not_contactable) state'; + is $report->state, 'feedback pending', 'Report sent back to Rueckmeldung ausstehend state'; + is $report->get_extra_metadata('closure_status'), 'not contactable', 'Report sent back to not_contactable state'; is $report->bodies_str, $division->id, 'Report sent back to division'; }; }; @@ -458,7 +555,7 @@ FixMyStreet::override_config { }; reset_report_state($report); -$report->update({ state => 'planned' }); +$report->update({ state => 'feedback pending' }); $mech->content_contains( 'report_edit/' . $report->id ); $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") ); @@ -493,9 +590,9 @@ like $email->header('From'), qr/do-not-reply\@example.org/, 'from line looks cor like $email->body, qr/FINAL UPDATE/, 'body looks correct'; $mech->clear_emails_ok; -# Assign planned (via confirmed), don't confirm email +# Assign feedback pending (via confirmed), don't confirm email @reports = $mech->create_problems_for_body( 1, $division->id, 'Second', { - state => 'unconfirmed', + state => 'submitted', confirmed => undef, cobrand => 'zurich', areas => ',423017,', @@ -509,7 +606,7 @@ FixMyStreet::override_config { $mech->get_ok( '/admin/report_edit/' . $report->id ); $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } ); $mech->get_ok( '/admin/report_edit/' . $report->id ); - $mech->submit_form_ok( { with_fields => { state => 'planned' } } ); + $mech->submit_form_ok( { with_fields => { state => 'feedback pending' } } ); $mech->get_ok( '/report/' . $report->id ); }; $mech->content_contains('In Bearbeitung'); @@ -536,7 +633,7 @@ $mech->email_count_is(0); # Report assigned to third party @reports = $mech->create_problems_for_body( 1, $division->id, 'Third', { - state => 'unconfirmed', + state => 'submitted', confirmed => undef, cobrand => 'zurich', areas => ',423017,', @@ -551,8 +648,8 @@ subtest "external report triggers email" => sub { }, sub { # required to see body_external field - $report->state('planned'); - $report->set_extra_metadata('closure_status' => 'closed'); + $report->state('feedback pending'); + $report->set_extra_metadata('closure_status' => 'external'); # Set the public_response manually here because the default one will have line breaks that get escaped as HTML, causing the comparison to fail. $report->set_extra_metadata('public_response' => 'Freundliche Gruesse Ihre Stadt Zuerich'); $report->update; @@ -568,7 +665,7 @@ subtest "external report triggers email" => sub { $report->discard_changes; $mech->get_ok( '/report/' . $report->id ); }; - is ($report->state, 'closed', 'Report was closed correctly'); + is ($report->state, 'external', 'Report was closed correctly'); $mech->content_contains('Extern') or die $mech->content; $mech->content_contains('Third Test'); @@ -589,8 +686,8 @@ subtest "external report triggers email" => sub { }, sub { $mech->get_ok( '/admin' ); # required to see body_external field - $report->state('planned'); - $report->set_extra_metadata('closure_status' => 'closed'); + $report->state('feedback pending'); + $report->set_extra_metadata('closure_status' => 'external'); $report->set_extra_metadata('public_response' => 'Freundliche Gruesse Ihre Stadt Zuerich'); $report->update; @@ -625,10 +722,10 @@ subtest "external report triggers email" => sub { }, sub { # set as wish $report->discard_changes; - $report->state('planned'); - $report->set_extra_metadata('closure_status' => 'investigating'); + $report->state('feedback pending'); + $report->set_extra_metadata('closure_status' => 'wish'); $report->update; - is ($report->state, 'planned', 'Sanity check') or die; + is ($report->state, 'feedback pending', 'Sanity check') or die; $mech->get_ok( '/admin/report_edit/' . $report->id ); @@ -639,6 +736,9 @@ subtest "external report triggers email" => sub { body_external => $external_body->id, external_message => $EXTERNAL_MESSAGE, } }); + # Wishes publicly viewable + $mech->get_ok( '/report/' . $report->id ); + $mech->content_contains('Freundliche Gruesse Ihre Stadt Zuerich'); }; send_reports_for_zurich(); $email = $mech->get_email; @@ -658,12 +758,12 @@ subtest "external report triggers email" => sub { }, sub { # set as extern reset_report_state($report); - $report->state('planned'); - $report->set_extra_metadata('closure_status' => 'closed'); + $report->state('feedback pending'); + $report->set_extra_metadata('closure_status' => 'external'); $report->set_extra_metadata('email_confirmed' => 1); $report->unset_extra_metadata('public_response'); $report->update; - is ($report->state, 'planned', 'Sanity check') or die; + is ($report->state, 'feedback pending', 'Sanity check') or die; $mech->get_ok( '/admin/report_edit/' . $report->id ); @@ -865,7 +965,7 @@ subtest "test admin_log" => sub { # XXX: following is dependent on all of test up till now, rewrite to explicitly # test which things need to be logged! is scalar @entries, 4, 'State changes logged'; - is $entries[-1]->action, 'state change to closed', 'State change logged as expected'; + is $entries[-1]->action, 'state change to external', 'State change logged as expected'; }; subtest 'email images to external partners' => sub { @@ -885,7 +985,7 @@ subtest 'email images to external partners' => sub { # The below email comparison must not have an external message. $report->unset_extra_metadata('external_message'); $report->update({ - state => 'closed', + state => 'external', photo => $fileid, external_body => $external_body->id, }); @@ -937,9 +1037,9 @@ subtest 'Status update shown as appropriate' => sub { }, sub { # ALL closed states must hide the public_response edit, and public ones # must show the answer in blue. - for (['planned', 1, 0, 0], + for (['feedback pending', 1, 0, 0], ['fixed - council', 0, 1, 0], - ['closed', 0, 1, 0], + ['external', 0, 1, 0], ['hidden', 0, 0, 1]) { my ($state, $update, $public, $user_response) = @$_; |