aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-05-04 18:18:27 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-05-16 17:15:27 +0100
commit61eb613ddc31943e9d6504050c0e96f91340f752 (patch)
tree7e0ea449a00a21ff977f211fc4812a414386db5a /t
parent16b4d05dac360a1c81d4595b0e06bd9468f7e4a1 (diff)
[Oxfordshire] Send RDI reports by email.
Diffstat (limited to 't')
-rw-r--r--t/Mock/MapIt.pm14
-rw-r--r--t/cobrand/oxfordshire.t62
2 files changed, 70 insertions, 6 deletions
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index 43d44d519..0b355983b 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -31,6 +31,7 @@ my @PLACES = (
[ '?', 50.78301, -0.646929 ],
[ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ],
[ 'WS1 4NH', 52.563074, -1.991032, 2535, 'Sandwell Borough Council', 'MTD' ],
+ [ 'OX28 4DS', 51.784721, -1.494453 ],
);
sub dispatch_request {
@@ -105,6 +106,19 @@ sub dispatch_request {
my ($self, $area) = @_;
return [ 200, [ 'Content-Type' => 'application/json' ], [ '"AB12 1AA"' ] ];
},
+
+ sub (GET + /nearest/**.*) {
+ my ($self, $point) = @_;
+ foreach (@PLACES) {
+ if ($point eq "4326/$_->[2],$_->[1]") {
+ return $self->output({
+ postcode => { wgs84_lat => $_->[1], wgs84_lon => $_->[2], postcode => $_->[0] },
+ });
+ }
+ }
+ return $self->output({});
+ },
+
}
LWP::Protocol::PSGI->register(t::Mock::MapIt->to_psgi_app, host => 'mapit.uk');
diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t
index b0fad3b56..4849554ea 100644
--- a/t/cobrand/oxfordshire.t
+++ b/t/cobrand/oxfordshire.t
@@ -5,12 +5,15 @@ use Test::More;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
+my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237);
+
subtest 'check /ajax defaults to open reports only' => sub {
my $categories = [ 'Bridges', 'Fences', 'Manhole' ];
my $params = {
postcode => 'OX28 4DS',
- latitude => 51.7847208192,
- longitude => -1.49445264029,
+ cobrand => 'oxfordshire',
+ latitude => 51.784721,
+ longitude => -1.494453,
};
my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01)
. ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01);
@@ -23,7 +26,7 @@ subtest 'check /ajax defaults to open reports only' => sub {
category => $category,
state => $state,
);
- $mech->create_problems_for_body( 1, 2237, 'Around page', \%report_params );
+ $mech->create_problems_for_body( 1, $oxon->id, 'Around page', \%report_params );
}
}
@@ -46,6 +49,8 @@ subtest 'check /ajax defaults to open reports only' => sub {
};
my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1);
+my $inspector = $mech->create_user_ok('inspector@example.com', name => 'Inspector');
+$inspector->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' });
subtest 'Exor RDI download appears on Oxfordshire cobrand admin' => sub {
FixMyStreet::override_config {
@@ -67,7 +72,52 @@ subtest 'Exor RDI download doesn’t appear outside of Oxfordshire cobrand admin
}
};
+subtest 'Exor file looks okay' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'oxfordshire' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->log_in_ok( $superuser->email );
+ $mech->get_ok('/admin/exordefects');
+ $mech->submit_form_ok( { with_fields => {
+ start_date => '05/05/2017',
+ end_date => '05/05/2017',
+ user_id => $inspector->id,
+ } }, 'submit download');
+ $mech->content_contains("No inspections by that inspector in the selected date range");
+ my $problem = FixMyStreet::DB->resultset('Problem')->first;
+ $problem->update({ state => 'action scheduled', external_id => 123 });
+ FixMyStreet::DB->resultset('AdminLog')->create({
+ admin_user => $inspector->name,
+ user => $inspector,
+ object_type => 'problem',
+ action => 'inspected',
+ object_id => $problem->id,
+ whenedited => DateTime->new(year => 2017, month => 5, day => 5, hour => 12),
+ });
+ $mech->submit_form_ok( { with_fields => {
+ start_date => '05/05/2017',
+ end_date => '05/05/2017',
+ user_id => $inspector->id,
+ } }, 'submit download');
+ (my $rdi = $mech->content) =~ s/\r\n/\n/g;
+ is $rdi, <<EOF, "RDI file matches expected";
+"1,1.8,1.0.0.0,ENHN,"
+"G,1989169,,,XX,170505,0700,D,INS,N,,,,"
+"H,MC"
+"I,MC,,001,"434970E 209683N Nearest postcode: OX28 4DS.",1200,,,,,,,,"TM none","123 ""
+"J,SFP2,2,,,434970,209683,,,,,"
+"M,resolve,,,/CMC,,"
+"P,0,999999"
+"X,1,1,1,1,0,0,0,1,0,1,0,0,0"
+EOF
+ }
+};
+
# Clean up
-$mech->delete_user( $superuser );
-$mech->delete_problems_for_body( 2237 );
-done_testing();
+END {
+ $mech->delete_user( $superuser );
+ $mech->delete_user( $inspector );
+ $mech->delete_problems_for_body( $oxon->id );
+ done_testing();
+}