From 48a56597c0bccf34417a1f4b184d623602b531cb Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 18 Jul 2012 13:13:27 +0100 Subject: Improve on 73da842, few more places where cobrand specific report URL is needed. --- t/app/model/problem.t | 119 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 37 deletions(-) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index a7415851b..818f115d1 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -348,44 +348,52 @@ for my $test ( my $mech = FixMyStreet::TestMech->new(); -FixMyStreet::App->model('DB::Contact')->find_or_create( - { - area_id => 2651, - category => 'potholes', - email => 'test@example.org', - confirmed => 1, - deleted => 0, - editor => 'test', - whenedited => \'ms_current_timestamp()', - note => '', - } -); - -FixMyStreet::App->model('DB::Contact')->find_or_create( - { - area_id => 2226, - category => 'potholes', - email => '2226@example.org', - confirmed => 1, - deleted => 0, - editor => 'test', - whenedited => \'ms_current_timestamp()', - note => '', - } -); - -FixMyStreet::App->model('DB::Contact')->find_or_create( - { - area_id => 2326, - category => 'potholes', - email => '2326@example.org', - confirmed => 1, - deleted => 0, - editor => 'test', - whenedited => \'ms_current_timestamp()', - note => '', - } +my %contact_params = ( + confirmed => 1, + deleted => 0, + editor => 'Test', + whenedited => \'ms_current_timestamp()', + note => 'Created for test', ); +# Let's make some contacts to send things to! +FixMyStreet::App->model('DB::Contact')->search( { + email => { 'like', '%example.com' }, +} )->delete; +my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2651, # Edinburgh + category => 'potholes', + email => 'test@example.org', +} ); +my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2226, # Gloucestershire + category => 'potholes', + email => '2226@example.org', +} ); +my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2326, # Cheltenham + category => 'potholes', + email => '2326@example.org', +} ); +my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2434, # Lichfield + category => 'potholes', + email => 'trees@example.com', +} ); +my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2240, # Staffordshire + category => 'potholes', + email => 'highways@example.com', +} ); +ok $contact1, "created test contact 1"; +ok $contact2, "created test contact 2"; +ok $contact3, "created test contact 3"; +ok $contact4, "created test contact 4"; +ok $contact5, "created test contact 5"; foreach my $test ( { desc => 'sends an email', @@ -427,6 +435,30 @@ foreach my $test ( { council => '2226|2649', missing => qr'problem might be the responsibility of Fife.*Council'ms, }, + { + desc => 'email to two tier council that only shows district, district', + unset_whendef => 1, + email_count => 1, + email => 'system_user@example.com', + name => 'Andrew Smith', + to => qr'Lichfield District Council', + dear => qr'Dear Lichfield District Council,', + council => '2434', + cobrand => 'lichfielddc', + url => 'lichfielddc.', + }, + { + desc => 'email to two tier council that only shows district, county', + unset_whendef => 1, + email_count => 1, + email => 'system_user@example.com', + name => 'Andrew Smith', + to => qr'Staffordshire County Council', + dear => qr'Dear Staffordshire County Council,', + council => '2240', + cobrand => 'lichfielddc', + url => '', + }, ) { subtest $test->{ desc } => sub { $mech->clear_emails_ok; @@ -445,6 +477,7 @@ foreach my $test ( { whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()', category => 'potholes', name => $test->{ name }, + cobrand => $test->{ cobrand } || 'fixmystreet', } ); FixMyStreet::App->model('DB::Problem')->send_reports(); @@ -465,6 +498,12 @@ foreach my $test ( { like $email->body, $test->{ missing }, 'missing council information correct'; } + if ( $test->{url} ) { + (my $base_url = FixMyStreet->config('BASE_URL')) =~ s{http://}{}; + my $id = $problem->id; + like $email->body, qr[$test->{url}$base_url/report/$id], 'URL present is correct'; + } + $problem->discard_changes; ok defined( $problem->whensent ), 'whensent set'; } @@ -475,4 +514,10 @@ $problem->comments->delete; $problem->delete; $user->delete; +$contact1->delete; +$contact2->delete; +$contact3->delete; +$contact4->delete; +$contact5->delete; + done_testing(); -- cgit v1.2.3 From 1d22165ba38a91daa74e52ac67dd75974abdaecb Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 20 Jul 2012 21:08:58 +0100 Subject: Add NI sender, for handling cross-council road reports. --- t/app/model/problem.t | 73 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 23 deletions(-) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 818f115d1..30963229c 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -389,75 +389,100 @@ my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( { category => 'potholes', email => 'highways@example.com', } ); +my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 14279, # Ballymoney + category => 'Street lighting', + email => 'roads.western@drdni.example.org', +} ); +my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 14279, # Ballymoney + category => 'Graffiti', + email => 'highways@example.com', +} ); ok $contact1, "created test contact 1"; ok $contact2, "created test contact 2"; ok $contact3, "created test contact 3"; ok $contact4, "created test contact 4"; ok $contact5, "created test contact 5"; +ok $contact6, "created test contact 6"; +ok $contact7, "created test contact 7"; +my %common = ( + email => 'system_user@example.com', + name => 'Andrew Smith', +); foreach my $test ( { + %common, desc => 'sends an email', unset_whendef => 1, email_count => 1, - email => 'system_user@example.com', - name => 'Andrew Smith', dear => qr'Dear City of Edinburgh Council', to => qr'City of Edinburgh Council', council => 2651, - }, - { + }, { + %common, desc => 'no email sent if no unsent problems', unset_whendef => 0, email_count => 0, - email => 'system_user@example.com', - name => 'Andrew Smith', council => 2651, - }, - { + }, { + %common, desc => 'email to two tier council', unset_whendef => 1, email_count => 1, - email => 'system_user@example.com', - name => 'Andrew Smith', to => qr'Gloucestershire County Council.*Cheltenham Borough Council', dear => qr'Dear Gloucestershire County Council and Cheltenham Borough', council => '2226,2326', multiple => 1, - }, - { + }, { + %common, desc => 'email to two tier council with one missing details', unset_whendef => 1, email_count => 1, - email => 'system_user@example.com', - name => 'Andrew Smith', to => qr'Gloucestershire County Council', dear => qr'Dear Gloucestershire County Council,', council => '2226|2649', missing => qr'problem might be the responsibility of Fife.*Council'ms, - }, - { + }, { + %common, desc => 'email to two tier council that only shows district, district', unset_whendef => 1, email_count => 1, - email => 'system_user@example.com', - name => 'Andrew Smith', to => qr'Lichfield District Council', dear => qr'Dear Lichfield District Council,', council => '2434', cobrand => 'lichfielddc', url => 'lichfielddc.', - }, - { + }, { + %common, desc => 'email to two tier council that only shows district, county', unset_whendef => 1, email_count => 1, - email => 'system_user@example.com', - name => 'Andrew Smith', to => qr'Staffordshire County Council', dear => qr'Dear Staffordshire County Council,', council => '2240', cobrand => 'lichfielddc', url => '', + }, { + %common, + desc => 'directs NI correctly, 1', + unset_whendef => 1, + email_count => 1, + dear => qr'Dear Ballymoney Borough Council', + to => qr'Ballymoney Borough Council', + council => 14279, + category => 'Graffiti', + }, { + %common, + desc => 'directs NI correctly, 2', + unset_whendef => 1, + email_count => 1, + dear => qr'Dear Roads Service \(Western\)', + to => qr'Roads Service \(Western\)', + council => 14279, + category => 'Street lighting', }, ) { subtest $test->{ desc } => sub { @@ -475,7 +500,7 @@ foreach my $test ( { state => 'confirmed', confirmed => \'ms_current_timestamp()', whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()', - category => 'potholes', + category => $test->{ category } || 'potholes', name => $test->{ name }, cobrand => $test->{ cobrand } || 'fixmystreet', } ); @@ -519,5 +544,7 @@ $contact2->delete; $contact3->delete; $contact4->delete; $contact5->delete; +$contact6->delete; +$contact7->delete; done_testing(); -- cgit v1.2.3 From 5fa680e52ffe8cfe7aa7b06fd96b8bce61095418 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 23 Jul 2012 11:13:35 +0100 Subject: Return correct failure code if no recipients. --- t/app/model/problem.t | 73 ++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 38 deletions(-) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 30963229c..8c3ea10c5 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -359,55 +359,45 @@ my %contact_params = ( FixMyStreet::App->model('DB::Contact')->search( { email => { 'like', '%example.com' }, } )->delete; -my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +my @contacts; +for my $contact ( { area_id => 2651, # Edinburgh category => 'potholes', email => 'test@example.org', -} ); -my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +}, { area_id => 2226, # Gloucestershire category => 'potholes', email => '2226@example.org', -} ); -my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +}, { area_id => 2326, # Cheltenham category => 'potholes', email => '2326@example.org', -} ); -my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +}, { area_id => 2434, # Lichfield category => 'potholes', email => 'trees@example.com', -} ); -my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +}, { area_id => 2240, # Staffordshire category => 'potholes', email => 'highways@example.com', -} ); -my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +}, { area_id => 14279, # Ballymoney category => 'Street lighting', email => 'roads.western@drdni.example.org', -} ); -my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( { - %contact_params, +}, { area_id => 14279, # Ballymoney category => 'Graffiti', email => 'highways@example.com', -} ); -ok $contact1, "created test contact 1"; -ok $contact2, "created test contact 2"; -ok $contact3, "created test contact 3"; -ok $contact4, "created test contact 4"; -ok $contact5, "created test contact 5"; -ok $contact6, "created test contact 6"; -ok $contact7, "created test contact 7"; +}, { + confirmed => 0, + area_id => 2636, # Isle of Wight + category => 'potholes', + email => '2636@example.com', +} ) { + my $new_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, %$contact } ); + ok $new_contact, "created test contact"; + push @contacts, $new_contact; +} my %common = ( email => 'system_user@example.com', @@ -441,7 +431,7 @@ foreach my $test ( { desc => 'email to two tier council with one missing details', unset_whendef => 1, email_count => 1, - to => qr'Gloucestershire County Council', + to => qr'Gloucestershire County Council" <2226@example', dear => qr'Dear Gloucestershire County Council,', council => '2226|2649', missing => qr'problem might be the responsibility of Fife.*Council'ms, @@ -460,7 +450,7 @@ foreach my $test ( { desc => 'email to two tier council that only shows district, county', unset_whendef => 1, email_count => 1, - to => qr'Staffordshire County Council', + to => qr'Staffordshire County Council" qr'Dear Staffordshire County Council,', council => '2240', cobrand => 'lichfielddc', @@ -480,9 +470,16 @@ foreach my $test ( { unset_whendef => 1, email_count => 1, dear => qr'Dear Roads Service \(Western\)', - to => qr'Roads Service \(Western\)', + to => qr'Roads Service \(Western\)" 14279, category => 'Street lighting', + }, { + %common, + desc => 'does not send to unconfirmed contact', + unset_whendef => 1, + stays_unsent => 1, + email_count => 0, + council => 2636, }, ) { subtest $test->{ desc } => sub { @@ -532,6 +529,10 @@ foreach my $test ( { $problem->discard_changes; ok defined( $problem->whensent ), 'whensent set'; } + if ( $test->{stays_unsent} ) { + $problem->discard_changes; + ok !defined( $problem->whensent ), 'whensent not set'; + } }; } @@ -539,12 +540,8 @@ $problem->comments->delete; $problem->delete; $user->delete; -$contact1->delete; -$contact2->delete; -$contact3->delete; -$contact4->delete; -$contact5->delete; -$contact6->delete; -$contact7->delete; +foreach (@contacts) { + $_->delete; +} done_testing(); -- cgit v1.2.3 From c1c43ae6714b35b85aa520b4422236f484936986 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 6 Aug 2012 10:54:04 +0100 Subject: Fix problem.t test so it skips Lichfield tests if Lichfield cobrand is not present. --- t/app/model/problem.t | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 8c3ea10c5..8aabce4f7 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -491,6 +491,10 @@ foreach my $test ( { } )->update( { whensent => \'ms_current_timestamp()' } ); + if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) { + plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand'; + } + $problem->discard_changes; $problem->update( { council => $test->{ council }, -- cgit v1.2.3