Skip to content

Commit

Permalink
[Archive] Add category filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Feb 18, 2022
1 parent 560b3c3 commit 5a68f8b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/archive-old-enquiries
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ my ($opts, $usage) = describe_options(
'%c %o',
['commit|c', "actually close reports and send emails. Omitting this flag will do a dry-run"],
['body|b=s', "which body ID to close reports for", { required => 1 } ],
['category=s@', "which category or categories to close reports for" ],
['user|u=s', "which user ID to assign closure updates to", { required => 1 } ],
['cobrand=s', "which cobrand template to use for sent emails" ],
[ "mode" => hidden => { one_of => [
Expand Down
3 changes: 3 additions & 0 deletions perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ sub filter {
my $params = {
state => [ FixMyStreet::DB::Result::Problem->open_states() ],
};
if ($opts->{category}) {
$params->{category} = $opts->{category};
}
return $rs->to_body($opts->{body})->search($params);
}

Expand Down
32 changes: 32 additions & 0 deletions t/script/archive_old_enquiries.t
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,36 @@ subtest 'date based updates do not happen without commit' => sub {
};
};

subtest 'category based closure' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'oxfordshire' ],
}, sub {

$opts->{category} = ["Something"];
$opts->{commit} = 1;

$mech->clear_emails_ok;

my ($report1) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Test', {
lastupdate => '2015-12-01 07:00:00',
});

my ($report2) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Test 2', {
lastupdate => '2015-12-01 07:00:00',
category => 'Something',
});

FixMyStreet::Script::ArchiveOldEnquiries::archive($opts);

$report1->discard_changes;
$report2->discard_changes;
is $report1->state, 'confirmed', 'Report 1 has not been updated';
is $report2->state, 'fixed', 'Report 2 has been updated';
is $report1->comments->count, 0, 'Report 1 has no comments';
is $report2->comments->count, 1, 'Report 1 has no comments';
$mech->email_count_is(1);
$mech->clear_emails_ok;
};
};

done_testing();

0 comments on commit 5a68f8b

Please sign in to comment.