aboutsummaryrefslogtreecommitdiffstats
path: root/t/sendreport/open311.t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-08-26 15:05:30 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-08-26 15:05:30 +0100
commit0e45fa27e4bc857f61b71f6c121a61e08e54cb6a (patch)
tree7e83c50825819b60a9a73f16c4d4f0a4ff247650 /t/sendreport/open311.t
parentc1178ea85d1879d6533ac09e2a3c813441554b43 (diff)
parenta09c61c807d8d6b50227c9d8aa687f1eb22bad00 (diff)
Merge branch 'stevenage-open311'
Diffstat (limited to 't/sendreport/open311.t')
-rw-r--r--t/sendreport/open311.t50
1 files changed, 50 insertions, 0 deletions
diff --git a/t/sendreport/open311.t b/t/sendreport/open311.t
new file mode 100644
index 000000000..636faba31
--- /dev/null
+++ b/t/sendreport/open311.t
@@ -0,0 +1,50 @@
+use strict;
+use warnings;
+use Test::More;
+
+use CGI::Simple;
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+my $user = $mech->create_user_ok( 'eh@example.com' );
+my $body = $mech->create_body_ok( 2342, 'East Hertfordshire Council');
+my $contact = $mech->create_contact_ok( body_id => $body->id, category => 'Potholes', email => 'POT' );
+$contact->set_extra_fields(
+ { code => 'easting', datatype => 'number' },
+ { code => 'northing', datatype => 'number' },
+ { code => 'fixmystreet_id', datatype => 'number' },
+);
+$contact->update;
+
+my ($report) = $mech->create_problems_for_body( 1, $body->id, 'Test', {
+ cobrand => 'fixmystreet',
+ category => 'Potholes',
+ user => $user,
+});
+
+subtest 'testing Open311 behaviour', sub {
+ $body->update( { send_method => 'Open311', endpoint => 'http://endpoint.example.com', jurisdiction => 'FMS', api_key => 'test' } );
+ my $test_data;
+ FixMyStreet::override_config {
+ SEND_REPORTS_ON_STAGING => 1,
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ }, sub {
+ $test_data = FixMyStreet::DB->resultset('Problem')->send_reports();
+ };
+ $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[easting]'), 529025, 'Request had easting';
+ is $c->param('attribute[northing]'), 179716, 'Request had northing';
+ is $c->param('attribute[fixmystreet_id]'), $report->id, 'Request had correct ID';
+ is $c->param('jurisdiction_id'), 'FMS', 'Request had correct jurisdiction';
+};
+
+# Clean up
+$mech->delete_user($user);
+$mech->delete_body($body);
+done_testing();