diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/contact_enquiry.t | 77 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 4 | ||||
-rw-r--r-- | t/cobrand/bexley.t | 75 |
3 files changed, 120 insertions, 36 deletions
diff --git a/t/app/controller/contact_enquiry.t b/t/app/controller/contact_enquiry.t index fe3962c8e..3f2989695 100644 --- a/t/app/controller/contact_enquiry.t +++ b/t/app/controller/contact_enquiry.t @@ -1,6 +1,10 @@ +use utf8; +use Encode; use FixMyStreet::TestMech; use Path::Tiny; use File::Temp 'tempdir'; +use FixMyStreet::Script::Reports; +use Test::MockModule; # disable info logs for this test run FixMyStreet::App->log->disable('info'); @@ -8,7 +12,12 @@ END { FixMyStreet::App->log->enable('info'); } my $mech = FixMyStreet::TestMech->new; -my $body = $mech->create_body_ok( 2483, 'Hounslow Borough Council' ); +my $body = $mech->create_body_ok( 2483, 'Hounslow Borough Council', { + send_method => 'Open311', + endpoint => 'endpoint', + api_key => 'key', + jurisdiction => 'hounslow', +}); my $contact = $mech->create_contact_ok( body_id => $body->id, category => 'General Enquiry', @@ -163,17 +172,22 @@ ok $sample_jpeg->exists, "sample image $sample_jpeg exists"; my $sample_pdf = path(__FILE__)->parent->child("sample.pdf"); ok $sample_pdf->exists, "sample PDF $sample_pdf exists"; -subtest "Check photo & file upload works" => sub { - my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); - - FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'hounslow' ], - MAPIT_URL => 'http://mapit.uk/', - PHOTO_STORAGE_BACKEND => 'FileSystem', - PHOTO_STORAGE_OPTIONS => { - UPLOAD_DIR => $UPLOAD_DIR, - }, - }, sub { +my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'hounslow' ], + STAGING_FLAGS => { send_reports => 1 }, + MAPIT_URL => 'http://mapit.uk/', + PHOTO_STORAGE_BACKEND => 'FileSystem', + PHOTO_STORAGE_OPTIONS => { + UPLOAD_DIR => $UPLOAD_DIR, + }, +}, sub { + + my $pdf_hash = '90f7a64043fb458d58de1a0703a6355e2856b15e.pdf'; + my $image_hash = '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg'; + + subtest "Check photo & file upload works" => sub { my $problems = FixMyStreet::App->model('DB::Problem')->to_body( $body->id ); $problems->delete_all; @@ -190,7 +204,7 @@ subtest "Check photo & file upload works" => sub { name => 'Test User', username => 'testuser@example.org', category => 'Other', - detail => 'This is a general enquiry', + detail => encode_utf8('This is a general enquiry‽'), photo1 => [ $sample_jpeg, undef, Content_Type => 'image/jpeg' ], photo2 => [ $sample_pdf, undef, Content_Type => 'application/pdf' ], } @@ -199,7 +213,7 @@ subtest "Check photo & file upload works" => sub { is $problems->count, 1, 'problem created'; my $problem = $problems->first; - is $problem->detail, 'This is a general enquiry', 'problem has correct detail'; + is $problem->detail, 'This is a general enquiry‽', 'problem has correct detail'; is $problem->non_public, 1, 'problem created non_public'; is $problem->postcode, ''; is $problem->used_map, 0; @@ -207,20 +221,47 @@ subtest "Check photo & file upload works" => sub { is $problem->longitude, -0.35, 'Problem has correct longitude'; ok $problem->confirmed, 'problem confirmed'; - my $image_file = path($UPLOAD_DIR, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg'); + my $image_file = path($UPLOAD_DIR, $image_hash); ok $image_file->exists, 'Photo uploaded to temp'; my $photoset = $problem->get_photoset(); is $photoset->num_images, 1, 'Found just 1 image'; - is $photoset->data, '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg'; + is $photoset->data, $image_hash; - my $pdf_file = path($UPLOAD_DIR, 'enquiry_files', '90f7a64043fb458d58de1a0703a6355e2856b15e.pdf'); + my $pdf_file = path($UPLOAD_DIR, 'enquiry_files', $pdf_hash); ok $pdf_file->exists, 'PDF uploaded to temp'; is_deeply $problem->get_extra_metadata('enquiry_files'), { - '90f7a64043fb458d58de1a0703a6355e2856b15e.pdf' => 'sample.pdf' + $pdf_hash => 'sample.pdf' }, 'enquiry file info stored OK'; + }; + subtest 'Check Open311 sending of the above report' => sub { + my $module = Test::MockModule->new('FixMyStreet::Cobrand::UKCouncils'); + $module->mock(get => sub ($) { '' }); + my $test_data = FixMyStreet::Script::Reports::send(); + my $req = $test_data->{test_req_used}; + my $found = 0; + foreach ($req->parts) { + my $cd = $_->header('Content-Disposition'); + if ($cd =~ /attribute\[description\]/) { + is decode_utf8($_->content), 'This is a general enquiry‽', 'Correct description'; + $found++; + } + if ($cd =~ /sample.pdf/) { + is $cd, 'form-data; name="file_' . $pdf_hash . '"; filename="sample.pdf"', 'Correct PDF header'; + is $_->header('Content-Type'), 'application/pdf', 'Correct PDF content type'; + $found++; + } + if ($cd =~ /jpeg/) { + is $cd, 'form-data; name="photo1"; filename="' . $image_hash . '"', 'Correct image header'; + is $_->header('Content-Type'), 'image/jpeg', 'Correct image content type'; + $found++; + } + } + is $found, 3, 'Found all tested headers'; }; + }; + done_testing(); diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index bde090dd1..bb5b0a72d 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -78,7 +78,7 @@ subtest "change report to non_public and check for 403 status" => sub { 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.'); + $mech->content_contains('permission to do that. If you are the problem reporter'); ok $report->update( { non_public => 0 } ), 'make report public'; }; @@ -94,7 +94,7 @@ subtest "check owner of report can view non public reports" => sub { 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->content_contains('permission to do that. If you are the problem reporter'); $mech->log_out_ok; ok $report->update( { non_public => 0 } ), 'make report public'; }; diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t index 2f74ac03a..07d7ed91b 100644 --- a/t/cobrand/bexley.t +++ b/t/cobrand/bexley.t @@ -30,11 +30,16 @@ my $mech = FixMyStreet::TestMech->new; my $body = $mech->create_body_ok(2494, 'London Borough of Bexley', { send_method => 'Open311', api_key => 'key', 'endpoint' => 'e', 'jurisdiction' => 'j' }); $mech->create_contact_ok(body_id => $body->id, category => 'Abandoned and untaxed vehicles', email => "ABAN"); +$mech->create_contact_ok(body_id => $body->id, category => 'Lamp post', email => "LAMP"); +$mech->create_contact_ok(body_id => $body->id, category => 'Parks and open spaces', email => "PARK"); +$mech->create_contact_ok(body_id => $body->id, category => 'Dead animal', email => "ANIM"); +$mech->create_contact_ok(body_id => $body->id, category => 'Something dangerous', email => "DANG"); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'bexley' ], MAPIT_URL => 'http://mapit.uk/', STAGING_FLAGS => { send_reports => 1, skip_checks => 0 }, + COBRAND_FEATURES => { open311_email => { bexley => { p1 => 'p1@bexley', lighting => 'thirdparty@notbexley.example.com' } } }, }, sub { subtest 'cobrand displays council name' => sub { @@ -48,24 +53,62 @@ FixMyStreet::override_config { $mech->content_contains('Bexley'); }; - my ($report) = $mech->create_problems_for_body(1, $body->id, 'On Road', { - category => 'Abandoned and untaxed vehicles', cobrand => 'bexley', - latitude => 51.408484, longitude => 0.074653, - }); - $report->set_extra_fields({ 'name' => 'burnt', description => 'Was it burnt?', 'value' => 'Yes' }); - $report->update; + foreach my $test ( + { category => 'Abandoned and untaxed vehicles', email => 1, code => 'ABAN', + extra => { 'name' => 'burnt', description => 'Was it burnt?', 'value' => 'Yes' } }, + { category => 'Abandoned and untaxed vehicles', code => 'ABAN', + extra => { 'name' => 'burnt', description => 'Was it burnt?', 'value' => 'No' } }, + { category => 'Dead animal', email => 1, code => 'ANIM' }, + { category => 'Something dangerous', email => 1, code => 'DANG', + extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } }, + { category => 'Something dangerous', code => 'DANG', + extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'No' } }, + { category => 'Parks and open spaces', email => 1, code => 'PARK', + extra => { 'name' => 'reportType', description => 'Type of report', 'value' => 'Wild animal' } }, + { category => 'Parks and open spaces', code => 'PARK', + extra => { 'name' => 'reportType', description => 'Type of report', 'value' => 'Maintenance' } }, + { category => 'Parks and open spaces', code => 'PARK', + extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } }, + { category => 'Parks and open spaces', email => 1, code => 'PARK', + extra => [ + { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' }, + { 'name' => 'reportType', description => 'Type of report', 'value' => 'Vandalism' }, + ] }, + { category => 'Lamp post', code => 'LAMP', email => 'thirdparty', + extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'No' } }, + { category => 'Lamp post', code => 'LAMP', email => 'p1.*thirdparty', + extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } }, + ) { + my ($report) = $mech->create_problems_for_body(1, $body->id, 'On Road', { + category => $test->{category}, cobrand => 'bexley', + latitude => 51.408484, longitude => 0.074653, + }); + if ($test->{extra}) { + $report->set_extra_fields(ref $test->{extra} eq 'ARRAY' ? @{$test->{extra}} : $test->{extra}); + $report->update; + } - subtest 'Server-side NSGRef included' => sub { - my $test_data = FixMyStreet::Script::Reports::send(); - my $req = $test_data->{test_req_used}; - my $c = CGI::Simple->new($req->content); - is $c->param('service_code'), 'ABAN'; - is $c->param('attribute[NSGRef]'), 'Road ID'; + subtest 'NSGRef and correct email config' => sub { + my $test_data = FixMyStreet::Script::Reports::send(); + my $req = $test_data->{test_req_used}; + my $c = CGI::Simple->new($req->content); + is $c->param('service_code'), $test->{code}; + is $c->param('attribute[NSGRef]'), 'Road ID'; - my $email = $mech->get_email; - like $email->header('To'), qr/"Bexley P1 email".*bexley/; - like $mech->get_text_body_from_email($email), qr/NSG Ref: Road ID/; - }; + if (my $t = $test->{email}) { + my $email = $mech->get_email; + if ($t eq 1) { + like $email->header('To'), qr/"Bexley P1 email".*bexley/; + } else { + like $email->header('To'), qr/$t/; + } + like $mech->get_text_body_from_email($email), qr/NSG Ref: Road ID/; + $mech->clear_emails_ok; + } else { + $mech->email_count_is(0); + } + }; + } }; |