diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/report_as_other.t | 26 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 53 |
2 files changed, 70 insertions, 9 deletions
diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index a07a903ff..377de27bd 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -40,7 +40,6 @@ subtest "Body user, has permission to add report as council" => sub { is $report->anonymous, 0, 'report not anonymous'; }; -my @users; subtest "Body user, has permission to add report as another user with email" => sub { my $report = add_report( 'contribute_as_another_user', @@ -56,7 +55,6 @@ subtest "Body user, has permission to add report as another user with email" => is $report->user->email, 'another@example.net', 'user email correct'; isnt $report->user->id, $user->id, 'user does not match'; like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/; - push @users, $report->user; }; subtest "Body user, has permission to add report as another user with mobile phone number" => sub { @@ -77,7 +75,6 @@ subtest "Body user, has permission to add report as another user with mobile pho is $report->user->email_verified, 0, 'user email not verified'; isnt $report->user->id, $user->id, 'user does not match'; $mech->email_count_is(0); - push @users, $report->user; }; subtest "Body user, has permission to add report as another user with landline number" => sub { @@ -98,7 +95,23 @@ subtest "Body user, has permission to add report as another user with landline n is $report->user->email_verified, 0, 'user email not verified'; isnt $report->user->id, $user->id, 'user does not match'; $mech->email_count_is(0); - push @users, $report->user; +}; + +subtest "Body user, has permission to add report as another user with only name" => sub { + my $report = add_report( + 'contribute_as_another_user', + form_as => 'another_user', + title => "Test Report", + detail => 'Test report details.', + category => 'Potholes', + name => 'Another User', + username => '', + may_show_name => undef, + ); + is $report->name, 'Another User', 'report name is name given'; + is $report->user->name, 'Body User', 'user name unchanged'; + is $report->user->id, $user->id, 'user matches'; + is $report->anonymous, 1, 'report anonymous'; }; subtest "Body user, has permission to add report as another (existing) user with email" => sub { @@ -120,7 +133,6 @@ subtest "Body user, has permission to add report as another (existing) user with is $report->user->email, $existing->email, 'user email correct'; isnt $report->user->id, $user->id, 'user does not match'; like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/; - push @users, $report->user; my $send_confirmation_mail_override = Sub::Override->new( "FixMyStreet::Cobrand::Default::report_sent_confirmation_email", @@ -148,7 +160,6 @@ subtest "Body user, has permission to add report as another (existing) user with is $report->user->phone, '+447906333333', 'user phone correct'; isnt $report->user->id, $user->id, 'user does not match'; $mech->email_count_is(0); - push @users, $report->user; }; subtest "Superuser, can add report as anonymous user" => sub { @@ -231,7 +242,6 @@ subtest "Body user, has permission to add update as another user with email" => is $update->user->email, 'another2@example.net', 'user email correct'; isnt $update->user->id, $user->id, 'user does not match'; like $mech->get_text_body_from_email, qr/Your update has been logged/; - push @users, $update->user; }; subtest "Body user, has permission to add update as another user with mobile phone" => sub { @@ -247,7 +257,6 @@ subtest "Body user, has permission to add update as another user with mobile pho is $update->user->phone, '+447906444444', 'user phone correct'; isnt $update->user->id, $user->id, 'user does not match'; $mech->email_count_is(0); - push @users, $update->user; }; subtest "Body user, has permission to add update as another user with landline phone" => sub { @@ -263,7 +272,6 @@ subtest "Body user, has permission to add update as another user with landline p is $update->user->phone, '+441685555555', 'user phone correct'; isnt $update->user->id, $user->id, 'user does not match'; $mech->email_count_is(0); - push @users, $update->user; }; subtest "Body user, has permission to add update as another (existing) user with email" => sub { diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index 264198052..3488b96ce 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -67,6 +67,23 @@ $mech->create_contact_ok( category => 'Something Other', email => '104', ); +$mech->create_contact_ok( + body_id => $body2->id, # Edinburgh + category => 'Abandoned vehicle', + email => '105', + extra => { _fields => [ + { description => 'This is a warning message.', code => 'notice', required => 'false', variable => 'false', order => '0' }, + { description => 'USRN', code => 'usrn', required => 'false', automated => 'hidden_field' }, + ] }, +); +$mech->create_contact_ok( + body_id => $body2->id, # Edinburgh + category => 'Traffic signals', + email => '106', + extra => { _fields => [ + { description => 'This is a warning message for traffic signals.', code => 'notice', required => 'false', variable => 'false', order => '0' }, + ] }, +); my $staff_user = $mech->create_user_ok('staff@example.org', name => 'staff', from_body => $body->id); @@ -283,6 +300,42 @@ subtest "Category extras omits description label when all fields are hidden" => }; }; +subtest "Category extras omits preamble when all fields are notices" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + for ( + { url => '/report/new/ajax?' }, + { url => '/report/new/category_extras?category=Traffic+signals' }, + ) { + my $json = $mech->get_ok_json($_->{url} . '&latitude=55.952055&longitude=-3.189579'); + my $category_extra = $json->{by_category} ? $json->{by_category}{'Traffic signals'}{category_extra} : $json->{category_extra}; + contains_string($category_extra, "This is a warning message for traffic signals."); + lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text"); + } + }; +}; + +subtest "Category extras omits preamble when fields are only notices and hidden" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + for ( + { url => '/report/new/ajax?' }, + { url => '/report/new/category_extras?category=Abandoned+vehicle' }, + ) { + my $json = $mech->get_ok_json($_->{url} . '&latitude=55.952055&longitude=-3.189579'); + my $category_extra = $json->{by_category} ? $json->{by_category}{'Abandoned vehicle'}{category_extra} : $json->{category_extra}; + contains_string($category_extra, "This is a warning message."); + contains_string($category_extra, "usrn"); + lacks_string($category_extra, "USRN", "Lacks 'USRN' label"); + lacks_string($category_extra, "resolve your problem quicker, by providing some extra detail", "Lacks description text"); + } + }; +}; + subtest "Category extras includes description label for user" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], |