aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/sendreport
diff options
context:
space:
mode:
Diffstat (limited to 't/app/sendreport')
-rw-r--r--t/app/sendreport/email.t8
-rw-r--r--t/app/sendreport/email/highways.t13
-rw-r--r--t/app/sendreport/email/tfl.t32
-rw-r--r--t/app/sendreport/inspection_required.t100
-rw-r--r--t/app/sendreport/open311.t74
5 files changed, 69 insertions, 158 deletions
diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t
index 3e6db4f67..cfd70a097 100644
--- a/t/app/sendreport/email.t
+++ b/t/app/sendreport/email.t
@@ -63,14 +63,14 @@ foreach my $test ( {
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';
+ is_deeply $e->unconfirmed_data, { 'council@example.com' => {
+ 'category' => { 'count' => 1, 'note' => $test->{expected_note} }
+ } }, 'correct unconfirmed_data';
}
};
}
-$body->body_areas->delete;
-$body->body_areas->create({ area_id => 2429 });
+$body->update({ name => 'Somerset West and Taunton Council' });
subtest 'Test special behaviour' => sub {
my $e = FixMyStreet::SendReport::Email->new;
diff --git a/t/app/sendreport/email/highways.t b/t/app/sendreport/email/highways.t
index f53062336..b9a71f23f 100644
--- a/t/app/sendreport/email/highways.t
+++ b/t/app/sendreport/email/highways.t
@@ -11,6 +11,7 @@ $mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id
$mech->create_contact_ok(email => 'highways@example.com', body_id => $highways->id, category => 'Pothole');
my $row = FixMyStreet::DB->resultset('Problem')->new( {
+ id => 123,
bodies_str => '1000',
category => 'Pothole',
cobrand => '',
@@ -28,5 +29,17 @@ $e->add_body($highways);
is $e->build_recipient_list($row), 1, 'correct recipient list count';
is_deeply $e->to, [ [ 'highways@example.com', 'Highways England' ] ], 'correct To line';
+$row->set_extra_fields( { name => 'area_name', value => 'Area 6' } );
+is $e->build_recipient_list($row), 1, 'correct recipient list count';
+is_deeply $e->to, [ [ 'highways@example.com', 'Highways England' ] ], 'correct To line';
+
+FixMyStreet::override_config {
+ COBRAND_FEATURES => { open311_email => { highwaysengland => { area_seven => 'a7@example.com' } } }
+}, sub {
+ $row->set_extra_fields( { name => 'area_name', value => 'Area 7' } );
+ is $e->build_recipient_list($row), 1, 'correct recipient list count';
+ is_deeply $e->to, [ [ 'a7@example.com', 'Highways England' ] ], 'correct To line';
+};
+
done_testing();
diff --git a/t/app/sendreport/email/tfl.t b/t/app/sendreport/email/tfl.t
deleted file mode 100644
index 0322de551..000000000
--- a/t/app/sendreport/email/tfl.t
+++ /dev/null
@@ -1,32 +0,0 @@
-use FixMyStreet::SendReport::Email::TfL;
-use FixMyStreet::TestMech;
-
-my $mech = FixMyStreet::TestMech->new;
-
-my $bromley = $mech->create_body_ok(2482, 'Bromley Council');
-my $tfl = $mech->create_body_ok(2482, 'TfL');
-
-$mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id, category => 'Graffiti');
-$mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id, category => 'Faulty street light');
-$mech->create_contact_ok(email => 'tfl@example.com', body_id => $tfl->id, category => 'Traffic lights');
-
-my $row = FixMyStreet::DB->resultset('Problem')->new( {
- bodies_str => '1000',
- category => 'Faulty street light',
- cobrand => '',
-} );
-
-my $e = FixMyStreet::SendReport::Email::TfL->new;
-is $e->build_recipient_list($row), undef, 'no recipients if no body';
-
-$e = FixMyStreet::SendReport::Email::TfL->new;
-$e->add_body($bromley);
-is $e->build_recipient_list($row), undef, 'no recipients if category missing';
-
-$e = FixMyStreet::SendReport::Email::TfL->new;
-$e->add_body($tfl);
-is $e->build_recipient_list($row), 1, 'correct recipient list count';
-is_deeply $e->to, [ [ 'tfl@example.com', 'TfL' ] ], 'correct To line';
-
-done_testing();
-
diff --git a/t/app/sendreport/inspection_required.t b/t/app/sendreport/inspection_required.t
deleted file mode 100644
index 64d6f70ee..000000000
--- a/t/app/sendreport/inspection_required.t
+++ /dev/null
@@ -1,100 +0,0 @@
-use FixMyStreet;
-use FixMyStreet::DB;
-use FixMyStreet::TestMech;
-use FixMyStreet::Script::Reports;
-
-ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
-
-my $user = $mech->create_user_ok( 'user@example.com' );
-
-my $body = $mech->create_body_ok( 2237, 'Oxfordshire County Council');
-# $body->update({ send_method => 'Email' });
-
-my $contact = $mech->create_contact_ok(
- body_id => $body->id,
- category => 'Pothole',
- email => 'test@example.org',
-);
-$contact->set_extra_metadata(inspection_required => 1);
-$contact->update;
-
-my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', {
- cobrand => 'oxfordshire',
- category => $contact->category,
- user => $user,
-});
-my $report = $reports[0];
-
-subtest "Report isn't sent if uninspected" => sub {
- $mech->clear_emails_ok;
-
- FixMyStreet::Script::Reports::send();
-
- $mech->email_count_is( 0 );
- is $report->whensent, undef, "Report hasn't been sent";
-};
-
-subtest 'Report is sent when inspected' => sub {
- $mech->clear_emails_ok;
- $report->set_extra_metadata(inspected => 1);
- $report->update;
-
- FixMyStreet::Script::Reports::send();
-
- $report->discard_changes;
- $mech->email_count_is( 1 );
- ok $report->whensent, 'Report marked as sent';
-};
-
-subtest 'Uninspected report is sent when made by trusted user' => sub {
- $mech->clear_emails_ok;
- $report->unset_extra_metadata('inspected');
- $report->whensent( undef );
- $report->update;
-
- $user->user_body_permissions->find_or_create({
- body => $body,
- permission_type => 'trusted',
- });
- ok $user->has_permission_to('trusted', $report->bodies_str_ids), 'User can make trusted reports';
-
- FixMyStreet::Script::Reports::send();
-
- $report->discard_changes;
- $mech->email_count_is( 1 );
- ok $report->whensent, 'Report marked as sent';
- is $report->get_extra_metadata('inspected'), undef, 'Report not marked as inspected';
-};
-
-subtest "Uninspected report isn't sent when user rep is too low" => sub {
- $mech->clear_emails_ok;
- $report->whensent( undef );
- $report->update;
-
- $user->user_body_permissions->delete;
- $user->set_extra_metadata(reputation => 15);
- $user->update;
-
- $contact->set_extra_metadata(reputation_threshold => 20);
- $contact->update;
-
- FixMyStreet::Script::Reports::send();
-
- $report->discard_changes;
- $mech->email_count_is( 0 );
- is $report->whensent, undef, "Report hasn't been sent";
-};
-
-subtest 'Uninspected report is sent when user rep is high enough' => sub {
- $user->set_extra_metadata(reputation => 21);
- $user->update;
-
- FixMyStreet::Script::Reports::send();
-
- $report->discard_changes;
- $mech->email_count_is( 1 );
- ok $report->whensent, 'Report marked as sent';
- is $report->get_extra_metadata('inspected'), undef, 'Report not marked as inspected';
-};
-
-done_testing();
diff --git a/t/app/sendreport/open311.t b/t/app/sendreport/open311.t
index 54aaa39d0..4e3c179c2 100644
--- a/t/app/sendreport/open311.t
+++ b/t/app/sendreport/open311.t
@@ -1,5 +1,6 @@
use FixMyStreet::Test;
+use Test::MockModule;
use Test::Deep;
use Open311;
@@ -8,6 +9,13 @@ use FixMyStreet::DB;
use Data::Dumper;
+my $ukc = Test::MockModule->new('FixMyStreet::Cobrand::UKCouncils');
+$ukc->mock('lookup_site_code', sub {
+ my ($self, $row, $buffer) = @_;
+ is $row->latitude, 100, 'Correct latitude';
+ return "Road ID";
+});
+
package main;
sub test_overrides; # defined below
@@ -32,7 +40,7 @@ my %standard_open311_parameters = (
test_overrides oxfordshire =>
{
body_name => 'Oxfordshire',
- body_id => 2237,
+ area_id => 2237,
row_data => {
postcode => 'OX1 1AA',
},
@@ -44,7 +52,6 @@ test_overrides oxfordshire =>
},
superhashof({
handler => isa('FixMyStreet::Cobrand::Oxfordshire'),
- discard_changes => 1,
'open311' => noclass(superhashof({
%standard_open311_parameters,
'extended_description' => 'oxfordshire',
@@ -60,7 +67,6 @@ test_overrides oxfordshire =>
my $bromley_check =
superhashof({
handler => isa('FixMyStreet::Cobrand::Bromley'),
- discard_changes => 1,
'open311' => noclass(superhashof({
%standard_open311_parameters,
'send_notpinpointed' => 1,
@@ -75,6 +81,7 @@ my $bromley_check =
{ name => 'email_alerts_requested', value => 'FALSE' },
{ name => 'requested_datetime', value => re(qr/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)/) },
{ name => 'email', value => TEST_USER_EMAIL },
+ { name => 'fms_extra_title', value => 'MR' },
{ name => 'last_name', value => 'Bloggs' },
),
});
@@ -82,7 +89,7 @@ my $bromley_check =
test_overrides bromley =>
{
body_name => 'Bromley',
- body_id => 2482,
+ area_id => 2482,
row_data => {
postcode => 'BR1 1AA',
extra => [ { name => 'last_name', value => 'Bloggs' } ],
@@ -91,14 +98,16 @@ test_overrides bromley =>
northing => 100,
easting => 100,
url => 'http://example.com/1234',
+ prow_reference => 'ABC',
},
},
- $bromley_check;
+ $bromley_check,
+ [ { name => 'last_name', value => 'Bloggs' } ];
test_overrides fixmystreet =>
{
body_name => 'Bromley',
- body_id => 2482,
+ area_id => 2482,
row_data => {
postcode => 'BR1 1AA',
# NB: we don't pass last_name here, as main cobrand doesn't know to do this!
@@ -114,7 +123,7 @@ test_overrides fixmystreet =>
test_overrides greenwich =>
{
body_name => 'Greenwich',
- body_id => 2493,
+ area_id => 2493,
},
superhashof({
handler => isa('FixMyStreet::Cobrand::Greenwich'),
@@ -129,7 +138,7 @@ test_overrides greenwich =>
test_overrides fixmystreet =>
{
body_name => 'West Berkshire',
- body_id => 2619,
+ area_id => 2619,
row_data => {
postcode => 'RG1 1AA',
},
@@ -145,20 +154,45 @@ test_overrides fixmystreet =>
})),
});
+test_overrides fixmystreet =>
+ {
+ body_name => 'Cheshire East',
+ area_id => 21069,
+ row_data => {
+ postcode => 'CW11 1HZ',
+ },
+ extra => {
+ url => 'http://example.com/1234',
+ },
+ },
+ superhashof({
+ handler => isa('FixMyStreet::Cobrand::CheshireEast'),
+ 'open311' => noclass(superhashof({
+ %standard_open311_parameters,
+ })),
+ problem_extra => bag(
+ { name => 'report_url' => value => 'http://example.com/1234' },
+ { name => 'title', value => 'Problem' },
+ { name => 'description', value => 'A big problem' },
+ { name => 'site_code', value => 'Road ID' },
+ ),
+ }),
+ [ { name => 'site_code', value => 'Road ID' } ];
+
sub test_overrides {
# NB: Open311 and ::SendReport::Open311 are mocked below in BEGIN { ... }
- my ($cobrand, $input, $expected_data) = @_;
+ my ($cobrand, $input, $expected_data, $end_extra) = @_;
subtest "$cobrand ($input->{body_name}) overrides" => sub {
FixMyStreet::override_config {
- ALLOWED_COBRANDS => ['fixmystreet', 'oxfordshire', 'bromley', 'westberkshire', 'greenwich'],
+ ALLOWED_COBRANDS => ['fixmystreet', 'oxfordshire', 'bromley', 'westberkshire', 'greenwich', 'cheshireeast'],
}, sub {
my $db = FixMyStreet::DB->schema;
#$db->txn_begin;
- my $params = { id => $input->{body_id}, name => $input->{body_name} };
+ my $params = { name => $input->{body_name} };
my $body = $db->resultset('Body')->find_or_create($params);
- $body->body_areas->find_or_create({ area_id => $input->{body_id} });
+ $body->body_areas->find_or_create({ area_id => $input->{area_id} });
ok $body, "found/created body " . $input->{body_name};
$body->update({ can_be_devolved => 1 });
@@ -171,7 +205,7 @@ sub test_overrides {
whenedited => DateTime->now,
jurisdiction => '1234',
api_key => 'SEEKRIT',
- body_id => $input->{body_id},
+ body_id => $body->id,
);
$contact->update({ send_method => 'Open311', endpoint => 'http://example.com/open311' });
@@ -179,6 +213,7 @@ sub test_overrides {
name => 'Fred Bloggs',
email => TEST_USER_EMAIL,
password => 'dummy',
+ title => 'MR',
});
my $row = $db->resultset('Problem')->create( {
@@ -188,8 +223,8 @@ sub test_overrides {
name => 'Fred Bloggs',
anonymous => 1,
state => 'unconfirmed',
- bodies_str => $input->{body_id},
- areas => (sprintf ',%d,', $input->{body_id}),
+ bodies_str => $body->id,
+ areas => (sprintf ',%d,', $input->{area_id}),
category => 'ZZ',
cobrand => $cobrand,
user => $user,
@@ -204,6 +239,8 @@ sub test_overrides {
$sr->add_body($body, $contact);
$sr->send( $row, $input->{extra} || {} );
+ my $new_extra = $row->get_extra_fields;
+ cmp_deeply $new_extra, $end_extra || [];
cmp_deeply (Open311->_get_test_data, $expected_data, 'Data as expected')
or diag Dumper( Open311->_get_test_data );
@@ -239,13 +276,6 @@ BEGIN {
sub _get_test_data { return +{ %data } }
sub _reset_test_data { %data = () }
- package FixMyStreet::DB::Result::Problem;
- use Class::Method::Modifiers; # is marked as immutable by Moose
- sub discard_changes {
- $data{discard_changes}++;
- # no need to actually discard, as we're in transaction anyway
- };
-
package FixMyStreet::DB::Result::Body;
use Class::Method::Modifiers; # is marked as immutable by Moose
around get_cobrand_handler => sub {