diff options
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/report_inspect.t | 30 | ||||
-rw-r--r-- | t/app/sendreport/inspection_required.t | 32 |
2 files changed, 60 insertions, 2 deletions
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 6d6ec6559..393a8beb2 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -6,8 +6,8 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -my $brum = $mech->create_body_ok(2514, 'Birmingham City Council'); -my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council'); +my $brum = $mech->create_body_ok(2514, 'Birmingham City Council', id => 2514); +my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237); my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Cows', email => 'cows@example.net' ); my $rp = FixMyStreet::DB->resultset("ResponsePriority")->create({ body => $oxon, @@ -62,6 +62,16 @@ FixMyStreet::override_config { is $report->get_extra_metadata('inspected'), 1, 'report marked as inspected'; }; + subtest "test positive reputation" => sub { + $report->unset_extra_metadata('inspected'); + $report->update; + my $reputation = $report->user->get_extra_metadata("reputation"); + $mech->get_ok("/report/$report_id/inspect"); + $mech->submit_form_ok({ button => 'save_inspected', with_fields => { public_update => "This is a public update." } }); + $report->discard_changes; + is $report->user->get_extra_metadata('reputation'), $reputation+1, "User reputation was increased"; + }; + subtest "test update is required when instructing" => sub { $report->unset_extra_metadata('inspected'); $report->update; @@ -107,6 +117,22 @@ FixMyStreet::override_config { } }; +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + ALLOWED_COBRANDS => 'oxfordshire', +}, sub { + subtest "test negative reputation" => sub { + my $reputation = $report->user->get_extra_metadata("reputation"); + + $mech->get_ok("/report/$report_id"); + $mech->submit_form( button => 'remove_from_site' ); + + $report->discard_changes; + is $report->user->get_extra_metadata('reputation'), $reputation-1, "User reputation was decreased"; + }; +}; + + END { $mech->delete_body($oxon); $mech->delete_body($brum); diff --git a/t/app/sendreport/inspection_required.t b/t/app/sendreport/inspection_required.t index 88a48e991..f9d40d39f 100644 --- a/t/app/sendreport/inspection_required.t +++ b/t/app/sendreport/inspection_required.t @@ -69,6 +69,38 @@ subtest 'Uninspected report is sent when made by trusted user' => sub { $report->discard_changes; $mech->email_count_is( 1 ); ok $report->whensent, 'Report marked as sent'; + is $report->get_extra_metadata('inspected'), undef, 'Report not marked as inspected'; +}; + +subtest 'Uninspected report isn’t sent when user rep is too low' => sub { + $mech->clear_emails_ok; + $report->whensent( undef ); + $report->update; + + $user->user_body_permissions->delete; + $user->set_extra_metadata(reputation => 15); + $user->update; + + $contact->set_extra_metadata(reputation_threshold => 20); + $contact->update; + + FixMyStreet::DB->resultset('Problem')->send_reports(); + + $report->discard_changes; + $mech->email_count_is( 0 ); + is $report->whensent, undef, 'Report hasn’t been sent'; +}; + +subtest 'Uninspected report is sent when user rep is high enough' => sub { + $user->set_extra_metadata(reputation => 21); + $user->update; + + FixMyStreet::DB->resultset('Problem')->send_reports(); + + $report->discard_changes; + $mech->email_count_is( 1 ); + ok $report->whensent, 'Report marked as sent'; + is $report->get_extra_metadata('inspected'), undef, 'Report not marked as inspected'; }; done_testing(); |