diff options
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/alert_new.t | 2 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 67 | ||||
-rw-r--r-- | t/app/model/alert_type.t | 2 |
3 files changed, 69 insertions, 2 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 5ea73625a..3a4c2ef81 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -452,7 +452,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { $count++ if $_->body =~ /The following updates have been left on this problem:/; $count++ if $_->body =~ /The following new problems have been reported to City of\s*Edinburgh Council:/; $count++ if $_->body =~ /The following nearby problems have been added:/; - $count++ if $_->body =~ / -\s+Testing, EH1 1BB/; + $count++ if $_->body =~ /\s+-\s+Testing,\s+EH1\s+1BB/; } is $count, 5, 'Five emails with the right things in them'; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 625c7531f..c16befd37 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -6,10 +6,14 @@ use utf8; use FixMyStreet::TestMech; use Web::Scraper; +use Path::Class; my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/report/new'); +my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; +ok -e $sample_file, "sample file $sample_file exists"; + subtest "test that bare requests to /report/new get redirected" => sub { $mech->get_ok('/report/new'); @@ -282,6 +286,69 @@ foreach my $test ( }, errors => [ 'Please enter a subject', 'Please enter some details', ], }, + { + msg => 'non-photo upload gives error', + pc => 'SW1A 1AA', + fields => { + title => 'Title', + detail => 'Detail', + photo => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ], + name => 'Bob Jones', + may_show_name => '1', + email => 'bob@example.com', + phone => '', + category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, + }, + changes => { + photo => '', + }, + errors => [ "Please upload a JPEG image only" ], + }, + { + msg => 'bad photo upload gives error', + pc => 'SW1A 1AA', + fields => { + title => 'Title', + detail => 'Detail', + photo => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ], + name => 'Bob Jones', + may_show_name => '1', + email => 'bob@example.com', + phone => '', + category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, + }, + changes => { + photo => '', + }, + errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ], + }, + { + msg => 'photo with octet-stream gets through okay', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => 'Detail', + photo => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ], + name => 'Bob Jones', + may_show_name => '1', + email => 'bob@example.com', + phone => '', + category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, + }, + changes => { + photo => '', + }, + errors => [ "Please enter a subject" ], + }, ) { subtest "check form errors where $test->{msg}" => sub { diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index ab129b4e7..67ddc10aa 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -202,7 +202,7 @@ for my $test ( (my $title = $report->title) =~ s/ /\\s+/; my $body = $email->body; - like $body, qr#report/$report_id - $title, $pc#, 'email contains expected postcode'; + like $body, qr#report/$report_id\s+-\s+$title,\s+$pc#, 'email contains expected postcode'; }; } |