aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm4
-rw-r--r--t/cobrand/zurich.t189
2 files changed, 136 insertions, 57 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 690fff104..b3e288bc4 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -737,11 +737,11 @@ sub admin_stats {
# Reports assigned to third party
my $closed = $c->model('DB::Problem')->search( { state => 'closed', %date_params } )->count;
# Reports moderated within 1 day
- my $moderated = $c->model('DB::Problem')->search( { extra => { like => '%moderated_overdue,I1:0%' }, %params } )->count;
+ my $moderated = $c->model('DB::Problem')->search( { extra => { like => '%moderated_overdue,I1:0%' }, %date_params } )->count;
# Reports solved within 5 days (sent back from subdiv)
my $subdiv_dealtwith = $c->model('DB::Problem')->search( { extra => { like => '%subdiv_overdue,I1:0%' }, %params } )->count;
# Reports solved within 5 days (marked as 'fixed - council', 'closed', or 'hidden'
- my $fixed_in_time = $c->model('DB::Problem')->search( { extra => { like => '%closed_overdue,I1:0%' }, %params } )->count;
+ my $fixed_in_time = $c->model('DB::Problem')->search( { extra => { like => '%closed_overdue,I1:0%' }, %date_params } )->count;
# Reports per category
my $per_category = $c->model('DB::Problem')->search( \%params, {
select => [ 'category', { count => 'id' } ],
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index a03099aac..fb6f172fe 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -26,6 +26,20 @@ sub send_reports_for_zurich {
FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
};
}
+sub reset_report_state {
+ my ($report, $created) = @_;
+ $report->discard_changes;
+ my $extra = $report->extra;
+ delete $extra->{moderated_overdue};
+ delete $extra->{subdiv_overdue};
+ delete $extra->{closed_overdue};
+ $report->update({
+ extra => { %$extra },
+ state => 'unconfirmed',
+ $created ? ( created => $created ) : (),
+ });
+}
+
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -65,6 +79,13 @@ $external_body->send_method( 'Zurich' );
$external_body->endpoint( 'external_body@example.org' );
$external_body->update;
+subtest "set up superuser" => sub {
+ my $superuser = $mech->log_in_ok( 'super@example.org' );
+ # a user from body $zurich is a superuser, as $zurich has no parent id!
+ $superuser->update({ from_body => $zurich->id });
+ $mech->log_out_ok;
+};
+
my @reports = $mech->create_problems_for_body( 1, 2, 'Test', {
state => 'unconfirmed',
confirmed => undef,
@@ -143,73 +164,131 @@ subtest "changing of categories" => sub {
my $new_comment = $comments_rs->first();
is( $new_comment->text, "Weitergeleitet von Cat1 an Cat2", "category change comment created" );
- # restore report to original state.
+ # restore report to original category.
$report->update({category => $original_category });
};
-ok ( ! exists ${$report->extra}{moderated_overdue}, 'Report currently unmoderated' );
+sub get_moderated_count {
+ # my %date_params = ( );
+ # my $moderated = FixMyStreet::App->model('DB::Problem')->search({
+ # extra => { like => '%moderated_overdue,I1:0%' }, %date_params } )->count;
+ # return $moderated;
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
-}, sub {
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->content_contains( 'Unbestätigt' ); # Unconfirmed email
- $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
- $mech->get_ok( '/report/' . $report->id );
-};
-$mech->content_contains('Aufgenommen');
-$mech->content_contains('Test Test');
-$mech->content_lacks('photo/' . $report->id . '.jpeg');
-$mech->email_count_is(0);
+ # use a separate mech to avoid stomping on test state
+ my $mech = FixMyStreet::TestMech->new;
+ my $user = $mech->log_in_ok( 'super@example.org' );
-$report->discard_changes;
-is ( $report->extra->{moderated_overdue}, 0, 'Report now marked moderated' );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get( '/admin/stats' );
+ };
+ if ($mech->content =~/Innerhalb eines Arbeitstages moderiert: (\d+)/) {
+ return $1;
+ }
+ else {
+ fail sprintf "Could not get moderation results (%d)", $mech->status;
+ return undef;
+ }
+}
-# Set state back to 10 days ago so that report is overdue
-my $created = $report->created;
-$report->update({
- state => 'unconfirmed',
- created => $created->subtract(days => 10),
-});
+subtest "report_edit" => sub {
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
-}, sub {
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
- $mech->get_ok( '/report/' . $report->id );
-};
-$report->discard_changes;
-is ( $report->extra->{moderated_overdue}, 0, 'Report still not overdue (subsequent time)' );
+ ok ( ! exists ${$report->extra}{moderated_overdue}, 'Report currently unmoderated' );
-$report->update({ created => $created }); # reset
-
-# delete the {moderated_overdue} so that changing status will now reset moderation
-{
- my $extra = $report->extra;
- delete $extra->{moderated_overdue};
- $report->update({
- extra => { %$extra },
- state => 'unconfirmed',
- });
-}
+ is get_moderated_count(), 0;
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
-}, sub {
- $mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
- $mech->get_ok( '/report/' . $report->id );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains( 'Unbestätigt' ); # Unconfirmed email
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
+ };
+
+ $mech->content_contains('Aufgenommen');
+ $mech->content_contains('Test Test');
+ $mech->content_lacks('photo/' . $report->id . '.jpeg');
+ $mech->email_count_is(0);
+
+ $report->discard_changes;
+
+ is ( $report->extra->{moderated_overdue}, 0, 'Report now marked moderated' );
+ is get_moderated_count(), 1;
+
+
+ # Set state back to 10 days ago so that report is overdue
+ my $created = $report->created;
+ reset_report_state($report, $created->clone->subtract(days => 10));
+
+ is get_moderated_count(), 0;
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
+ };
+ $report->discard_changes;
+ is ( $report->extra->{moderated_overdue}, 1, 'moderated_overdue set correctly when overdue' );
+ is get_moderated_count(), 0, 'Moderated count not increased when overdue';
+
+ reset_report_state($report, $created);
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
+ };
+ $report->discard_changes;
+ is ( $report->extra->{moderated_overdue}, 0, 'Marking confirmed sets moderated_overdue' );
+ is ( $report->extra->{closed_overdue}, undef, 'Marking confirmed does NOT set closed_overdue' );
+ is get_moderated_count(), 1;
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'hidden' } } );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ };
+ $report->discard_changes;
+ is ( $report->extra->{moderated_overdue}, 0, 'Still marked moderated_overdue' );
+ is ( $report->extra->{closed_overdue}, 0, 'Marking hidden also set closed_overdue' );
+ is get_moderated_count(), 1, 'Check still counted moderated'
+ or diag $report->get_column('extra');
+
+ reset_report_state($report);
+
+ is ( $report->extra->{moderated_overdue}, undef, 'Sanity check' );
+ is get_moderated_count(), 0;
+
+ # Check that setting to 'hidden' also triggers moderation
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'hidden' } } );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ };
+ $report->discard_changes;
+ is ( $report->extra->{moderated_overdue}, 0, 'Marking hidden from scratch sets moderated_overdue' );
+ is ( $report->extra->{closed_overdue}, 0, 'Marking hidden from scratch also set closed_overdue' );
+ is get_moderated_count(), 1;
+
+ reset_report_state($report);
};
-$report->discard_changes;
-is ( $report->extra->{moderated_overdue}, 1, 'Report marked as moderated_overdue' );
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'zurich' ],
}, sub {
# Photo publishing
$mech->get_ok( '/admin/report_edit/' . $report->id );
- $mech->submit_form_ok( { with_fields => { publish_photo => 1 } } );
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed', publish_photo => 1 } } );
$mech->get_ok( '/report/' . $report->id );
$mech->content_contains('photo/' . $report->id . '.jpeg');
@@ -414,8 +493,6 @@ $mech->log_out_ok;
subtest "only superuser can see stats" => sub {
$user = $mech->log_in_ok( 'super@example.org' );
- # a user from body $zurich is a superuser, as $zurich has no parent id!
- $user->update({ from_body => $zurich->id });
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'zurich' ],
@@ -549,8 +626,10 @@ subtest "test stats" => sub {
};
is $mech->res->code, 200, "superuser should be able to see stats page";
- $mech->content_contains('Innerhalb eines Arbeitstages moderiert: 1');
- $mech->content_contains('Innerhalb von fünf Arbeitstagen abgeschlossen: 1');
+ $mech->content_contains('Innerhalb eines Arbeitstages moderiert: 2'); # now including hidden
+ $mech->content_contains('Innerhalb von fünf Arbeitstagen abgeschlossen: 3');
+ # my @data = $mech->content =~ /(?:moderiert|abgeschlossen): \d+/g;
+ # diag Dumper(\@data); use Data::Dumper;
$mech->log_out_ok;
};