diff options
author | Struan Donald <struan@exo.org.uk> | 2012-08-22 10:57:10 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-08-22 10:57:10 +0100 |
commit | 2e0a4e8ec45579e4e5c9cf8aa123d5ab215b9703 (patch) | |
tree | c13e3c59b686e01460dc7960547f7e9c53c288bd /t/app/sendreport/email.t | |
parent | b99c5ff97b29a27eeba52ed24385ac30388e875c (diff) | |
parent | 88a7d38dffa3dabdf0f85573b254cea9c8ab232b (diff) |
Merge remote-tracking branch 'origin/master' into fmb-read-only
Conflicts:
.gitignore
bin/make_css
conf/general.yml-example
perllib/FixMyStreet/App/Controller/Council.pm
perllib/FixMyStreet/App/Controller/Report/New.pm
perllib/FixMyStreet/Cobrand/Default.pm
templates/web/default/around/around_index.html
templates/web/default/index.html
templates/web/emptyhomes/index.html
templates/web/fixmystreet/around/around_index.html
templates/web/fixmystreet/index.html
web/fixmystreet_app_cgi.cgi
web/fixmystreet_app_fastcgi.cgi
Diffstat (limited to 't/app/sendreport/email.t')
-rw-r--r-- | t/app/sendreport/email.t | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t new file mode 100644 index 000000000..f0e1f153a --- /dev/null +++ b/t/app/sendreport/email.t @@ -0,0 +1,77 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; + +use FixMyStreet; +use FixMyStreet::App; +use FixMyStreet::DB::Result::Contact; +use FixMyStreet::SendReport::Email; +use FixMyStreet::TestMech; +use mySociety::Locale; + +my $e = FixMyStreet::SendReport::Email->new(); + +my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( + email => 'council@example.com', + area_id => 1000, + category => 'category', + confirmed => 1, + deleted => 0, + editor => 'test suite', + whenedited => DateTime->now, + note => '', +); + +my $row = FixMyStreet::App->model('DB::Problem')->new( { + council => '1000', + category => 'category', +} ); + +ok $e; + +foreach my $test ( { + desc => 'no councils added means no receipients', + count => 0, + add_council => 0, + }, + { + desc => 'adding a council results in receipients', + count => 1, + add_council => 1, + }, + { + desc => 'unconfirmed contact results in no receipients', + count => undef, + add_council => 1, + unconfirmed => 1, + expected_note => 'Council 1000 deleted', + }, + { + desc => 'unconfirmed contact note uses note from contact table', + count => undef, + add_council => 1, + unconfirmed => 1, + note => 'received bounced so unconfirmed', + expected_note => 'received bounced so unconfirmed', + }, +) { + subtest $test->{desc} => sub { + my $e = FixMyStreet::SendReport::Email->new; + $contact->update( { confirmed => 0 } ) if $test->{unconfirmed}; + $contact->update( { note => $test->{note} } ) if $test->{note}; + $e->add_council( 1000, { name => 'test council' } ) if $test->{add_council}; + is $e->build_recipient_list( $row, {} ), $test->{count}, 'correct recipient list count'; + + if ( $test->{unconfirmed} ) { + is_deeply $e->unconfirmed_counts, { 'council@example.com' => { 'category' => 1 } }, 'correct unconfirmed_counts count'; + is_deeply $e->unconfirmed_notes, { 'council@example.com' => { 'category' => $test->{expected_note} } }, 'correct note used'; + } + }; +} + +$contact->delete; + +done_testing(); |