diff options
author | Struan Donald <struan@exo.org.uk> | 2017-10-06 15:36:08 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2017-10-17 09:55:50 +0100 |
commit | 56a4f2d8ea52623cc8184da921ea5fd5c0124c1d (patch) | |
tree | 86ff38aa758aa3507084ae4aba3773bbee410d3b /t/app/controller | |
parent | 6e7a34d79217f71076f65b3017eba313b78854cb (diff) |
make sure duplicate id provided when marking as duplicate
It was possible to mark a report as a duplicate in the inspector panel
without providing an id of the duplicate. This prevents that.
Fixes mysociety/fixmystreetforcouncils#236
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/report_inspect.t | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index f74c94c34..b3a3990a3 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -148,6 +148,67 @@ FixMyStreet::override_config { $report2->update; }; + subtest "can mark a report as duplicate without supplying a duplicate and a public update" => sub { + my $old_state = $report->state; + $report->comments->delete_all; + + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', include_update => "0" } }); + + $mech->content_contains('provide a duplicate ID', "error message about missing duplicate id"); + $report->discard_changes; + $report2->discard_changes; + + is $report->state, $old_state, 'report not marked as duplicate'; + is $report->comments->search({ problem_state => 'duplicate' })->count, 0, 'no update marking report as duplicate was left'; + + is $report->get_extra_metadata('duplicate_of'), undef; + + $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', public_update => 'This is a duplicate', include_update => "1" } }); + $mech->content_lacks('provide a duplicate ID', "no error message about missing duplicate id"); + $report->discard_changes; + $report2->discard_changes; + + is $report->state, 'duplicate', 'report marked as duplicate'; + is $report->comments->search({ problem_state => 'duplicate' })->count, 1, 'update marking report as duplicate was left'; + is $report->get_extra_metadata('duplicate_of'), undef; + is_deeply $report2->get_extra_metadata('duplicates'), undef; + + $report->update({ state => $old_state }); + }; + + subtest "can mark a report as duplicate without supplying a public update and a duplicate id" => sub { + my $old_state = $report->state; + $report->comments->delete_all; + + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', include_update => "0" } }); + + $mech->content_contains('provide a duplicate ID', "error message about missing duplicate id"); + $report->discard_changes; + $report2->discard_changes; + + is $report->state, $old_state, 'report not marked as duplicate'; + is $report->comments->search({ problem_state => 'duplicate' })->count, 0, 'no update marking report as duplicate was left'; + + is $report->get_extra_metadata('duplicate_of'), undef; + + $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', duplicate_of => $report2->id, include_update => "0" } }); + $mech->content_lacks('provide a duplicate ID', "no error message about missing duplicate id"); + $report->discard_changes; + $report2->discard_changes; + + is $report->state, 'duplicate', 'report marked as duplicate'; + is $report->comments->search({ problem_state => 'duplicate' })->count, 1, 'update marking report as duplicate was left'; + is $report->get_extra_metadata('duplicate_of'), $report2->id; + is_deeply $report2->get_extra_metadata('duplicates'), [ $report->id ]; + + $report->set_extra_metadata('duplicate_of', undef); + $report->update({ state => $old_state }); + $report2->set_extra_metadata('duplicates', undef); + $report2->update; + }; + subtest "marking a report as a duplicate with update correctly sets update status" => sub { my $old_state = $report->state; $report->comments->delete_all; |