aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/Mock/MapIt.pm1
-rw-r--r--t/Mock/Tilma.pm2
-rw-r--r--t/app/model/problem.t65
-rw-r--r--t/cobrand/bristol.t8
-rw-r--r--t/cobrand/tfl.t28
-rw-r--r--t/open311/getupdates.t31
6 files changed, 82 insertions, 53 deletions
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm
index ed95e71fc..760e0ba52 100644
--- a/t/Mock/MapIt.pm
+++ b/t/Mock/MapIt.pm
@@ -45,6 +45,7 @@ my @PLACES = (
[ '?', 52.238827, -0.894970, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ],
[ '?', 52.23025, -1.015826, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ],
[ 'E8 1DY', 51.552267, -0.063316, 2508, 'Hackney Borough Council', 'LBO' ],
+ [ 'E8 2DY', 51.552287, -0.063326, 2508, 'Hackney Council', 'LBO' ],
[ 'TW7 5JN', 51.482286, -0.328163, 2483, 'Hounslow Borough Council', 'LBO' ],
[ '?', 51.48111, -0.327219, 2483, 'Hounslow Borough Council', 'LBO' ],
[ '?', 51.482045, -0.327219, 2483, 'Hounslow Borough Council', 'LBO' ],
diff --git a/t/Mock/Tilma.pm b/t/Mock/Tilma.pm
index 7542b1f5e..b7ef2be2f 100644
--- a/t/Mock/Tilma.pm
+++ b/t/Mock/Tilma.pm
@@ -28,7 +28,7 @@ sub dispatch_request {
sub (GET + /mapserver/tfl + ?*) {
my ($self, $args) = @_;
my $features = [];
- if ($args->{Filter} =~ /540512,169141/) {
+ if ($args->{Filter} =~ /540512,169141|534371,185488/) {
$features = [
{ type => "Feature", properties => { HA_ID => "19" }, geometry => { type => "Polygon", coordinates => [ [
[ 539408.94, 170607.58 ],
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 661a8827f..be949054b 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -2,6 +2,7 @@ use FixMyStreet::TestMech;
use FixMyStreet;
use FixMyStreet::DB;
use FixMyStreet::Script::Reports;
+use Open311::GetUpdates;
use Sub::Override;
my $problem_rs = FixMyStreet::DB->resultset('Problem');
@@ -133,6 +134,7 @@ $problem->anonymous(1);
$problem->insert;
my $tz_local = DateTime::TimeZone->new( name => 'local' );
+my $comment_time = DateTime->now->set_time_zone( $tz_local );
my $body = FixMyStreet::DB->resultset('Body')->new({
name => 'Edinburgh City Council'
@@ -140,52 +142,32 @@ my $body = FixMyStreet::DB->resultset('Body')->new({
for my $test (
{
- desc => 'request older than problem ignored',
- lastupdate => '',
+ desc => 'request after problem created',
request => {
- updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local )->subtract( days => 2 ) ),
- },
- created => 0,
- },
- {
- desc => 'request newer than problem created',
- lastupdate => '',
- request => {
- updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local ) ),
status => 'open',
- status_notes => 'this is an update from the council',
+ comment_time => $comment_time,
+ description => 'this is an update from the council',
},
- created => 1,
state => 'confirmed',
- mark_fixed => 0,
- mark_open => 0,
},
{
desc => 'update with state of closed fixes problem',
- lastupdate => '',
request => {
- updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local ) ),
+ comment_time => $comment_time,
status => 'closed',
- status_notes => 'the council have fixed this',
+ description => 'the council have fixed this',
},
- created => 1,
- state => 'fixed',
- mark_fixed => 1,
- mark_open => 0,
+ state => 'fixed - council',
},
{
- desc => 'update with state of open leaves problem as fixed',
- lastupdate => '',
+ desc => 'update with state of open reopens problem',
request => {
- updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local ) ),
+ comment_time => $comment_time,
status => 'open',
- status_notes => 'the council do not think this is fixed',
+ description => 'the council do not think this is fixed',
},
- created => 1,
- start_state => 'fixed',
- state => 'fixed',
- mark_fixed => 0,
- mark_open => 0,
+ start_state => 'fixed - council',
+ state => 'confirmed',
},
) {
subtest $test->{desc} => sub {
@@ -197,23 +179,20 @@ for my $test (
$problem->update;
my $w3c = DateTime::Format::W3CDTF->new();
- my $ret = $problem->update_from_open311_service_request( $test->{request}, $body, $user );
- is $ret, $test->{created}, 'return value';
-
- return unless $test->{created};
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1 );
+ my $updates = Open311::GetUpdates->new(
+ current_open311 => $o,
+ current_body => $body,
+ system_user => $user,
+ );
+ my $update = $updates->process_update($test->{request}, $problem);
$problem->discard_changes;
- is $problem->lastupdate, $w3c->parse_datetime($test->{request}->{updated_datetime}), 'lastupdate time';
-
- my $update = $problem->comments->first;
+ is $problem->lastupdate, $test->{request}->{comment_time}, 'lastupdate time';
ok $update, 'updated created';
-
is $problem->state, $test->{state}, 'problem state';
-
- is $update->text, $test->{request}->{status_notes}, 'update text';
- is $update->mark_open, $test->{mark_open}, 'update mark_open flag';
- is $update->mark_fixed, $test->{mark_fixed}, 'update mark_fixed flag';
+ is $update->text, $test->{request}->{description}, 'update text';
};
}
diff --git a/t/cobrand/bristol.t b/t/cobrand/bristol.t
index d4770b6ee..eacb65ce9 100644
--- a/t/cobrand/bristol.t
+++ b/t/cobrand/bristol.t
@@ -14,6 +14,12 @@ my $open311_contact = $mech->create_contact_ok(
category => 'Street Lighting',
email => 'LIGHT',
);
+my $open311_edited_contact = $mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Flooding',
+ email => 'FLOOD',
+ send_method => '',
+);
my $email_contact = $mech->create_contact_ok(
body_id => $body->id,
category => 'Potholes',
@@ -38,6 +44,7 @@ subtest 'Only Open311 categories are shown on Bristol cobrand', sub {
}, sub {
$mech->get_ok("/report/new/ajax?latitude=51.494885&longitude=-2.602237");
$mech->content_contains($open311_contact->category);
+ $mech->content_contains($open311_edited_contact->category);
$mech->content_lacks($email_contact->category);
};
};
@@ -49,6 +56,7 @@ subtest 'All categories are shown on FMS cobrand', sub {
}, sub {
$mech->get_ok("/report/new/ajax?latitude=51.494885&longitude=-2.602237");
$mech->content_contains($open311_contact->category);
+ $mech->content_contains($open311_edited_contact->category);
$mech->content_contains($email_contact->category);
};
};
diff --git a/t/cobrand/tfl.t b/t/cobrand/tfl.t
index f8e0a11c8..cf1ec1c41 100644
--- a/t/cobrand/tfl.t
+++ b/t/cobrand/tfl.t
@@ -23,6 +23,10 @@ FixMyStreet::DB->resultset('BodyArea')->find_or_create({
area_id => 2457, # Epsom Ewell, outside London, for bus stop test
body_id => $body->id,
});
+FixMyStreet::DB->resultset('BodyArea')->find_or_create({
+ area_id => 2508, # Hackney
+ body_id => $body->id,
+});
my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1);
my $staffuser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $body, password => 'password');
$staffuser->user_body_permissions->create({
@@ -58,6 +62,13 @@ my $bromley_flytipping = $mech->create_contact_ok(
$bromley_flytipping->set_extra_metadata(group => [ 'Street cleaning' ]);
$bromley_flytipping->update;
+my $hackney = $mech->create_body_ok(2508, 'Hackney Council');
+$mech->create_contact_ok(
+ body_id => $hackney->id,
+ category => 'Abandoned Vehicle',
+ email => 'av-hackney@example.com',
+);
+
my $contact1 = $mech->create_contact_ok(
body_id => $body->id,
category => 'Bus stops',
@@ -748,7 +759,7 @@ subtest 'Test no questionnaire sending' => sub {
};
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'tfl', 'bromley', 'fixmystreet' ],
+ ALLOWED_COBRANDS => [ 'tfl', 'bromley', 'fixmystreet', 'hackney' ],
MAPIT_URL => 'http://mapit.uk/',
COBRAND_FEATURES => {
internal_ips => { tfl => [ '127.0.0.1' ] },
@@ -864,6 +875,21 @@ for my $test (
'Trees'
],
},
+ {
+ host => 'hackney.fixmystreet.com',
+ name => "test no hackney categories on red route",
+ lat => 51.552287,
+ lon => -0.063326,
+ expected => [
+ 'Bus stops',
+ 'Flooding',
+ 'Grit bins',
+ 'Pothole',
+ 'Timings',
+ 'Traffic lights',
+ 'Trees'
+ ],
+ },
) {
subtest $test->{name} . ' on ' . $test->{host} => sub {
$mech->host($test->{host});
diff --git a/t/open311/getupdates.t b/t/open311/getupdates.t
index 351f17f6f..c1e51d380 100644
--- a/t/open311/getupdates.t
+++ b/t/open311/getupdates.t
@@ -18,9 +18,6 @@ my $body = FixMyStreet::DB->resultset('Body')->new( {
name => 'Test Body',
} );
-my $updates = Open311::GetUpdates->new( system_user => $user );
-ok $updates, 'created object';
-
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests>
<request>
@@ -101,7 +98,12 @@ for my $test (
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } );
- ok $updates->update_reports( [ 638344 ], $o, $body ), 'Updated reports';
+ my $updates = Open311::GetUpdates->new(
+ system_user => $user,
+ current_open311 => $o,
+ current_body => $body,
+ );
+ $updates->update_reports( [ $problem ] );
my @parts = uri_split($o->test_uri_used);
is $parts[2], '/requests.xml', 'path matches';
my @qs = sort split '&', $parts[3];
@@ -179,7 +181,13 @@ subtest 'update with two requests' => sub {
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } );
- ok $updates->update_reports( [ 638344,638345 ], $o, $body ), 'Updated reports';
+ my $updates = Open311::GetUpdates->new(
+ system_user => $user,
+ current_open311 => $o,
+ current_body => $body,
+ );
+
+ $updates->update_reports( [ $problem, $problem2 ] );
my @parts = uri_split($o->test_uri_used);
is $parts[2], '/requests.xml', 'path matches';
my @qs = sort split '&', $parts[3];
@@ -227,7 +235,7 @@ my $problem3 = $problem_rs->create( {
external_id => 638346,
} );
-subtest 'test translation of auto-added comment from old-style Open311 update' => sub {
+subtest 'test auto-added comment from old-style Open311 update' => sub {
my $dt = sprintf( '<updated_datetime>%s</updated_datetime>', DateTime->now );
$requests_xml =~ s/UPDATED_DATETIME/$dt/;
@@ -236,7 +244,13 @@ subtest 'test translation of auto-added comment from old-style Open311 update' =
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fixamingata' ],
}, sub {
- ok $updates->update_reports( [ 638346 ], $o, $body ), 'Updated reports';
+ my $updates = Open311::GetUpdates->new(
+ system_user => $user,
+ current_open311 => $o,
+ current_body => $body,
+ blank_updates_permitted => 1,
+ );
+ $updates->update_reports( [ $problem3 ] );
};
my @parts = uri_split($o->test_uri_used);
is $parts[2], '/requests.xml', 'path matches';
@@ -244,7 +258,8 @@ subtest 'test translation of auto-added comment from old-style Open311 update' =
is_deeply(\@qs, [ 'jurisdiction_id=mysociety', 'service_request_id=638346' ], 'query string matches');
is $problem3->comments->count, 1, 'added a comment';
- is $problem3->comments->first->text, "Stängd av kommunen", 'correct comment text';
+ is $problem3->comments->first->problem_state, 'fixed - council';
+ is $problem3->comments->first->text, '', 'correct comment text';
};
END {