aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-07-15 18:02:45 +0100
committerDave Arter <davea@mysociety.org>2019-08-16 12:04:28 +0100
commite77546bb7fb14dd0314fbc295b3e1b8d88876157 (patch)
tree4d7c118b76a6015692e240c802f9fa7d60e5ccf0 /t/app/controller
parent48156c475483e6e603bef436abf19f79a2bc277c (diff)
Improve user-anonymous reporting.
Make it more like the staff-creation, with no confirmation email, and no messing with the user.
Diffstat (limited to 't/app/controller')
-rw-r--r--t/app/controller/report_new_anon.t92
1 files changed, 92 insertions, 0 deletions
diff --git a/t/app/controller/report_new_anon.t b/t/app/controller/report_new_anon.t
new file mode 100644
index 000000000..5a4f35f5d
--- /dev/null
+++ b/t/app/controller/report_new_anon.t
@@ -0,0 +1,92 @@
+package FixMyStreet::Cobrand::AnonAllowed;
+use parent 'FixMyStreet::Cobrand::FixMyStreet';
+sub allow_anonymous_reports { 1 }
+sub anonymous_account { { email => 'anon@example.org', name => 'Anonymous' } }
+
+package main;
+
+use FixMyStreet::TestMech;
+use FixMyStreet::App;
+
+# disable info logs for this test run
+FixMyStreet::App->log->disable('info');
+END { FixMyStreet::App->log->enable('info'); }
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $body = $mech->create_body_ok(2651, 'Edinburgh');
+my $contact1 = $mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Street lighting',
+ email => 'highways@example.com',
+);
+my $contact2 = $mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Trees',
+ email => 'trees@example.com',
+);
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'anonallowed',
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+
+subtest "check form errors when anonymous account is on" => sub {
+ $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( { with_fields => { category => "Street lighting" } }, "submit form" );
+
+ my @errors = (
+ 'Please enter a subject',
+ 'Please enter some details',
+ # No user errors
+ );
+ is_deeply [ sort @{$mech->page_errors} ], [ sort @errors ], "check errors";
+};
+
+subtest "test report creation anonymously" => sub {
+ $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 => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ name => 'Joe Bloggs',
+ may_show_name => '1',
+ category => 'Street lighting',
+ }
+ },
+ "submit good details"
+ );
+ $mech->content_contains('Thank you');
+
+ is_deeply $mech->page_errors, [], "check there were no errors";
+
+ my $report = FixMyStreet::DB->resultset("Problem")->first;
+ ok $report, "Found the report";
+
+ is $report->state, 'confirmed', "report confirmed";
+ $mech->get_ok( '/report/' . $report->id );
+
+ is $report->bodies_str, $body->id;
+ is $report->name, 'Anonymous';
+ is $report->anonymous, 0; # Doesn't change behaviour here, but uses anon account's name always
+
+ my $alert = FixMyStreet::App->model('DB::Alert')->find( {
+ user => $report->user,
+ alert_type => 'new_updates',
+ parameter => $report->id,
+ } );
+ is $alert, undef, "no alert created";
+
+ $mech->not_logged_in_ok;
+};
+
+};
+
+done_testing();