aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/controller/admin.t112
-rw-r--r--t/open311/getservicerequestupdates.t30
-rw-r--r--t/open311/populate-service-list.t9
3 files changed, 143 insertions, 8 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 0be54dbc5..179557976 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -1659,6 +1659,108 @@ subtest "response templates are included on page" => sub {
};
};
+subtest "auto-response templates that duplicate a single category can't be added" => sub {
+ $mech->delete_response_template($_) for $oxfordshire->response_templates;
+ my $template = $oxfordshire->response_templates->create({
+ title => "Report fixed - potholes",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 1,
+ state => 'fixed - council',
+ });
+ $template->contact_response_templates->find_or_create({
+ contact_id => $oxfordshirecontact->id,
+ });
+ is $oxfordshire->response_templates->count, 1, "Initial response template was created";
+
+
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok( "/admin/templates/" . $oxfordshire->id . "/new" );
+
+ # This response template has the same category & state as an existing one
+ # so won't be allowed.
+ my $fields = {
+ title => "Report marked fixed - potholes",
+ text => "Thank you for your report. This pothole has been fixed.",
+ auto_response => 'on',
+ state => 'fixed - council',
+ "contacts[".$oxfordshirecontact->id."]" => 1,
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/templates/' . $oxfordshire->id . '/new', 'not redirected';
+ $mech->content_contains( 'Please correct the errors below' );
+ $mech->content_contains( 'There is already an auto-response template for this category/state.' );
+
+ is $oxfordshire->response_templates->count, 1, "Duplicate response template wasn't added";
+};
+
+subtest "auto-response templates that duplicate all categories can't be added" => sub {
+ $mech->delete_response_template($_) for $oxfordshire->response_templates;
+ $oxfordshire->response_templates->create({
+ title => "Report investigating - all cats",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 1,
+ state => 'fixed - council',
+ });
+ is $oxfordshire->response_templates->count, 1, "Initial response template was created";
+
+
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok( "/admin/templates/" . $oxfordshire->id . "/new" );
+
+ # There's already a response template for all categories and this state, so
+ # this new template won't be allowed.
+ my $fields = {
+ title => "Report investigating - single cat",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 'on',
+ state => 'fixed - council',
+ "contacts[".$oxfordshirecontact->id."]" => 1,
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/templates/' . $oxfordshire->id . '/new', 'not redirected';
+ $mech->content_contains( 'Please correct the errors below' );
+ $mech->content_contains( 'There is already an auto-response template for this category/state.' );
+
+
+ is $oxfordshire->response_templates->count, 1, "Duplicate response template wasn't added";
+};
+
+subtest "all-category auto-response templates that duplicate a single category can't be added" => sub {
+ $mech->delete_response_template($_) for $oxfordshire->response_templates;
+ my $template = $oxfordshire->response_templates->create({
+ title => "Report fixed - potholes",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 1,
+ state => 'fixed - council',
+ });
+ $template->contact_response_templates->find_or_create({
+ contact_id => $oxfordshirecontact->id,
+ });
+ is $oxfordshire->response_templates->count, 1, "Initial response template was created";
+
+
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok( "/admin/templates/" . $oxfordshire->id . "/new" );
+
+ # This response template is implicitly for all categories, but there's
+ # already a template for a specific category in this state, so it won't be
+ # allowed.
+ my $fields = {
+ title => "Report marked fixed - all cats",
+ text => "Thank you for your report. This problem has been fixed.",
+ auto_response => 'on',
+ state => 'fixed - council',
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+ is $mech->uri->path, '/admin/templates/' . $oxfordshire->id . '/new', 'not redirected';
+ $mech->content_contains( 'Please correct the errors below' );
+ $mech->content_contains( 'There is already an auto-response template for this category/state.' );
+
+ is $oxfordshire->response_templates->count, 1, "Duplicate response template wasn't added";
+};
+
+
+
$mech->log_in_ok( $superuser->email );
subtest "response priorities can be added" => sub {
@@ -1674,8 +1776,8 @@ subtest "response priorities can be added" => sub {
};
$mech->submit_form_ok( { with_fields => $fields } );
- is $oxfordshire->response_priorities->count, 1, "Response template was added to body";
- is $oxfordshirecontact->response_priorities->count, 1, "Response template was added to contact";
+ is $oxfordshire->response_priorities->count, 1, "Response priority was added to body";
+ is $oxfordshirecontact->response_priorities->count, 1, "Response priority was added to contact";
};
subtest "response priorities can set to default" => sub {
@@ -1693,7 +1795,7 @@ subtest "response priorities can set to default" => sub {
$mech->submit_form_ok( { with_fields => $fields } );
is $oxfordshire->response_priorities->count, 1, "Still one response priority";
- is $oxfordshirecontact->response_priorities->count, 1, "Still one response template";
+ is $oxfordshirecontact->response_priorities->count, 1, "Still one response priority";
ok $oxfordshire->response_priorities->first->is_default, "Response priority set to default";
};
@@ -1710,8 +1812,8 @@ subtest "response priorities are limited by body" => sub {
name => "Bromley Cat 0",
} );
- is $bromley->response_priorities->count, 1, "Response template was added to Bromley";
- is $oxfordshire->response_priorities->count, 1, "Response template wasn't added to Oxfordshire";
+ is $bromley->response_priorities->count, 1, "Response priority was added to Bromley";
+ is $oxfordshire->response_priorities->count, 1, "Response priority wasn't added to Oxfordshire";
$mech->get_ok( "/admin/responsepriorities/" . $oxfordshire->id );
$mech->content_lacks( $bromleypriority->name );
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 9a8db4374..da427e505 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -20,11 +20,18 @@ my $user = FixMyStreet::DB->resultset('User')->find_or_create(
my %bodies = (
2237 => FixMyStreet::DB->resultset("Body")->create({ name => 'Oxfordshire' }),
- 2482 => FixMyStreet::DB->resultset("Body")->new({ id => 2482 }),
+ 2482 => FixMyStreet::DB->resultset("Body")->create({ name=> 'Bromley', id => 2482 }),
2651 => FixMyStreet::DB->resultset("Body")->new({ id => 2651 }),
);
$bodies{2237}->body_areas->create({ area_id => 2237 });
+my $response_template = $bodies{2482}->response_templates->create({
+ title => "investigating template",
+ text => "We are investigating this report.",
+ auto_response => 1,
+ state => "investigating"
+});
+
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests_updates>
<request_update>
@@ -157,6 +164,10 @@ for my $test (
end_state => 'confirmed',
},
+ # NB because we have an auto-response ResponseTemplate set up for
+ # the 'investigating' state, this test is also testing that the
+ # response template isn't used if the update XML has a non-empty
+ # <description>.
{
desc => 'investigating status changes problem status',
description => 'This is a note',
@@ -334,6 +345,18 @@ for my $test (
end_state => 'fixed - council',
},
{
+ desc => 'empty description triggers auto-response template',
+ description => 'We are investigating this report.',
+ xml_description => '',
+ external_id => 638344,
+ start_state => 'fixed - council',
+ comment_status => 'INVESTIGATING',
+ mark_fixed => 0,
+ mark_open => 0,
+ problem_state => 'investigating',
+ end_state => 'investigating',
+ },
+ {
desc => 'open status does not re-open hidden report',
description => 'This is a note',
external_id => 638344,
@@ -346,7 +369,7 @@ for my $test (
},
) {
subtest $test->{desc} => sub {
- my $local_requests_xml = setup_xml($problem->external_id, $problem->id, $test->{comment_status});
+ my $local_requests_xml = setup_xml($problem->external_id, $problem->id, $test->{comment_status}, $test->{xml_description});
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
$problem->lastupdate( DateTime->now()->subtract( days => 1 ) );
@@ -762,13 +785,14 @@ foreach my $test ( {
done_testing();
sub setup_xml {
- my ($id, $id_ext, $status) = @_;
+ my ($id, $id_ext, $status, $description) = @_;
my $xml = $requests_xml;
my $updated_datetime = sprintf( '<updated_datetime>%s</updated_datetime>', $dt );
$xml =~ s/UPDATED_DATETIME/$updated_datetime/;
$xml =~ s#<service_request_id>\d+</service_request_id>#<service_request_id>$id</service_request_id>#;
$xml =~ s#<service_request_id_ext>\d+</service_request_id_ext>#<service_request_id_ext>$id_ext</service_request_id_ext>#;
$xml =~ s#<status>\w+</status>#<status>$status</status># if $status;
+ $xml =~ s#<description>.+</description>#<description>$description</description># if defined $description;
return $xml;
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 04740a9e8..7d4f491c6 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -39,6 +39,15 @@ subtest 'check basic functionality' => sub {
my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
+
+ for my $test (
+ { code => "001", group => "sanitation" },
+ { code => "002", group => "street" },
+ { code => "003", group => "street" },
+ ) {
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1, email => $test->{code} } )->first;
+ is $contact->get_extra->{group}, $test->{group}, "Group set correctly";
+ }
};
subtest 'check non open311 contacts marked as deleted' => sub {