aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Mock/Tilma.pm27
-rw-r--r--t/open311/getservicerequestupdates.t79
2 files changed, 97 insertions, 9 deletions
diff --git a/t/Mock/Tilma.pm b/t/Mock/Tilma.pm
index 5a11209e3..7542b1f5e 100644
--- a/t/Mock/Tilma.pm
+++ b/t/Mock/Tilma.pm
@@ -10,6 +10,18 @@ has json => (
},
);
+sub as_json {
+ my ($self, $features) = @_;
+ my $json = mySociety::Locale::in_gb_locale {
+ $self->json->encode({
+ type => "FeatureCollection",
+ crs => { type => "name", properties => { name => "urn:ogc:def:crs:EPSG::27700" } },
+ features => $features,
+ });
+ };
+ return $json;
+}
+
sub dispatch_request {
my $self = shift;
@@ -25,15 +37,16 @@ sub dispatch_request {
[ 539408.94, 170607.58 ],
] ] } } ];
}
- my $json = mySociety::Locale::in_gb_locale {
- $self->json->encode({
- type => "FeatureCollection",
- crs => { type => "name", properties => { name => "urn:ogc:def:crs:EPSG::27700" } },
- features => $features,
- });
- };
+ my $json = $self->as_json($features);
return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
},
+
+ sub (GET + /mapserver/highways + ?*) {
+ my ($self, $args) = @_;
+ my $json = $self->as_json([]);
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
+
}
__PACKAGE__->run_if_script;
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 07c3b4cdd..35be0f7b5 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -932,8 +932,6 @@ subtest 'check that external_status_code triggers auto-responses' => sub {
$problem->discard_changes;
is $problem->comments->count, 1, 'one comment after fetching updates';
- my $comment = $problem->comments->first;
-
is $problem->comments->first->text, "Thank you for your report. We will provide an update within 24 hours.", "correct external status code on first comment";
};
@@ -991,6 +989,83 @@ foreach my $test ( {
$problem->comments->delete;
};
}
+
+my $response_template_in_progress = $bodies{2482}->response_templates->create({
+ title => "Acknowledgement 1",
+ text => "Thank you for your report. We will provide an update within 48 hours.",
+ auto_response => 1,
+ state => "in progress"
+});
+
+for my $test (
+ {
+ external_code => '090',
+ description => 'check numeric external status code in response template override state',
+ },
+ {
+ external_code => 'futher',
+ description => 'check alpha external status code in response template override state',
+ },
+) {
+ subtest $test->{description} => sub {
+ my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
+ <service_requests_updates>
+ <request_update>
+ <update_id>638344</update_id>
+ <service_request_id>@{[ $problem->external_id ]}</service_request_id>
+ <status>in_progress</status>
+ <description></description>
+ <updated_datetime>UPDATED_DATETIME</updated_datetime>
+ <external_status_code></external_status_code>
+ </request_update>
+ <request_update>
+ <update_id>638345</update_id>
+ <service_request_id>@{[ $problem->external_id ]}</service_request_id>
+ <status>in_progress</status>
+ <description></description>
+ <updated_datetime>UPDATED_DATETIME2</updated_datetime>
+ <external_status_code>@{[ $test->{external_code} ]}</external_status_code>
+ </request_update>
+ </service_requests_updates>
+ };
+
+ my $response_template = $bodies{2482}->response_templates->create({
+ # the default ordering uses the title of the report so
+ # make sure this comes second
+ title => "Acknowledgement 2",
+ text => "Thank you for your report. We will provide an update within 24 hours.",
+ auto_response => 1,
+ external_status_code => $test->{external_code}
+ });
+
+ $problem->comments->delete;
+
+ my $dt2 = $dt->clone->add( minutes => 1 );
+ $requests_xml =~ s/UPDATED_DATETIME/$dt/;
+ $requests_xml =~ s/UPDATED_DATETIME2/$dt2/;
+
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } );
+
+ my $update = Open311::GetServiceRequestUpdates->new(
+ system_user => $user,
+ current_open311 => $o,
+ current_body => $bodies{2482},
+ );
+
+ $update->process_body;
+
+ $problem->discard_changes;
+ is $problem->comments->count, 2, 'two comment after fetching updates';
+
+ my @comments = $problem->comments;
+
+ is $comments[0]->text, "Thank you for your report. We will provide an update within 48 hours.", "correct external status code on first comment";
+ is $comments[1]->text, "Thank you for your report. We will provide an update within 24 hours.", "correct external status code on second comment";
+ $problem->comments->delete;
+ $response_template->delete;
+ };
+}
+
subtest 'check that first comment always updates state' => sub {
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests_updates>