diff options
Diffstat (limited to 't')
-rw-r--r-- | t/cobrand/get_body_sender.t | 18 | ||||
-rw-r--r-- | t/cobrand/hackney.t | 71 |
2 files changed, 66 insertions, 23 deletions
diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t index 06ffb42a5..a1e8f2320 100644 --- a/t/cobrand/get_body_sender.t +++ b/t/cobrand/get_body_sender.t @@ -6,31 +6,21 @@ use_ok 'FixMyStreet::Cobrand'; my $c = FixMyStreet::Cobrand::FixMyStreet->new(); -FixMyStreet::DB->resultset('BodyArea')->search( { body_id => 1000 } )->delete; -FixMyStreet::DB->resultset('Body')->search( { name => 'Body of a Thousand' } )->delete; - my $body = FixMyStreet::DB->resultset('Body')->find_or_create({ id => 1000, name => 'Body of a Thousand', }); -my $body_area = $body->body_areas->find_or_create({ area_id => 1000 }); + +my $problem = FixMyStreet::DB->resultset('Problem')->new({}); FixMyStreet::override_config { MAPIT_TYPES => [ 'LBO' ], MAPIT_URL => 'http://mapit.uk/', # Not actually used as no special casing at present }, sub { - is_deeply $c->get_body_sender( $body ), { method => 'Email', contact => undef }, 'defaults to email'; - $body_area->update({ area_id => 2481 }); # Croydon LBO - is_deeply $c->get_body_sender( $body ), { method => 'Email', contact => undef }, 'still email if London borough'; + is_deeply $c->get_body_sender( $body, $problem ), { method => 'Email', contact => undef }, 'defaults to email'; }; $body->send_method( 'TestMethod' ); -is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to London'; - -$body_area->update({ area_id => 1000 }); # Nothing -is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to Email'; - -$body_area->delete; -$body->delete; +is $c->get_body_sender( $body, $problem )->{ method }, 'TestMethod', 'uses send_method in preference to Email'; done_testing(); 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" <parks@example>'; + $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" <estates@example>'; + $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"; |