aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model
diff options
context:
space:
mode:
Diffstat (limited to 't/app/model')
-rw-r--r--t/app/model/alert_type.t69
-rw-r--r--t/app/model/problem.t177
2 files changed, 142 insertions, 104 deletions
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index c23252de6..7df4c44c0 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -155,59 +155,24 @@ my $council_alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
}
);
-for my $test (
- {
- postcode => 'SW1A 1AA',
- expected_postcode => 'SW1A 1AA',
- },
- {
- postcode => 'sw1a 1AA',
- expected_postcode => 'SW1A 1AA',
- },
- {
- postcode => 'SW1A 1aa',
- expected_postcode => 'SW1A 1AA',
- },
- {
- postcode => 'SW1A1AA',
- expected_postcode => 'SW1A 1AA',
- },
- {
- postcode => 'Buckingham Gate',
- expected_postcode => 'Buckingham\s+Gate',
- },
- {
- postcode => 'Buckingham gate',
- expected_postcode => 'Buckingham\s+gate',
- },
-) {
- subtest "correct text for postcode $test->{postcode}" => sub {
- $mech->clear_emails_ok;
-
- my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
- {
- alert_id => $council_alert->id,
- parameter => $report->id,
- }
- )->delete;
-
- $report->postcode( $test->{postcode} );
- $report->update;
-
- FixMyStreet::App->model('DB::AlertType')->email_alerts();
+subtest "correct text for title after URL" => sub {
+ $mech->clear_emails_ok;
- $mech->email_count_is( 1 );
- my $email = $mech->get_email;
- my $pc = $test->{expected_postcode};
- (my $title = $report->title) =~ s/ /\\s+/;
- my $body = $email->body;
+ my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
+ {
+ alert_id => $council_alert->id,
+ parameter => $report->id,
+ }
+ )->delete;
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
- like $body, qr#report/$report_id\s+-\s+$title,\s+$pc#, 'email contains expected postcode';
- };
-}
+ $mech->email_count_is( 1 );
+ my $email = $mech->get_email;
+ (my $title = $report->title) =~ s/ /\\s+/;
+ my $body = $email->body;
-$report->postcode( 'SW1A 1AA' );
-$report->update;
+ like $body, qr#report/$report_id\s+-\s+$title#, 'email contains expected title';
+};
$report->geocode(
{
@@ -448,7 +413,7 @@ subtest "check alerts from cobrand send main site url for alerts for different c
my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id;
my $expected3 = mySociety::Config::get('BASE_URL') . '/report/' . $report_outside_district->id;
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('lichfielddc')->new();
- my $expected2 = $cobrand->base_url_for_emails . '/report/' . $report_to_council->id;
+ my $expected2 = $cobrand->base_url . '/report/' . $report_to_council->id;
like $body, qr#$expected1#, 'non cobrand area report point to fixmystreet.com';
like $body, qr#$expected2#, 'cobrand area report point to cobrand url';
@@ -485,7 +450,7 @@ subtest "check local alerts from cobrand send main site url for alerts for diffe
my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id;
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('lichfielddc')->new();
- my $expected2 = $cobrand->base_url_for_emails . '/report/' . $report_to_council->id;
+ my $expected2 = $cobrand->base_url . '/report/' . $report_to_council->id;
like $body, qr#$expected1#, 'non cobrand area report point to fixmystreet.com';
like $body, qr#$expected2#, 'cobrand area report point to cobrand url';
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index a7415851b..8aabce4f7 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -348,84 +348,138 @@ 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 => '',
- }
+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 @contacts;
+for my $contact ( {
+ area_id => 2651, # Edinburgh
+ category => 'potholes',
+ email => 'test@example.org',
+}, {
+ area_id => 2226, # Gloucestershire
+ category => 'potholes',
+ email => '2226@example.org',
+}, {
+ area_id => 2326, # Cheltenham
+ category => 'potholes',
+ email => '2326@example.org',
+}, {
+ area_id => 2434, # Lichfield
+ category => 'potholes',
+ email => 'trees@example.com',
+}, {
+ area_id => 2240, # Staffordshire
+ category => 'potholes',
+ email => 'highways@example.com',
+}, {
+ area_id => 14279, # Ballymoney
+ category => 'Street lighting',
+ email => 'roads.western@drdni.example.org',
+}, {
+ area_id => 14279, # Ballymoney
+ category => 'Graffiti',
+ email => 'highways@example.com',
+}, {
+ 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;
+}
-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 %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',
+ 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,
+ }, {
+ %common,
+ desc => 'email to two tier council that only shows district, district',
+ unset_whendef => 1,
+ email_count => 1,
+ 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,
+ to => qr'Staffordshire County Council" <highways@example',
+ 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\)" <roads',
+ council => 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 {
@@ -437,14 +491,19 @@ 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 },
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',
} );
FixMyStreet::App->model('DB::Problem')->send_reports();
@@ -465,9 +524,19 @@ 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';
}
+ if ( $test->{stays_unsent} ) {
+ $problem->discard_changes;
+ ok !defined( $problem->whensent ), 'whensent not set';
+ }
};
}
@@ -475,4 +544,8 @@ $problem->comments->delete;
$problem->delete;
$user->delete;
+foreach (@contacts) {
+ $_->delete;
+}
+
done_testing();