diff options
Diffstat (limited to 't/open311/getservicerequestupdates.t')
-rw-r--r-- | t/open311/getservicerequestupdates.t | 237 |
1 files changed, 198 insertions, 39 deletions
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index aba811e58..00c25a83e 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -13,6 +13,7 @@ use_ok( 'Open311' ); use_ok( 'Open311::GetServiceRequestUpdates' ); use DateTime; +use DateTime::Format::W3CDTF; use FixMyStreet::App; my $user = FixMyStreet::App->model('DB::User')->find_or_create( @@ -123,7 +124,7 @@ my $problem = $problem_rs->new( lastupdate => DateTime->now()->subtract( days => 1 ), anonymous => 1, external_id => time(), - council => 2482, + bodies_str => 2482, } ); @@ -131,71 +132,212 @@ $problem->insert; for my $test ( { - desc => 'element with content', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), + desc => 'OPEN status for confirmed problem does not change state', description => 'This is a note', external_id => 638344, start_state => 'confirmed', - close_comment => 0, + comment_status => 'OPEN', mark_fixed=> 0, mark_open => 0, problem_state => undef, end_state => 'confirmed', }, { - desc => 'comment closes report', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), + desc => 'bad state does not update states but does create update', description => 'This is a note', external_id => 638344, start_state => 'confirmed', - close_comment => 1, + comment_status => 'INVALID_STATE', + mark_fixed=> 0, + mark_open => 0, + problem_state => undef, + end_state => 'confirmed', + }, + + { + desc => 'investigating status changes problem status', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'INVESTIGATING', + mark_fixed=> 0, + mark_open => 0, + problem_state => 'investigating', + end_state => 'investigating', + }, + { + desc => 'in progress status changes problem status', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'IN_PROGRESS', + mark_fixed=> 0, + mark_open => 0, + problem_state => 'in progress', + end_state => 'in progress', + }, + { + desc => 'action scheduled status changes problem status', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'ACTION_SCHEDULED', + mark_fixed=> 0, + mark_open => 0, + problem_state => 'action scheduled', + end_state => 'action scheduled', + }, + { + desc => 'not responsible status changes problem status', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'NOT_COUNCILS_RESPONSIBILITY', + mark_fixed=> 0, + mark_open => 0, + problem_state => 'not responsible', + end_state => 'not responsible', + }, + { + desc => 'internal referral status changes problem status', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'INTERNAL_REFERRAL', + mark_fixed=> 0, + mark_open => 0, + problem_state => 'internal referral', + end_state => 'internal referral', + }, + { + desc => 'duplicate status changes problem status', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'DUPLICATE', + mark_fixed=> 0, + mark_open => 0, + problem_state => 'duplicate', + end_state => 'duplicate', + }, + { + desc => 'fixed status marks report as fixed - council', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'FIXED', mark_fixed=> 0, mark_open => 0, problem_state => 'fixed - council', end_state => 'fixed - council', }, { - desc => 'comment re-opens fixed report', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), + desc => 'status of CLOSED marks report as fixed - council', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'CLOSED', + mark_fixed=> 0, + mark_open => 0, + problem_state => 'fixed - council', + end_state => 'fixed - council', + }, + { + desc => 'status of OPEN re-opens fixed report', description => 'This is a note', external_id => 638344, start_state => 'fixed - user', - close_comment => 0, + comment_status => 'OPEN', mark_fixed => 0, mark_open => 0, problem_state => 'confirmed', end_state => 'confirmed', }, { - desc => 'comment re-opens closed report', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), + desc => 'action sheduled re-opens fixed report as action scheduled', + description => 'This is a note', + external_id => 638344, + start_state => 'fixed - user', + comment_status => 'ACTION_SCHEDULED', + mark_fixed => 0, + mark_open => 0, + problem_state => 'action scheduled', + end_state => 'action scheduled', + }, + { + desc => 'open status re-opens closed report', description => 'This is a note', external_id => 638344, - start_state => 'closed', - close_comment => 0, + start_state => 'not responsible', + comment_status => 'OPEN', mark_fixed => 0, mark_open => 0, problem_state => 'confirmed', end_state => 'confirmed', }, { - desc => 'comment leaves report closed', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), + desc => 'fixed status leaves fixed - user report as fixed - user', + description => 'This is a note', + external_id => 638344, + start_state => 'fixed - user', + comment_status => 'FIXED', + mark_fixed => 0, + mark_open => 0, + problem_state => undef, + end_state => 'fixed - user', + }, + { + desc => 'closed status updates fixed report', + description => 'This is a note', + external_id => 638344, + start_state => 'fixed - user', + comment_status => 'NO_FURTHER_ACTION', + mark_fixed => 0, + mark_open => 0, + problem_state => 'unable to fix', + end_state => 'unable to fix', + }, + { + desc => 'no futher action status closes report', + description => 'This is a note', + external_id => 638344, + start_state => 'confirmed', + comment_status => 'NO_FURTHER_ACTION', + mark_fixed => 0, + mark_open => 0, + problem_state => 'unable to fix', + end_state => 'unable to fix', + }, + { + desc => 'fixed status sets closed report as fixed', + description => 'This is a note', + external_id => 638344, + start_state => 'unable to fix', + comment_status => 'FIXED', + mark_fixed => 0, + mark_open => 0, + problem_state => 'fixed - council', + end_state => 'fixed - council', + }, + { + desc => 'open status does not re-open hidden report', description => 'This is a note', external_id => 638344, - start_state => 'closed', - close_comment => 1, + start_state => 'hidden', + comment_status => 'OPEN', mark_fixed => 0, mark_open => 0, - end_state => 'closed', + problem_state => 'confirmed', + end_state => 'hidden', }, ) { subtest $test->{desc} => sub { my $local_requests_xml = $requests_xml; - $local_requests_xml =~ s/UPDATED_DATETIME/$test->{updated_datetime}/; + my $updated_datetime = sprintf( '<updated_datetime>%s</updated_datetime>', $dt ); + $local_requests_xml =~ s/UPDATED_DATETIME/$updated_datetime/; $local_requests_xml =~ s#<service_request_id>\d+</service_request_id>#<service_request_id>@{[$problem->external_id]}</service_request_id>#; $local_requests_xml =~ s#<service_request_id_ext>\d+</service_request_id_ext>#<service_request_id_ext>@{[$problem->id]}</service_request_id_ext>#; - $local_requests_xml =~ s#<status>\w+</status>#<status>closed</status># if $test->{close_comment}; + $local_requests_xml =~ s#<status>\w+</status>#<status>$test->{comment_status}</status># if $test->{comment_status}; my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); @@ -204,7 +346,7 @@ for my $test ( $problem->state( $test->{start_state} ); $problem->update; - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; my $update = Open311::GetServiceRequestUpdates->new( system_user => $user ); $update->update_comments( $o, $council_details ); @@ -234,7 +376,8 @@ foreach my $test ( $dt->subtract( minutes => 10 ); my $local_requests_xml = $requests_xml; - my $updated = sprintf( '<updated_datetime>%s</updated_datetime>', $dt ); + my $updated = sprintf( '<updated_datetime>%s</updated_datetime>', DateTime::Format::W3CDTF->format_datetime( $dt ) ); + $local_requests_xml =~ s/UPDATED_DATETIME/$updated/; $local_requests_xml =~ s#<service_request_id>\d+</service_request_id>#<service_request_id>@{[$problem->external_id]}</service_request_id>#; $local_requests_xml =~ s#<service_request_id_ext>\d+</service_request_id_ext>#<service_request_id_ext>@{[$problem->id]}</service_request_id_ext>#; @@ -243,7 +386,7 @@ foreach my $test ( $problem->comments->delete; - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; my $update = Open311::GetServiceRequestUpdates->new( system_user => $user ); $update->update_comments( $o, $council_details ); @@ -273,7 +416,7 @@ my $problem2 = $problem_rs->new( lastupdate => DateTime->now(), anonymous => 1, external_id => $problem->external_id, - council => 2651, + bodies_str => 2651, } ); @@ -312,7 +455,7 @@ for my $test ( my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); - my $council_details = { areaid => $test->{area_id} }; + my $council_details = { areas => { $test->{area_id} => 1 } }; my $update = Open311::GetServiceRequestUpdates->new( system_user => $user ); $update->update_comments( $o, $council_details ); @@ -352,7 +495,7 @@ subtest 'using start and end date' => sub { end_date => $end_dt, ); - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; $update->update_comments( $o, $council_details ); my $start = $start_dt . ''; @@ -412,7 +555,7 @@ subtest 'check that existing comments are not duplicated' => sub { system_user => $user, ); - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; $update->update_comments( $o, $council_details ); $problem->discard_changes; @@ -473,7 +616,7 @@ foreach my $test ( { system_user => $user, ); - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; $update->update_comments( $o, $council_details ); $problem->discard_changes; @@ -484,10 +627,22 @@ foreach my $test ( { foreach my $test ( { desc => 'normally alerts are not suppressed', + num_alerts => 1, suppress_alerts => 0, }, { desc => 'alerts suppressed if suppress_alerts set', + num_alerts => 1, + suppress_alerts => 1, + }, + { + desc => 'alert suppression ok even if no alerts', + num_alerts => 0, + suppress_alerts => 1, + }, + { + desc => 'alert suppression ok even if 2x alerts', + num_alerts => 2, suppress_alerts => 1, } ) { @@ -509,12 +664,14 @@ foreach my $test ( { $problem->lastupdate( $dt->subtract( hours => 3 ) ); $problem->update; - my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( { - alert_type => 'new_updates', - parameter => $problem->id, - confirmed => 1, - user_id => $problem->user->id, - } ); + my @alerts = map { + my $alert = FixMyStreet::App->model('DB::Alert')->create( { + alert_type => 'new_updates', + parameter => $problem->id, + confirmed => 1, + user_id => $problem->user->id, + } ) + } (1..$test->{num_alerts}); $requests_xml =~ s/UPDATED_DATETIME/$dt/; @@ -525,25 +682,27 @@ foreach my $test ( { suppress_alerts => $test->{suppress_alerts}, ); - my $council_details = { areaid => 2482 }; + my $council_details = { areas => { 2482 => 1 } }; $update->update_comments( $o, $council_details ); $problem->discard_changes; my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->search( { - alert_id => $alert->id, + alert_id => [ map $_->id, @alerts ], parameter => $problem->comments->first->id, } ); if ( $test->{suppress_alerts} ) { - ok $alerts_sent->count(), 'alerts suppressed'; + is $alerts_sent->count(), $test->{num_alerts}, 'alerts suppressed'; } else { is $alerts_sent->count(), 0, 'alerts not suppressed'; } $alerts_sent->delete; - $alert->delete; + for my $alert (@alerts) { + $alert->delete; + } } } |