aboutsummaryrefslogtreecommitdiffstats
path: root/t/sendreport
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-02-14 17:40:56 +1300
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-03-15 13:18:11 +0000
commit4e31d58ac2ac23228d2d6c561901547d20f57ffb (patch)
treedf228c7cbe9e86ee37dbb2f2657b92df198bb362 /t/sendreport
parentf1c8da3ed21adc1c64e8276edc116af200b8883f (diff)
send multiple photos over open311
Per cobrand configurable option to send multiple photos over open311 instead of just a single one. Does this by sending multiple media_url parameters in the POST body. The default remains to send the first photo associated with a report.
Diffstat (limited to 't/sendreport')
-rw-r--r--t/sendreport/open311.t81
1 files changed, 81 insertions, 0 deletions
diff --git a/t/sendreport/open311.t b/t/sendreport/open311.t
index 1eb5535aa..23096aaac 100644
--- a/t/sendreport/open311.t
+++ b/t/sendreport/open311.t
@@ -1,4 +1,16 @@
+package FixMyStreet::Cobrand::Tester;
+
+use parent 'FixMyStreet::Cobrand::FixMyStreet';
+
+sub open311_config {
+ my ($self, $row, $h, $params) = @_;
+ $params->{multi_photos} = 1;
+}
+
+package main;
+
use CGI::Simple;
+use Path::Tiny;
use FixMyStreet::Script::Reports;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -41,4 +53,73 @@ subtest 'testing Open311 behaviour', sub {
is $c->param('jurisdiction_id'), 'FMS', 'Request had correct jurisdiction';
};
+my ($photo_report) = $mech->create_problems_for_body( 1, $body->id, 'Test', {
+ cobrand => 'fixmystreet',
+ category => 'Potholes',
+ user => $user,
+});
+my $sample_file = path(__FILE__)->parent->parent->child("app/controller/sample.jpg");
+my $UPLOAD_DIR = File::Temp->newdir();
+my @files = map { $_ x 40 . ".jpeg" } (1..3);
+$sample_file->copy(path($UPLOAD_DIR, $_)) for @files;
+$photo_report->photo(join(',', @files));
+$photo_report->update;
+
+subtest 'test report with multiple photos only sends one', sub {
+ $body->update( { send_method => 'Open311', endpoint => 'http://endpoint.example.com', jurisdiction => 'FMS', api_key => 'test' } );
+ my $test_data;
+
+ FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1 },
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ }, sub {
+ $test_data = FixMyStreet::Script::Reports::send();
+ };
+ $photo_report->discard_changes;
+ ok $photo_report->whensent, 'Report marked as sent';
+ is $photo_report->send_method_used, 'Open311', 'Report sent via Open311';
+ is $photo_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]'), $photo_report->id, 'Request had correct ID';
+ is $c->param('jurisdiction_id'), 'FMS', 'Request had correct jurisdiction';
+ my @media = $c->param('media_url');
+ is_deeply \@media, [
+ 'http://www.example.org/photo/' . $photo_report->id .'.0.full.jpeg?11111111'
+ ], 'One photo in media_url';
+};
+
+$photo_report->whensent(undef);
+$photo_report->cobrand('tester');
+$photo_report->send_method_used('');
+$photo_report->update();
+
+subtest 'test sending multiple photos', sub {
+ $body->update( { send_method => 'Open311', endpoint => 'http://endpoint.example.com', jurisdiction => 'FMS', api_key => 'test' } );
+ my $test_data;
+
+ FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1 },
+ ALLOWED_COBRANDS => [ 'tester' ],
+ }, sub {
+ $test_data = FixMyStreet::Script::Reports::send();
+ };
+ $photo_report->discard_changes;
+ ok $photo_report->whensent, 'Report marked as sent';
+ is $photo_report->send_method_used, 'Open311', 'Report sent via Open311';
+ is $photo_report->external_id, 248, 'Report has right external ID';
+
+ my $req = $test_data->{test_req_used};
+ my $c = CGI::Simple->new($req->content);
+ my @media = $c->param('media_url');
+ is_deeply \@media, [
+ 'http://www.example.org/photo/' . $photo_report->id .'.0.full.jpeg?11111111',
+ 'http://www.example.org/photo/' . $photo_report->id .'.1.full.jpeg?22222222',
+ 'http://www.example.org/photo/' . $photo_report->id .'.2.full.jpeg?33333333'
+ ], 'Multiple photos in media_url';
+};
+
done_testing();