aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorM Somerville <matthew-github@dracos.co.uk>2020-10-02 16:25:31 +0100
committerM Somerville <matthew-github@dracos.co.uk>2020-10-02 16:25:31 +0100
commitc344dd774bc68dd1b9c7d41dc3c63c29ce4b3f42 (patch)
treece45124c84f7be55653c92ab8f9a29650c6a8f8d /t
parent399b8a783a1833098ab8401087d8a6609ac6d515 (diff)
parente3e1e9d54999692dc01f3fdd32693547af8deb7b (diff)
Merge branch 'deleted-response-priorities'
Diffstat (limited to 't')
-rw-r--r--t/app/controller/report_inspect.t12
-rw-r--r--t/app/model/responsepriority.t49
2 files changed, 49 insertions, 12 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 96325760c..c10fe7f94 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -17,6 +17,11 @@ my $rp2 = FixMyStreet::DB->resultset("ResponsePriority")->create({
body => $oxon,
name => 'Low Priority',
});
+my $rp3 = FixMyStreet::DB->resultset("ResponsePriority")->create({
+ body => $oxon,
+ name => 'Deleted Priority',
+ deleted => 1,
+});
FixMyStreet::DB->resultset("ContactResponsePriority")->create({
contact => $contact,
response_priority => $rp,
@@ -447,6 +452,7 @@ FixMyStreet::override_config {
subtest "default response priorities display correctly" => sub {
$mech->get_ok("/report/$report_id");
$mech->content_contains('Priority</label', 'report priority list present');
+ $mech->content_lacks('Deleted Priority');
like $mech->content, qr/<select name="priority" id="problem_priority" class="form-control">[^<]*<option value="" selecte/s, 'blank priority option is selected';
$mech->content_lacks('value="' . $rp->id . '" selected>High', 'non default priority not selected');
@@ -456,6 +462,12 @@ FixMyStreet::override_config {
$mech->content_contains('value="' . $rp->id . '" selected>High', 'default priority selected');
};
+ subtest "check when report has deleted priority" => sub {
+ $report->update({ response_priority => $rp3 });
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains('value="' . $rp3->id . '" selected>Deleted Priority');
+ };
+
foreach my $test (
{ type => 'report_edit_priority', priority => 1 },
{ type => 'report_edit_category', category => 1 },
diff --git a/t/app/model/responsepriority.t b/t/app/model/responsepriority.t
index bd09c2da0..0ecce1529 100644
--- a/t/app/model/responsepriority.t
+++ b/t/app/model/responsepriority.t
@@ -12,6 +12,7 @@ my $oxfordshire = $mech->create_body_ok($area_id, 'Oxfordshire County Council');
my $other_body = $mech->create_body_ok($area_id, 'Some Other Council');
my $potholes_contact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' );
my $traffic_lights_contact =$mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' );
+my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all;
my $potholes_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->find_or_create(
{
@@ -32,25 +33,42 @@ my $general_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->
}
);
-subtest 'for_bodies returns correct results' => sub {
+my $deleted1_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->find_or_create(
+ {
+ body_id => $oxfordshire->id,
+ name => 'Deleted priority 1',
+ description => 'This priority has been deleted',
+ deleted => 1,
+ }
+);
+
+my $deleted2_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->find_or_create(
+ {
+ body_id => $oxfordshire->id,
+ name => 'Deleted priority 2',
+ description => 'This priority has been deleted',
+ deleted => 1,
+ }
+);
+
+subtest 'for_bodies returns correct results (including deleted)' => sub {
my $priorities = FixMyStreet::DB->resultset('ResponsePriority')->for_bodies(
[ $oxfordshire->id ],
'Potholes'
);
- is $priorities->count, 2, 'Both priorities are included for Potholes category';
+ is $priorities->count, 4, 'all priorities are included for Potholes category';
$priorities = FixMyStreet::DB->resultset('ResponsePriority')->for_bodies(
[ $oxfordshire->id ],
'Traffic lights'
);
- is $priorities->count, 1, 'Only 1 priority is included for Traffic lights category';
+ is $priorities->count, 3, 'Pothole-only priority ignored for Traffic lights category';
is $priorities->first->name, $general_response_priority->name, 'Correct priority is returned for Traffic lights category';
};
-subtest 'by_categories returns all response priorities grouped by category' => sub {
- my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all;
+subtest 'by_categories returns all undeleted response priorities grouped by category' => sub {
my $priorities = FixMyStreet::DB->resultset('ResponsePriority')->by_categories(\@contacts, body_id => $oxfordshire->id);
my $potholes = decode_json($priorities->{Potholes});
my $traffic_lights = decode_json($priorities->{'Traffic lights'});
@@ -59,7 +77,7 @@ subtest 'by_categories returns all response priorities grouped by category' => s
is scalar @$traffic_lights, 1, 'Traffic lights have 1 defect type';
};
-subtest 'by_categories returns all response priorities for an area with multiple bodies' => sub {
+subtest 'by_categories returns all undeleted response priorities for an area with multiple bodies' => sub {
my $other_response_priority = FixMyStreet::DB->resultset('ResponsePriority')->find_or_create(
{
body_id => $other_body->id,
@@ -68,7 +86,6 @@ subtest 'by_categories returns all response priorities for an area with multiple
}
);
- my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { body_id => [ $oxfordshire->id ] } )->all;
my $priorities = FixMyStreet::DB->resultset('ResponsePriority')->by_categories(\@contacts, area_id => $area_id);
my $potholes = decode_json($priorities->{Potholes});
my $traffic_lights = decode_json($priorities->{'Traffic lights'});
@@ -77,8 +94,16 @@ subtest 'by_categories returns all response priorities for an area with multiple
is scalar @$traffic_lights, 2, 'Traffic lights have 2 defect types';
};
-END {
- $mech->delete_body( $other_body );
- $mech->delete_body( $oxfordshire );
- done_testing();
-}
+subtest 'test with existing problem' => sub {
+ my ($problem) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Title', {
+ response_priority => $deleted1_response_priority,
+ });
+ my $priorities = FixMyStreet::DB->resultset('ResponsePriority')->by_categories(\@contacts,
+ area_id => $area_id, problem => $problem);
+ my $potholes = decode_json($priorities->{Potholes});
+ my $traffic_lights = decode_json($priorities->{'Traffic lights'});
+ is scalar @$potholes, 4, 'Potholes have 4 defect types, deleted is included';
+ is scalar @$traffic_lights, 3, 'Traffic lights have 3 defect types, deleted is included';
+};
+
+done_testing();