aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/cobrand/bristol.t66
-rw-r--r--t/cobrand/greenwich.t114
-rw-r--r--t/open311.t15
-rw-r--r--t/open311/populate-service-list.t27
4 files changed, 221 insertions, 1 deletions
diff --git a/t/cobrand/bristol.t b/t/cobrand/bristol.t
index b4b6ed4ac..b2b8cff13 100644
--- a/t/cobrand/bristol.t
+++ b/t/cobrand/bristol.t
@@ -1,6 +1,8 @@
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
+use Open311::PopulateServiceList;
+
# Create test data
my $body = $mech->create_body_ok( 2561, 'Bristol County Council', {
send_method => 'Open311',
@@ -41,4 +43,68 @@ subtest 'All categories are shown on FMS cobrand', sub {
};
};
+subtest 'check services override' => sub {
+ my $processor = Open311::PopulateServiceList->new();
+
+ my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
+<service_definition>
+ <service_code>LIGHT</service_code>
+ <attributes>
+ <attribute>
+ <variable>true</variable>
+ <code>easting</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <order>1</order>
+ <description>Easting</description>
+ </attribute>
+ <attribute>
+ <variable>true</variable>
+ <code>size</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <order>2</order>
+ <description>How big is the pothole</description>
+ </attribute>
+ </attributes>
+</service_definition>
+ ';
+
+ my $o = Open311->new(
+ jurisdiction => 'mysociety',
+ endpoint => 'http://example.com',
+ test_mode => 1,
+ test_get_returns => { 'services/LIGHT.xml' => $meta_xml }
+ );
+
+ $processor->_current_open311( $o );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'bristol' ],
+ }, sub {
+ $processor->_current_body( $body );
+ };
+ $processor->_current_service( { service_code => 'LIGHT' } );
+ $processor->_add_meta_to_contact( $open311_contact );
+
+ my $extra = [ {
+ automated => 'server_set',
+ variable => 'true',
+ code => 'easting',
+ datatype => 'string',
+ required => 'true',
+ order => 1,
+ description => 'Easting',
+ }, {
+ variable => 'true',
+ code => 'size',
+ datatype => 'string',
+ required => 'true',
+ order => 2,
+ description => 'How big is the pothole',
+ } ];
+
+ $open311_contact->discard_changes;
+ is_deeply $open311_contact->get_extra_fields, $extra, 'Easting has automated set';
+};
+
done_testing();
diff --git a/t/cobrand/greenwich.t b/t/cobrand/greenwich.t
new file mode 100644
index 000000000..e6aaca973
--- /dev/null
+++ b/t/cobrand/greenwich.t
@@ -0,0 +1,114 @@
+use CGI::Simple;
+use FixMyStreet::TestMech;
+use FixMyStreet::Script::Reports;
+use Open311::PopulateServiceList;
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $body = $mech->create_body_ok( 2493, 'Greenwich Council', {
+ send_method => 'Open311',
+ endpoint => 'endpoint',
+ api_key => 'key',
+ jurisdiction => 'greenwich',
+});
+
+my $contact = $mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Pothole',
+ email => 'HOLE',
+);
+
+my $user = $mech->create_user_ok( 'greenwich@example.com' );
+my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', {
+ category => 'Pothole',
+ cobrand => 'greenwich',
+ user => $user,
+});
+my $report = $reports[0];
+
+subtest 'check services override' => sub {
+ my $processor = Open311::PopulateServiceList->new();
+
+ my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
+<service_definition>
+ <service_code>HOLE</service_code>
+ <attributes>
+ <attribute>
+ <variable>true</variable>
+ <code>easting</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <order>1</order>
+ <description>Easting</description>
+ </attribute>
+ <attribute>
+ <variable>true</variable>
+ <code>size</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <order>2</order>
+ <description>How big is the pothole</description>
+ </attribute>
+ </attributes>
+</service_definition>
+ ';
+
+ my $o = Open311->new(
+ jurisdiction => 'mysociety',
+ endpoint => 'http://example.com',
+ test_mode => 1,
+ test_get_returns => { 'services/HOLE.xml' => $meta_xml }
+ );
+
+ $processor->_current_open311( $o );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'greenwich' ],
+ }, sub {
+ $processor->_current_body( $body );
+ };
+ $processor->_current_service( { service_code => 'HOLE' } );
+ $processor->_add_meta_to_contact( $contact );
+
+ my $extra = [ {
+ automated => 'server_set',
+ variable => 'true',
+ code => 'easting',
+ datatype => 'string',
+ required => 'true',
+ order => 1,
+ description => 'Easting',
+ }, {
+ variable => 'true',
+ code => 'size',
+ datatype => 'string',
+ required => 'true',
+ order => 2,
+ description => 'How big is the pothole',
+ } ];
+
+ $contact->discard_changes;
+ is_deeply $contact->get_extra_fields, $extra, 'Easting has automated set';
+};
+
+subtest 'testing special Open311 behaviour', sub {
+ my $test_data;
+ FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1 },
+ ALLOWED_COBRANDS => [ 'greenwich' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $test_data = FixMyStreet::Script::Reports::send();
+ };
+ $report->discard_changes;
+ ok $report->whensent, 'Report marked as sent';
+ is $report->send_method_used, 'Open311', 'Report sent via Open311';
+ is $report->external_id, 248, 'Report has right external ID';
+
+ my $req = $test_data->{test_req_used};
+ my $c = CGI::Simple->new($req->content);
+ is $c->param('attribute[external_id]'), $report->id, 'Request had correct ID';
+ is $c->param('attribute[easting]'), 529025, 'Request had correct easting';
+};
+
+done_testing();
+
diff --git a/t/open311.t b/t/open311.t
index ef52eb538..f2fdefda6 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -261,6 +261,21 @@ for my $test (
};
}
+subtest 'test always_send_email' => sub {
+ my $email = $user->email;
+ $user->email(undef);
+ my $extra = { url => 'http://example.com/report/1', };
+
+ my $results = make_service_req(
+ $problem, $extra, $problem->category,
+ '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>',
+ { always_send_email => 1 }
+ );
+ my $c = CGI::Simple->new( $results->{req}->content );
+
+ is $c->param('email'), 'do-not-reply@example.org', 'correct email';
+ $user->email($email);
+};
my $comment = FixMyStreet::DB->resultset('Comment')->new( {
id => 38362,
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 4d70dfebc..ff4c4cf9d 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -584,6 +584,15 @@ subtest 'check Bromley skip code' => sub {
<order>1</order>
<description>Type of bin</description>
</attribute>
+ <attribute>
+ <variable>true</variable>
+ <code>easting</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <datatype_description>String</datatype_description>
+ <order>1</order>
+ <description>Easting</description>
+ </attribute>
</attributes>
</service_definition>
';
@@ -626,6 +635,15 @@ subtest 'check Bromley skip code' => sub {
order => 1,
description => 'Type of bin'
}, {
+ automated => 'server_set',
+ variable => 'true',
+ code => 'easting',
+ datatype => 'string',
+ required => 'true',
+ datatype_description => 'String',
+ order => 1,
+ description => 'Easting',
+ }, {
automated => 'hidden_field',
variable => 'true',
code => 'prow_reference',
@@ -671,7 +689,14 @@ subtest 'check Bromley skip code' => sub {
datatype_description => 'Type of bin',
order => 1,
description => 'Type of bin'
-
+ }, {
+ variable => 'true',
+ code => 'easting',
+ datatype => 'string',
+ required => 'true',
+ datatype_description => 'String',
+ order => 1,
+ description => 'Easting',
},
];