aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2019-07-26 17:47:32 +0100
committerStruan Donald <struan@exo.org.uk>2019-08-14 09:26:01 +0100
commitbafdef065a13720c180067d0fb522ecd3f1aac37 (patch)
tree7cd4ed3acf6ab406524765e533d6d4d4f54d8c8f
parenta18c143e8aacd978bbe9c055fa2b3a225a5d4f09 (diff)
[Northamptonshire] do not send comments on defects
There is no support for updates to defects so if a report was created from a defect (i.e. the user is the comment_user) then skip sending the comment
-rw-r--r--perllib/FixMyStreet/Cobrand/Northamptonshire.pm12
-rw-r--r--t/cobrand/northamptonshire.t58
2 files changed, 69 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Northamptonshire.pm b/perllib/FixMyStreet/Cobrand/Northamptonshire.pm
index d9c3b97e6..533dad5d3 100644
--- a/perllib/FixMyStreet/Cobrand/Northamptonshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Northamptonshire.pm
@@ -76,6 +76,18 @@ sub open311_config {
$params->{multi_photos} = 1;
}
+sub should_skip_sending_update {
+ my ($self, $comment) = @_;
+
+ my $p = $comment->problem;
+ my %body_users = map { $_->comment_user_id => 1 } values %{ $p->bodies };
+ if ( $body_users{ $p->user->id } ) {
+ return 1;
+ }
+
+ return 0;
+}
+
sub report_validation {
my ($self, $report, $errors) = @_;
diff --git a/t/cobrand/northamptonshire.t b/t/cobrand/northamptonshire.t
index 3331f0c99..09023f4c0 100644
--- a/t/cobrand/northamptonshire.t
+++ b/t/cobrand/northamptonshire.t
@@ -1,13 +1,19 @@
use Test::MockModule;
use FixMyStreet::TestMech;
+use Open311::PostServiceRequestUpdates;
+
my $mech = FixMyStreet::TestMech->new;
use open ':std', ':encoding(UTF-8)';
-my $ncc = $mech->create_body_ok(2234, 'Northamptonshire County Council');
+my $ncc = $mech->create_body_ok(2234, 'Northamptonshire County Council', {
+ send_method => 'Open311', api_key => 'key', 'endpoint' => 'e', 'jurisdiction' => 'j', send_comments => 1 });
my $nbc = $mech->create_body_ok(2397, 'Northampton Borough Council');
+my $counciluser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $ncc);
+my $user = $mech->create_user_ok('user@example.com', name => 'User');
+
my $ncc_contact = $mech->create_contact_ok(
body_id => $ncc->id,
category => 'Trees',
@@ -20,6 +26,28 @@ my $nbc_contact = $mech->create_contact_ok(
email => 'flytipping-2397@example.com',
);
+my ($report) = $mech->create_problems_for_body(1, $ncc->id, 'Defect Problem', {
+ whensent => DateTime->now()->subtract( minutes => 5 ),
+ external_id => 1,
+ send_method_used => 'Open311',
+ user => $counciluser
+});
+
+my $comment = FixMyStreet::DB->resultset('Comment')->create( {
+ mark_fixed => 0,
+ user => $user,
+ problem => $report,
+ anonymous => 0,
+ text => 'this is a comment',
+ confirmed => DateTime->now,
+ state => 'confirmed',
+ problem_state => 'confirmed',
+ cobrand => 'default',
+} );
+
+$ncc->update( { comment_user_id => $counciluser->id } );
+
+
subtest 'Check district categories hidden on cobrand' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { northamptonshire => '.' } ],
@@ -38,4 +66,32 @@ subtest 'Check district categories hidden on cobrand' => sub {
};
};
+subtest 'Check updates not sent for defects' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { northamptonshire => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ my $updates = Open311::PostServiceRequestUpdates->new();
+ $updates->send;
+ };
+
+ $comment->discard_changes;
+ is $comment->send_fail_count, 0, "comment sending not attempted";
+ is $comment->get_extra_metadata('cobrand_skipped_sending'), 1, "skipped sending comment";
+};
+
+$report->update({ user => $user });
+subtest 'check updates sent for non defects' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { northamptonshire => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ my $updates = Open311::PostServiceRequestUpdates->new();
+ $updates->send;
+ };
+
+ $comment->discard_changes;
+ is $comment->send_fail_count, 1, "comment sending attempted";
+};
+
done_testing();