Skip to content

Commit

Permalink
Fix over-display of "State changed to" in alerts.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jan 7, 2021
1 parent 43a5795 commit ac3d686
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 3 additions & 5 deletions perllib/FixMyStreet/Script/Alerts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ sub send() {
$query = FixMyStreet::DB->schema->storage->dbh->prepare($query);
$query->execute();
my $last_alert_id;
my $last_problem_state = '';
my $last_problem_state = 'confirmed';
my %data = ( template => $alert_type->template, data => [], schema => $schema );
while (my $row = $query->fetchrow_hashref) {

Expand Down Expand Up @@ -100,15 +100,13 @@ sub send() {
if ($row->{is_new_update}) {
# this might throw up the odd false positive but only in cases where the
# state has changed and there was already update text
if ($row->{item_problem_state} &&
!( $last_problem_state eq '' && $row->{item_problem_state} eq 'confirmed' ) &&
$last_problem_state ne $row->{item_problem_state}
) {
if ($row->{item_problem_state} && $last_problem_state ne $row->{item_problem_state}) {
my $state = FixMyStreet::DB->resultset("State")->display($row->{item_problem_state}, 1, $cobrand->moniker);

my $update = _('State changed to:') . ' ' . $state;
$row->{item_text} = $row->{item_text} ? $row->{item_text} . "\n\n" . $update :
$update;
$last_problem_state = $row->{item_problem_state};
}
next unless $row->{item_text};
}
Expand Down
5 changes: 5 additions & 0 deletions t/app/controller/alert_new.t
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ subtest "Test no marked as confirmed added to alerts" => sub {

my ($report) = $mech->create_problems_for_body(1, 1, 'Testing', {
user => $user1,
state => 'investigating',
});
my $report_id = $report->id;
ok $report, "created test report - $report_id";
Expand All @@ -556,6 +557,8 @@ subtest "Test no marked as confirmed added to alerts" => sub {
ok $alert, 'created alert for other user';

$mech->create_comment_for_problem($report, $user3, 'Staff User', 'this is update', 'f', 'confirmed', 'confirmed', { confirmed => $dt->clone->add( hours => 9 ) });
$mech->create_comment_for_problem($report, $user3, 'Staff User', 'this is another update', 'f', 'confirmed', 'investigating', { confirmed => $dt->clone->add( hours => 10 ) });
$mech->create_comment_for_problem($report, $user3, 'Staff User', 'this is a third update, same state', 'f', 'confirmed', 'investigating', { confirmed => $dt->clone->add( hours => 11 ) });

$mech->clear_emails_ok;
FixMyStreet::override_config {
Expand All @@ -570,6 +573,8 @@ subtest "Test no marked as confirmed added to alerts" => sub {
like $body, qr/The following updates have been left on this report:/, 'email is about updates to existing report';
like $body, qr/Staff User/, 'Update comes from correct user';
unlike $body, qr/State changed to: Open/s, 'no marked as confirmed text';
like $body, qr/State changed to: Investigating/, 'mention of state change';
unlike $body, qr/State changed to: Investigating.*State changed to: Investigating/s, 'only one mention of state change';

$mech->delete_user($user1);
$mech->delete_user($user2);
Expand Down

0 comments on commit ac3d686

Please sign in to comment.