Skip to content

Commit

Permalink
Include status change line in update emails using auto response
Browse files Browse the repository at this point in the history
templates.

Except for waste categories.

#4901
  • Loading branch information
neprune committed May 28, 2024
1 parent a0876c3 commit 44674bb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Switch to OpenStreetMap for reverse geocoding. #4444
- Convert all uploaded images to JPEGs.
- Redirect after POST when creating reports. #4362
- Include status change line in report update emails using auto response templates.

* v5.0 (10th May 2023)
- Front end improvements:
Expand Down
3 changes: 3 additions & 0 deletions perllib/FixMyStreet/Script/Alerts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ sub send_alert_type {
$row->{item_text_original} = $row->{item_text};
$row->{item_text} = $row->{item_text} ? $row->{item_text} . "\n\n" . $update :
$update;
if ($row->{item_private_email_text} && $report->cobrand_data ne 'waste') {
$row->{item_private_email_text} = $row->{item_private_email_text} . "\n\n" . $update;
}
$last_problem_state = $row->{item_problem_state};
}
next unless $row->{item_text};
Expand Down
81 changes: 81 additions & 0 deletions t/app/controller/alert_new.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use utf8;
use FixMyStreet::TestMech;
use FixMyStreet::Script::Alerts;

use_ok( 'Open311::GetUpdates' );
use_ok( 'Open311' );

use t::Mock::Twilio;
my $twilio = t::Mock::Twilio->new;
LWP::Protocol::PSGI->register($twilio->to_psgi_app, host => 'api.twilio.com');
Expand Down Expand Up @@ -1044,5 +1047,83 @@ FixMyStreet::override_config {
};
};

subtest 'check state update line included in auto response template alerts' => sub {
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests>
<request>
<service_request_id>1234</service_request_id>
<status>investigating</status>
<service_name>Test Service</service_name>
<service_code>test_service_code</service_code>
<description></description>
<agency_responsible></agency_responsible>
<service_notice></service_notice>
<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime>
<updated_datetime>UPDATED_DATETIME</updated_datetime>
<lat>37.762221815</lat>
<long>-122.4651145</long>
</request>
</service_requests>
};
my $dt = DateTime->now->add( minutes => -30 );

my $system_user = FixMyStreet::DB->resultset('User')->find_or_create(
{
email => '[email protected]'
}
);
my $template = FixMyStreet::DB->resultset("ResponseTemplate")->create({
body => $body,
state => 'investigating',
title => 'Investigating email response',
text => "Cheers we'll have a gander.",
email_text => "Cheers we'll have a gander.",
auto_response => 1,
});
my $resident_user = $mech->create_user_ok('[email protected]');
my $contact = $mech->create_contact_ok( body_id => $body->id, category => 'Whatever', email => 'WHATEVER' );
my ($report) = $mech->create_problems_for_body(1, $body->id, 'Testing', {
user => $resident_user,
state => 'confirmed',
external_id => 1234,
lastupdate => $dt->add( minutes => -1),
category => $contact->category,
});


my $alert = FixMyStreet::DB->resultset('Alert')->create({
user => $resident_user,
alert_type => 'new_updates',
parameter => $report->id,
confirmed => 1,
whensubscribed => $dt,
});
ok $alert, "alert created";

my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com' );

$requests_xml =~ s/UPDATED_DATETIME/$dt/;
Open311->_inject_response('/requests.xml', $requests_xml);

FixMyStreet::override_config {
ALLOWED_COBRANDS => 'fixmystreet',
}, sub {
my $updates = Open311::GetUpdates->new(
system_user => $system_user,
current_open311 => $o,
current_body => $body,
blank_updates_permitted => 1,
);
$updates->update_reports( [ $report ] );
$report->discard_changes;
FixMyStreet::Script::Alerts::send_updates();
};

$mech->email_count_is(1);
my $email = $mech->get_text_body_from_email;
like $email, qr/Cheers we'll have a gander/, '';
like $email, qr/State changed to: Investigating/, '';

};

done_testing();

0 comments on commit 44674bb

Please sign in to comment.