diff options
author | Marius Halden <marius.h@lden.org> | 2021-10-07 13:32:40 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2021-10-07 13:32:40 +0200 |
commit | 09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch) | |
tree | 7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /t/app/model/responsepriority.t | |
parent | 585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff) | |
parent | cea89fb87a96943708a1db0f646492fbfaaf000f (diff) |
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 't/app/model/responsepriority.t')
-rw-r--r-- | t/app/model/responsepriority.t | 49 |
1 files changed, 37 insertions, 12 deletions
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(); |