From 3e9277ed0e81b5d09656bff0aa5dacd87da1e55e Mon Sep 17 00:00:00 2001 From: Martin Wright Date: Wed, 9 Oct 2019 14:02:12 +0100 Subject: [Hackney] Initial cobrand design & privacy policy amendment Co-Authored-By: Struan Donald For https://github.com/mysociety/fixmystreet-commercial/issues/1808 --- t/cobrand/hackney.t | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 t/cobrand/hackney.t (limited to 't/cobrand/hackney.t') diff --git a/t/cobrand/hackney.t b/t/cobrand/hackney.t new file mode 100644 index 000000000..519b1b3b8 --- /dev/null +++ b/t/cobrand/hackney.t @@ -0,0 +1,223 @@ +use utf8; +use CGI::Simple; +use DateTime; +use Test::MockModule; +use FixMyStreet::TestMech; +use Open311; +use Open311::GetServiceRequests; +use Open311::GetServiceRequestUpdates; +use Open311::PostServiceRequestUpdates; +use FixMyStreet::Script::Alerts; +use FixMyStreet::Script::Reports; + +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' ); + +my $params = { + send_method => 'Open311', + send_comments => 1, + api_key => 'KEY', + endpoint => 'endpoint', + jurisdiction => 'home', + can_be_devolved => 1, +}; + +my $hackney = $mech->create_body_ok(2508, 'Hackney Council', $params); +my $contact = $mech->create_contact_ok( + body_id => $hackney->id, + category => 'Potholes', + email => 'pothole@example.org', +); +$contact->set_extra_fields( ( { + code => 'urgent', + datatype => 'string', + description => 'question', + variable => 'true', + required => 'false', + order => 1, + datatype_description => 'datatype', +} ) ); +$contact->update; + +my $user = $mech->create_user_ok('user@example.org', name => 'Test User'); +my $hackney_user = $mech->create_user_ok('hackney_user@example.org', name => 'Hackney User', from_body => $hackney); +$hackney_user->user_body_permissions->create({ + body => $hackney, + permission_type => 'moderate', +}); + +my $contact2 = $mech->create_contact_ok( + body_id => $hackney->id, + category => 'Roads', + email => 'roads@example.org', + send_method => 'Triage', +); + +my $admin_user = $mech->create_user_ok('admin-user@example.org', name => 'Admin User', from_body => $hackney); + +$admin_user->user_body_permissions->create({ + body => $hackney, + permission_type => 'triage' +}); + +my @reports = $mech->create_problems_for_body(1, $hackney->id, 'A Hackney report', { + confirmed => '2019-10-25 09:00', + lastupdate => '2019-10-25 09:00', + latitude => 51.552267, + longitude => -0.063316, + user => $user, + external_id => 101202303 +}); + +subtest "check clicking all reports link" => sub { + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => ['hackney'], + }, sub { + $mech->get_ok('/'); + $mech->follow_link_ok({ text => 'All reports' }); + }; + + $mech->content_contains("A Hackney report", "Hackney report there"); + $mech->content_contains("Hackney Council", "is still on cobrand"); +}; + +subtest "check moderation label uses correct name" => sub { + my $REPORT_URL = '/report/' . $reports[0]->id; + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => ['hackney'], + }, sub { + $mech->log_out_ok; + $mech->log_in_ok( $hackney_user->email ); + $mech->get_ok($REPORT_URL); + $mech->content_lacks('show-moderation'); + $mech->follow_link_ok({ text_regex => qr/^Moderate$/ }); + $mech->content_contains('show-moderation'); + $mech->submit_form_ok({ with_fields => { + problem_title => 'Good good', + problem_detail => 'Good good improved', + }}); + $mech->base_like( qr{\Q$REPORT_URL\E} ); + $mech->content_like(qr/Moderated by Hackney Council/); + }; +}; + +$_->delete for @reports; + +my $system_user = $mech->create_user_ok('system_user@example.org'); + +my ($p) = $mech->create_problems_for_body(1, $hackney->id, '', { cobrand => 'hackney' }); +my $alert = FixMyStreet::DB->resultset('Alert')->create( { + parameter => $p->id, + alert_type => 'new_updates', + user => $user, + cobrand => 'hackney', +} )->confirm; + +subtest "sends branded alert emails" => sub { + $mech->create_comment_for_problem($p, $system_user, 'Other User', 'This is some update text', 'f', 'confirmed', undef); + $mech->clear_emails_ok; + + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => ['hackney','fixmystreet'], + }, sub { + FixMyStreet::Script::Alerts::send(); + }; + + $mech->email_count_is(1); + my $email = $mech->get_email; + ok $email, "got an email"; + like $mech->get_text_body_from_email($email), qr/Hackney Council/, "emails are branded"; +}; + +$p->comments->delete; +$p->delete; + +subtest "sends branded confirmation emails" => sub { + $mech->log_out_ok; + $mech->clear_emails_ok; + $mech->get_ok('/around'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'hackney' ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'E8 1DY', } }, + "submit location" ); + + # click through to the report page + $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.', + photo1 => '', + name => 'Joe Bloggs', + username => 'test-1@example.com', + category => 'Roads', + } + }, + "submit good details" + ); + + $mech->email_count_is(1); + my $email = $mech->get_email; + ok $email, "got an email"; + like $mech->get_text_body_from_email($email), qr/Hackney Council/, "emails are branded"; + + my $url = $mech->get_link_from_email($email); + $mech->get_ok($url); + $mech->clear_emails_ok; + }; +}; + +#subtest "sends branded report sent emails" => sub { + #$mech->clear_emails_ok; + #FixMyStreet::override_config { + #STAGING_FLAGS => { send_reports => 1 }, + #MAPIT_URL => 'http://mapit.uk/', + #ALLOWED_COBRANDS => ['hackney','fixmystreet'], + #}, sub { + #FixMyStreet::Script::Reports::send(); + #}; + #$mech->email_count_is(1); + #my $email = $mech->get_email; + #ok $email, "got an email"; + #like $mech->get_text_body_from_email($email), qr/Hackney Council/, "emails are branded"; +#}; + +subtest "check category extra uses correct name" => sub { + my @extras = ( { + code => 'test', + datatype => 'string', + description => 'question', + variable => 'true', + required => 'false', + order => 1, + datatype_description => 'datatype', + } ); + $contact2->set_extra_fields( @extras ); + $contact2->update; + + my $extra_details; + + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => ['hackney','fixmystreet'], + }, sub { + $extra_details = $mech->get_ok_json('/report/new/category_extras?category=Roads&latitude=51.552267&longitude=-0.063316'); + }; + + like $extra_details->{category_extra}, qr/Hackney Council/, 'correct name in category extras'; +}; + + +done_testing(); -- cgit v1.2.3 From 53b9f82cbb7fe81484b8bbf434f0b0acd925b454 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 11 May 2020 12:43:02 +0100 Subject: [Hackney] Special destination handling. --- t/cobrand/hackney.t | 71 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 9 deletions(-) (limited to 't/cobrand/hackney.t') diff --git a/t/cobrand/hackney.t b/t/cobrand/hackney.t index 519b1b3b8..82fefc15b 100644 --- a/t/cobrand/hackney.t +++ b/t/cobrand/hackney.t @@ -53,16 +53,11 @@ my $contact2 = $mech->create_contact_ok( body_id => $hackney->id, category => 'Roads', email => 'roads@example.org', - send_method => 'Triage', + send_method => 'Email', ); my $admin_user = $mech->create_user_ok('admin-user@example.org', name => 'Admin User', from_body => $hackney); -$admin_user->user_body_permissions->create({ - body => $hackney, - permission_type => 'triage' -}); - my @reports = $mech->create_problems_for_body(1, $hackney->id, 'A Hackney report', { confirmed => '2019-10-25 09:00', lastupdate => '2019-10-25 09:00', @@ -129,7 +124,6 @@ subtest "sends branded alert emails" => sub { FixMyStreet::Script::Alerts::send(); }; - $mech->email_count_is(1); my $email = $mech->get_email; ok $email, "got an email"; like $mech->get_text_body_from_email($email), qr/Hackney Council/, "emails are branded"; @@ -168,7 +162,6 @@ subtest "sends branded confirmation emails" => sub { "submit good details" ); - $mech->email_count_is(1); my $email = $mech->get_email; ok $email, "got an email"; like $mech->get_text_body_from_email($email), qr/Hackney Council/, "emails are branded"; @@ -179,6 +172,67 @@ subtest "sends branded confirmation emails" => sub { }; }; +FixMyStreet::override_config { + STAGING_FLAGS => { send_reports => 1 }, + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => ['hackney', 'fixmystreet'], +}, sub { + subtest "special send handling" => sub { + my $cbr = Test::MockModule->new('FixMyStreet::Cobrand::Hackney'); + my $p = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first; + $contact2->update({ email => 'park:parks@example;estate:estates@example;other:OTHER', send_method => '' }); + + subtest 'in a park' => sub { + $cbr->mock('_fetch_features', sub { + my ($self, $cfg, $x, $y) = @_; + return [{ + properties => { park_id => 'park' }, + geometry => { + type => 'Polygon', + coordinates => [ [ [ $x-1, $y-1 ], [ $x+1, $y+1 ] ] ], + } + }] if $cfg->{typename} eq 'greenspaces:hackney_park'; + }); + FixMyStreet::Script::Reports::send(); + my $email = $mech->get_email; + is $email->header('To'), '"Hackney Council" '; + $mech->clear_emails_ok; + $p->discard_changes; + $p->update({ whensent => undef }); + }; + + subtest 'in an estate' => sub { + $cbr->mock('_fetch_features', sub { + my ($self, $cfg, $x, $y) = @_; + return [{ + properties => { id => 'estate' }, + geometry => { + type => 'Polygon', + coordinates => [ [ [ $x-1, $y-1 ], [ $x+1, $y+1 ] ] ], + } + }] if $cfg->{typename} eq 'housing:lbh_estate'; + }); + FixMyStreet::Script::Reports::send(); + my $email = $mech->get_email; + is $email->header('To'), '"Hackney Council" '; + $mech->clear_emails_ok; + $p->discard_changes; + $p->update({ whensent => undef }); + }; + + subtest 'elsewhere' => sub { + $cbr->mock('_fetch_features', sub { + my ($self, $cfg, $x, $y) = @_; + return []; # Not in park or estate + }); + 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'), 'OTHER'; + }; + }; +}; + #subtest "sends branded report sent emails" => sub { #$mech->clear_emails_ok; #FixMyStreet::override_config { @@ -188,7 +242,6 @@ subtest "sends branded confirmation emails" => sub { #}, sub { #FixMyStreet::Script::Reports::send(); #}; - #$mech->email_count_is(1); #my $email = $mech->get_email; #ok $email, "got an email"; #like $mech->get_text_body_from_email($email), qr/Hackney Council/, "emails are branded"; -- cgit v1.2.3 From f4b5a6263b1529003a42787b404952ab28aefeba Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Thu, 2 Jul 2020 17:13:50 +0100 Subject: [Hackney] Use cobrand feature config for email envelope domain --- t/cobrand/hackney.t | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/cobrand/hackney.t') diff --git a/t/cobrand/hackney.t b/t/cobrand/hackney.t index 82fefc15b..b5a629e33 100644 --- a/t/cobrand/hackney.t +++ b/t/cobrand/hackney.t @@ -85,6 +85,14 @@ subtest "check moderation label uses correct name" => sub { FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => ['hackney'], + COBRAND_FEATURES => { + do_not_reply_email => { + hackney => 'fms-hackney-DO-NOT-REPLY@hackney-example.com', + }, + verp_email_domain => { + hackney => 'hackney-example.com', + }, + }, }, sub { $mech->log_out_ok; $mech->log_in_ok( $hackney_user->email ); @@ -139,6 +147,14 @@ subtest "sends branded confirmation emails" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'hackney' ], MAPIT_URL => 'http://mapit.uk/', + COBRAND_FEATURES => { + do_not_reply_email => { + hackney => 'fms-hackney-DO-NOT-REPLY@hackney-example.com', + }, + verp_email_domain => { + hackney => 'hackney-example.com', + }, + }, }, sub { $mech->submit_form_ok( { with_fields => { pc => 'E8 1DY', } }, "submit location" ); -- cgit v1.2.3 From 88c607fa378951491c7ec0f3384bc8f27fbca467 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 15 Jul 2020 16:02:21 +0100 Subject: Fix lookups in templates of categories with &s. A hash lookup in a template is escaping the key used, meaning the lookup is failing anywhere we are using a category containing an ampersand as a key. A continuation of the changes made in 527d763b. --- t/cobrand/hackney.t | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 't/cobrand/hackney.t') diff --git a/t/cobrand/hackney.t b/t/cobrand/hackney.t index b5a629e33..374bf2ea9 100644 --- a/t/cobrand/hackney.t +++ b/t/cobrand/hackney.t @@ -28,7 +28,7 @@ my $params = { my $hackney = $mech->create_body_ok(2508, 'Hackney Council', $params); my $contact = $mech->create_contact_ok( body_id => $hackney->id, - category => 'Potholes', + category => 'Potholes & stuff', email => 'pothole@example.org', ); $contact->set_extra_fields( ( { @@ -143,7 +143,7 @@ $p->delete; subtest "sends branded confirmation emails" => sub { $mech->log_out_ok; $mech->clear_emails_ok; - $mech->get_ok('/around'); + $mech->get_ok('/?filter_category=Potholes+%26+stuff'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'hackney' ], MAPIT_URL => 'http://mapit.uk/', @@ -159,6 +159,9 @@ subtest "sends branded confirmation emails" => sub { $mech->submit_form_ok( { with_fields => { pc => 'E8 1DY', } }, "submit location" ); + # While we're here, check the category with an ampersand (regression test) + $mech->content_contains('