aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/controller/admin.t116
-rw-r--r--t/app/controller/alert_new.t6
-rw-r--r--t/app/controller/around.t2
-rw-r--r--t/app/controller/dashboard.t14
-rw-r--r--t/app/controller/index.t4
-rw-r--r--t/app/controller/json.t8
-rw-r--r--t/app/controller/questionnaire.t2
-rw-r--r--t/app/controller/report_display.t114
-rw-r--r--t/app/controller/report_interest_count.t40
-rw-r--r--t/app/controller/report_new.t88
-rw-r--r--t/app/controller/report_new_open311.t16
-rw-r--r--t/app/controller/report_updates.t26
-rw-r--r--t/app/controller/reports.t13
-rw-r--r--t/app/controller/rss.t64
-rw-r--r--t/app/model/alert_type.t8
-rw-r--r--t/app/model/problem.t78
-rw-r--r--t/app/sendreport/email.t13
-rw-r--r--t/cobrand/closest.t2
-rw-r--r--t/cobrand/get_body_sender.t38
-rw-r--r--t/cobrand/get_council_sender.t30
-rw-r--r--t/cobrand/zurich.t168
-rw-r--r--t/map/tilma/original.t2
-rw-r--r--t/open311/getservicerequestupdates.t18
-rw-r--r--t/open311/getupdates.t198
-rw-r--r--t/open311/populate-service-list.t114
25 files changed, 686 insertions, 496 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 9ec15ec21..8963e417d 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -45,7 +45,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Report to Edit',
@@ -84,7 +84,7 @@ subtest 'check summary counts' => sub {
my $problem_count = $problems->count;
$problems->update( { cobrand => '' } );
- FixMyStreet::App->model('DB::Problem')->search( { council => 2489 } )->update( { council => 1 } );
+ FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 2489 } )->update( { bodies_str => 1 } );
my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_new( { problem => $report, });
$q->whensent( \'ms_current_timestamp()' );
@@ -118,7 +118,7 @@ subtest 'check summary counts' => sub {
my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/;
my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/;
- $report->council(2489);
+ $report->bodies_str(2489);
$report->cobrand('barnet');
$report->update;
@@ -131,7 +131,7 @@ subtest 'check summary counts' => sub {
$mech->content_contains( ($num_alerts+1) . " confirmed alerts" );
$mech->content_contains( ($num_qs+1) . " questionnaires sent" );
- $report->council(2504);
+ $report->bodies_str(2504);
$report->cobrand('');
$report->update;
@@ -139,28 +139,30 @@ subtest 'check summary counts' => sub {
$alert->update;
}
- FixMyStreet::App->model('DB::Problem')->search( { council => 1 } )->update( { council => 2489 } );
+ FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 1 } )->update( { bodies_str => 2489 } );
ok $mech->host('fixmystreet.com');
};
my $host = FixMyStreet->config('BASE_URL');
-$mech->get_ok('/admin/council_contacts/2650');
+
+my $body = $mech->create_body_ok(2650, 'Aberdeen City Council');
+$mech->get_ok('/admin/body/2650');
$mech->content_contains('Aberdeen City Council');
$mech->content_like(qr{AB\d\d});
$mech->content_contains("$host/around");
subtest 'check contact creation' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->search(
- { area_id => 2650, category => [ 'test category', 'test/category' ] }
+ { body_id => 2650, category => [ 'test category', 'test/category' ] }
);
$contact->delete_all;
my $history = FixMyStreet::App->model('DB::ContactsHistory')->search(
- { area_id => 2650, category => [ 'test category', 'test/category' ] }
+ { body_id => 2650, category => [ 'test category', 'test/category' ] }
);
$history->delete_all;
- $mech->get_ok('/admin/council_contacts/2650');
+ $mech->get_ok('/admin/body/2650');
$mech->submit_form_ok( { with_fields => {
category => 'test category',
@@ -190,12 +192,12 @@ subtest 'check contact creation' => sub {
note => 'test/note',
non_public => 'on',
} } );
- $mech->get_ok('/admin/council_edit/2650/test/category');
+ $mech->get_ok('/admin/body_edit/2650/test/category');
};
subtest 'check contact editing' => sub {
- $mech->get_ok('/admin/council_edit/2650/test%20category');
+ $mech->get_ok('/admin/body_edit/2650/test%20category');
$mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
@@ -216,31 +218,29 @@ subtest 'check contact editing' => sub {
$mech->content_contains( '<td>Non Public' );
- $mech->get_ok('/admin/council_edit/2650/test%20category');
+ $mech->get_ok('/admin/body_edit/2650/test%20category');
$mech->content_contains( '<td><strong>test2@example.com' );
};
subtest 'check contact updating' => sub {
- $mech->get_ok('/admin/council_edit/2650/test%20category');
+ $mech->get_ok('/admin/body_edit/2650/test%20category');
$mech->content_like(qr{test2\@example.com</strong>[^<]*</td>[^<]*<td>No}s);
- $mech->get_ok('/admin/council_contacts/2650');
+ $mech->get_ok('/admin/body/2650');
$mech->form_number( 1 );
$mech->tick( 'confirmed', 'test category' );
$mech->submit_form_ok({form_number => 1});
$mech->content_like(qr'test2@example.com</td>[^<]*<td>Yes's);
- $mech->get_ok('/admin/council_edit/2650/test%20category');
+ $mech->get_ok('/admin/body_edit/2650/test%20category');
$mech->content_like(qr{test2\@example.com[^<]*</td>[^<]*<td><strong>Yes}s);
};
-my $open311 =
- FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } );
-$open311->delete if $open311;
+$body->update({ send_method => undef });
subtest 'check open311 configuring' => sub {
- $mech->get_ok('/admin/council_contacts/2650/');
+ $mech->get_ok('/admin/body/2650');
$mech->content_lacks('Council contacts configured via Open311');
$mech->form_number(3);
@@ -258,11 +258,7 @@ subtest 'check open311 configuring' => sub {
$mech->content_contains('Council contacts configured via Open311');
$mech->content_contains('Configuration updated - contacts will be generated automatically later');
- $open311 =
- FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } );
-
- is $open311->count, 1, 'only one configuration';
- my $conf = $open311->first;
+ my $conf = FixMyStreet::App->model('DB::Body')->find( 2650 );
is $conf->endpoint, 'http://example.com/open311', 'endpoint configured';
is $conf->api_key, 'api key', 'api key configured';
is $conf->jurisdiction, 'mySociety', 'jurisdiction configures';
@@ -282,18 +278,14 @@ subtest 'check open311 configuring' => sub {
$mech->content_contains('Configuration updated');
- $open311 =
- FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } );
-
- is $open311->count, 1, 'only one configuration';
- $conf = $open311->first;
+ $conf = FixMyStreet::App->model('DB::Body')->find( 2650 );
is $conf->endpoint, 'http://example.org/open311', 'endpoint updated';
is $conf->api_key, 'new api key', 'api key updated';
is $conf->jurisdiction, 'open311', 'jurisdiction configures';
};
subtest 'check text output' => sub {
- $mech->get_ok('/admin/council_contacts/2650?text=1');
+ $mech->get_ok('/admin/body/2650?text=1');
is $mech->content_type, 'text/plain';
$mech->content_contains('test category');
};
@@ -845,6 +837,8 @@ for my $test (
};
}
+$mech->create_body_ok(2504, 'Westminster City Council');
+
for my $test (
{
desc => 'user is problem owner',
@@ -853,17 +847,17 @@ for my $test (
update_fixed => 0,
update_reopen => 0,
update_state => undef,
- user_council => undef,
+ user_body => undef,
content => 'user is problem owner',
},
{
- desc => 'user is council user',
+ desc => 'user is body user',
problem_user => $user,
update_user => $user2,
update_fixed => 0,
update_reopen => 0,
update_state => undef,
- user_council => 2504,
+ user_body => 2504,
content => 'user is from same council as problem - 2504',
},
{
@@ -873,7 +867,7 @@ for my $test (
update_fixed => 0,
update_reopen => 0,
update_state => 'planned',
- user_council => 2504,
+ user_body => 2504,
content => 'Update changed problem state to planned',
},
{
@@ -883,7 +877,7 @@ for my $test (
update_fixed => 1,
update_reopen => 0,
update_state => undef,
- user_council => undef,
+ user_body => undef,
content => 'Update marked problem as fixed',
},
{
@@ -893,7 +887,7 @@ for my $test (
update_fixed => 0,
update_reopen => 1,
update_state => undef,
- user_council => undef,
+ user_body => undef,
content => 'Update reopened problem',
},
) {
@@ -907,7 +901,7 @@ for my $test (
$update->mark_open( $test->{update_reopen} );
$update->update;
- $test->{update_user}->from_council( $test->{user_council} );
+ $test->{update_user}->from_body( $test->{user_body} );
$test->{update_user}->update;
$mech->get_ok('/admin/update_edit/' . $update->id );
@@ -1033,14 +1027,14 @@ subtest 'report search' => sub {
$update->user($report->user);
$update->update;
- $mech->get_ok('/admin/search_reports');
- $mech->get_ok('/admin/search_reports?search=' . $report->id );
+ $mech->get_ok('/admin/reports');
+ $mech->get_ok('/admin/reports?search=' . $report->id );
$mech->content_contains( $report->title );
my $r_id = $report->id;
$mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id</a>} );
- $mech->get_ok('/admin/search_reports?search=' . $report->user->email);
+ $mech->get_ok('/admin/reports?search=' . $report->user->email);
my $u_id = $update->id;
$mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id</a>} );
@@ -1049,25 +1043,25 @@ subtest 'report search' => sub {
$update->state('hidden');
$update->update;
- $mech->get_ok('/admin/search_reports?search=' . $report->user->email);
+ $mech->get_ok('/admin/reports?search=' . $report->user->email);
$mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $u_id \s* </td>}xs );
$report->state('hidden');
$report->update;
- $mech->get_ok('/admin/search_reports?search=' . $report->user->email);
+ $mech->get_ok('/admin/reports?search=' . $report->user->email);
$mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $r_id \s* </td>}xs );
$report->state('fixed - user');
$report->update;
- $mech->get_ok('/admin/search_reports?search=' . $report->user->email);
+ $mech->get_ok('/admin/reports?search=' . $report->user->email);
$mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id</a>} );
};
subtest 'search abuse' => sub {
- $mech->get_ok( '/admin/search_users?search=example' );
- $mech->content_like(qr/test4\@example.com.*\n.*\n.*Email in abuse table/);
+ $mech->get_ok( '/admin/users?search=example' );
+ $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>\(Email in abuse table});
};
subtest 'show flagged entries' => sub {
@@ -1077,27 +1071,29 @@ subtest 'show flagged entries' => sub {
$user->flagged( 1 );
$user->update;
- $mech->get_ok('/admin/list_flagged');
+ $mech->get_ok('/admin/flagged');
$mech->content_contains( $report->title );
$mech->content_contains( $user->email );
};
+$mech->create_body_ok(2509, 'Haringey Borough Council');
+
subtest 'user search' => sub {
- $mech->get_ok('/admin/search_users');
- $mech->get_ok('/admin/search_users?search=' . $user->name);
+ $mech->get_ok('/admin/users');
+ $mech->get_ok('/admin/users?search=' . $user->name);
$mech->content_contains( $user->name);
my $u_id = $user->id;
$mech->content_like( qr{user_edit/$u_id">Edit</a>} );
- $mech->get_ok('/admin/search_users?search=' . $user->email);
+ $mech->get_ok('/admin/users?search=' . $user->email);
$mech->content_like( qr{user_edit/$u_id">Edit</a>} );
- $user->from_council(2509);
+ $user->from_body(2509);
$user->update;
- $mech->get_ok('/admin/search_users?search=2509' );
- $mech->content_contains(2509);
+ $mech->get_ok('/admin/users?search=2509' );
+ $mech->content_contains('Haringey');
};
$log_entries = FixMyStreet::App->model('DB::AdminLog')->search(
@@ -1115,13 +1111,15 @@ is $log_entries->count, 0, 'no admin log entries';
$user->flagged( 0 );
$user->update;
+$mech->create_body_ok(2607, 'Southend-on-Sea Borough Council');
+
for my $test (
{
desc => 'edit user name',
fields => {
name => 'Test User',
email => 'test@example.com',
- council => 2509,
+ body => 2509,
flagged => undef,
},
changes => {
@@ -1135,7 +1133,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'test@example.com',
- council => 2509,
+ body => 2509,
flagged => undef,
},
changes => {
@@ -1145,15 +1143,15 @@ for my $test (
log_entries => [qw/edit edit/],
},
{
- desc => 'edit user council',
+ desc => 'edit user body',
fields => {
name => 'Changed User',
email => 'changed@example.com',
- council => 2509,
+ body => 2509,
flagged => undef,
},
changes => {
- council => 2607,
+ body => 2607,
},
log_count => 3,
log_entries => [qw/edit edit edit/],
@@ -1163,7 +1161,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'changed@example.com',
- council => 2607,
+ body => 2607,
flagged => undef,
},
changes => {
@@ -1177,7 +1175,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'changed@example.com',
- council => 2607,
+ body => 2607,
flagged => 'on',
},
changes => {
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index c849b9485..6f130279b 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -382,7 +382,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
my $report_time = '2011-03-01 12:00:00';
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
postcode => 'EH1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Testing',
@@ -532,7 +532,7 @@ for my $test (
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
postcode => 'EH1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Alert test for non public reports',
@@ -590,7 +590,7 @@ subtest 'check new updates alerts for non public reports only go to report owner
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
postcode => 'EH1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Alert test for non public reports',
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index d973543ce..0f01a9ea9 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -90,7 +90,7 @@ subtest 'check non public reports are not displayed on around page' => sub {
longitude => -3.17492254484,
};
my @edinburgh_problems =
- $mech->create_problems_for_council( 5, 2651, 'Around page', $params );
+ $mech->create_problems_for_body( 5, 2651, 'Around page', $params );
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } },
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t
index 25e144464..091335040 100644
--- a/t/app/controller/dashboard.t
+++ b/t/app/controller/dashboard.t
@@ -12,6 +12,8 @@ my $test_pass = 'password';
my $test_council = 2651;
my $test_ward = 20723;
+$mech->create_body_ok($test_council, 'City of Edinburgh Council');
+
$mech->delete_user( $test_user );
my $user = FixMyStreet::App->model('DB::User')->create( {
email => $test_user,
@@ -33,7 +35,7 @@ $mech->submit_form(
is $mech->status, '404', 'If not council user get 404';
-$user->from_council( $test_council );
+$user->from_body( $test_council );
$user->update;
$mech->log_out_ok;
@@ -44,7 +46,7 @@ $mech->submit_form_ok( {
$mech->content_contains( 'City of Edinburgh' );
-FixMyStreet::App->model('DB::Contact')->search( { area_id => $test_council } )
+FixMyStreet::App->model('DB::Contact')->search( { body_id => $test_council } )
->delete;
delete_problems();
@@ -53,7 +55,7 @@ my @cats = qw( Grafitti Litter Potholes Other );
for my $contact ( @cats ) {
FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => $test_council,
+ body_id => $test_council,
category => $contact,
email => "$contact\@example.org",
confirmed => 1,
@@ -608,7 +610,7 @@ sub make_problem {
confirmed => $args->{conf_dt},
whensent => $args->{conf_dt},
lastupdate => $args->{mark_dt} || $args->{conf_dt},
- council => $test_council,
+ bodies_str => $test_council,
postcode => 'EH99 1SP',
latitude => '51',
longitude => '1',
@@ -662,10 +664,10 @@ sub check_report_counts {
sub delete_problems {
FixMyStreet::App->model('DB::Comment')
- ->search( { 'problem.council' => $test_council }, { join => 'problem' } )
+ ->search( { 'problem.bodies_str' => $test_council }, { join => 'problem' } )
->delete;
FixMyStreet::App->model('DB::Problem')
- ->search( { council => $test_council } )->delete();
+ ->search( { bodies_str => $test_council } )->delete();
}
done_testing;
diff --git a/t/app/controller/index.t b/t/app/controller/index.t
index 462b21064..47c08291f 100644
--- a/t/app/controller/index.t
+++ b/t/app/controller/index.t
@@ -55,12 +55,12 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub {
}
};
-$mech->delete_problems_for_council( 2651 );
+$mech->delete_problems_for_body( 2651 );
my $problem_rs = FixMyStreet::App->model('DB::Problem');
my $num = $problem_rs->count;
-my @edinburgh_problems = $mech->create_problems_for_council(5, 2651, 'Front page');
+my @edinburgh_problems = $mech->create_problems_for_body(5, 2651, 'Front page');
is scalar @edinburgh_problems, 5, 'correct number of edinburgh problems created';
$mech->get_ok('/report/' . $edinburgh_problems[2]->id);
diff --git a/t/app/controller/json.t b/t/app/controller/json.t
index 468fa5b31..405a84821 100644
--- a/t/app/controller/json.t
+++ b/t/app/controller/json.t
@@ -45,9 +45,11 @@ is_deeply #
# put an entry in the database for this test
my $user = $mech->create_user_ok('test@example.com');
+my $body = $mech->create_body_ok(2501, 'Wandsworth Borough Council');
+
my $problem_args = {
postcode => 'sw1a 1aa',
- council => '2501',
+ bodies_str => '2501',
areas => ',105164,11806,11827,2247,2501,34817,42011,66045,70786,8519,',
category => 'test category',
title => 'Test title',
@@ -86,7 +88,7 @@ is_deeply #
'category' => 'test category',
'confirmed' => '2000-01-01 12:01:00',
'lastupdate' => '2000-01-01 12:00:00',
- 'council' => 'Wandsworth Borough Council',
+ 'bodies_str' => 'Wandsworth Borough Council',
'detail' => 'Test detail',
'id' => $problem->id,
'name' => 'Test Name',
@@ -103,7 +105,7 @@ is_deeply #
'category' => 'test category',
'confirmed' => '2000-01-01 12:02:00',
'lastupdate' => '2000-01-01 12:00:00',
- 'council' => 'Wandsworth Borough Council',
+ 'bodies_str' => 'Wandsworth Borough Council',
'detail' => 'Test detail',
'id' => $anon_problem->id,
'name' => '',
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index d8d1eb4f3..5c81a43d1 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -30,7 +30,7 @@ my $sent_time = $sent->ymd . ' ' . $sent->hms;
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'EH1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Testing',
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index aa04e499b..a3c4edfc7 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -5,6 +5,7 @@ use Test::More;
use FixMyStreet::TestMech;
use Web::Scraper;
use Path::Class;
+use Test::LongString;
use DateTime;
my $mech = FixMyStreet::TestMech->new;
@@ -33,7 +34,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -94,6 +95,19 @@ subtest "change report to unconfirmed and check for 404 status" => sub {
ok $report->update( { state => 'confirmed' } ), 'confirm report again';
};
+
+subtest "Zurich unconfirmeds are 200" => sub {
+ if ( !FixMyStreet::Cobrand->exists('zurich') ) {
+ plan skip_all => 'Skipping Zurich test without Zurich cobrand';
+ }
+ $mech->host( 'zurich.fixmystreet.com' );
+ ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report';
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains( 'This report is awaiting moderation' );
+ ok $report->update( { state => 'confirmed' } ), 'confirm report again';
+ $mech->host( 'www.fixmystreet.com' );
+};
+
subtest "change report to hidden and check for 410 status" => sub {
ok $report->update( { state => 'hidden' } ), 'hide report';
ok $mech->get("/report/$report_id"), "get '/report/$report_id'";
@@ -385,39 +399,111 @@ for my $test (
};
}
+subtest "Zurich banners are displayed correctly" => sub {
+ if ( !FixMyStreet::Cobrand->exists('zurich') ) {
+ plan skip_all => 'Skipping Zurich test without Zurich cobrand';
+ }
+ $mech->host( 'zurich.fixmystreet.com' );
+
+ for my $test (
+ {
+ description => 'new report',
+ state => 'unconfirmed',
+ banner_id => 'closed',
+ banner_text => 'Erfasst'
+ },
+ {
+ description => 'confirmed report',
+ state => 'confirmed',
+ banner_id => 'closed',
+ banner_text => 'Aufgenommen',
+ },
+ {
+ description => 'fixed report',
+ state => 'fixed - council',
+ banner_id => 'fixed',
+ banner_text => 'Erledigt',
+ },
+ {
+ description => 'closed report',
+ state => 'closed',
+ banner_id => 'fixed',
+ banner_text => 'Erledigt',
+ },
+ {
+ description => 'in progress report',
+ state => 'in progress',
+ banner_id => 'progress',
+ banner_text => 'In Bearbeitung',
+ },
+ {
+ description => 'planned report',
+ state => 'planned',
+ banner_id => 'progress',
+ banner_text => 'In Bearbeitung',
+ },
+ ) {
+ subtest "banner for $test->{description}" => sub {
+ $report->state( $test->{state} );
+ $report->update;
+
+ $mech->get_ok("/report/$report_id");
+ is $mech->uri->path, "/report/$report_id", "at /report/$report_id";
+ my $banner = $mech->extract_problem_banner;
+ if ( $banner->{text} ) {
+ $banner->{text} =~ s/^ //g;
+ $banner->{text} =~ s/ $//g;
+ }
+
+ is $banner->{id}, $test->{banner_id}, 'banner id';
+ if ($test->{banner_text}) {
+ like_string( $banner->{text}, qr/$test->{banner_text}/i, 'banner text is ' . $test->{banner_text} );
+ } else {
+ is $banner->{text}, $test->{banner_text}, 'banner text';
+ }
+
+ };
+ }
+
+ $mech->host( 'www.fixmystreet.com' );
+};
+
+$mech->create_body_ok(2504, 'Westminster City Council');
+$mech->create_body_ok(2505, 'Camden Borough Council');
+
for my $test (
{
desc => 'no state dropdown if user not from authority',
- from_council => 0,
+ from_body => undef,
no_state => 1,
- report_council => '2504',
+ report_body => '2504',
},
{
desc => 'state dropdown if user from authority',
- from_council => 2504,
+ from_body => 2504,
no_state => 0,
- report_council => '2504',
+ report_body => '2504',
},
{
- desc => 'no state dropdown if user not from same council as problem',
- from_council => 2505,
+ desc => 'no state dropdown if user not from same body as problem',
+ from_body => 2505,
no_state => 1,
- report_council => '2504',
+ report_body => '2504',
},
{
- desc => 'state dropdown if user from authority and problem sent to multiple councils',
- from_council => 2504,
+ desc => 'state dropdown if user from authority and problem sent to multiple bodies',
+ from_body => 2504,
no_state => 0,
- report_council => '2504,2506',
+ report_body => '2504,2506',
},
) {
subtest $test->{desc} => sub {
$mech->log_in_ok( $user->email );
- $user->from_council( $test->{from_council} );
+ $user->from_body( $test->{from_body} );
$user->update;
$report->discard_changes;
- $report->council( $test->{report_council} );
+ $report->bodies_str( $test->{report_body} );
$report->update;
$mech->get_ok("/report/$report_id");
@@ -431,7 +517,7 @@ for my $test (
}
$report->discard_changes;
-$report->council( 2504 );
+$report->bodies_str( 2504 );
$report->update;
# tidy up
diff --git a/t/app/controller/report_interest_count.t b/t/app/controller/report_interest_count.t
index dd44a83d4..bfd1a8d1f 100644
--- a/t/app/controller/report_interest_count.t
+++ b/t/app/controller/report_interest_count.t
@@ -16,11 +16,6 @@ my $user =
->find_or_create( { email => 'test@example.com', name => 'Test User' } );
ok $user, "created test user";
-my $user2 =
- FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'test2@example.com', name => 'Other User' } );
-ok $user2, "created test user";
-
my $dt = DateTime->new(
year => 2011,
month => 04,
@@ -33,7 +28,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -59,21 +54,24 @@ ok $report, "created test report - $report_id";
SKIP: {
skip( "Need 'fixmybarangay' in ALLOWED_COBRANDS config", 29 )
unless FixMyStreet::Cobrand->exists('fixmybarangay');
+
+ $mech->create_body_ok(2504, 'Westminster City Council');
+
for my $test (
{
- desc => 'if not from council then no supporter button',
- from_council => 0,
+ desc => 'if not from body then no supporter button',
+ from_body => undef,
support_string => 'No supporters',
},
{
- desc => 'from council user can increment supported count',
- from_council => 2504,
+ desc => 'from body user can increment supported count',
+ from_body => 2504,
support_string => 'No supporters',
updated_support => '1 supporter'
},
{
desc => 'correct grammar for more than one supporter',
- from_council => 2504,
+ from_body => 2504,
support_string => '1 supporter',
updated_support => '2 supporters'
},
@@ -81,17 +79,17 @@ SKIP: {
subtest $test->{desc} => sub {
ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
$mech->log_in_ok( $user->email );
- $user->from_council( $test->{from_council} );
+ $user->from_body( $test->{from_body} );
$user->update;
- $report->discard_changes;
- $report->council( $test->{report_council} );
- $report->update;
+ $report->update( {
+ bodies_str => $test->{report_council}
+ } );
$mech->get_ok("/report/$report_id");
$mech->content_contains( $test->{support_string} );
- if ( $test->{from_council} ) {
+ if ( $test->{from_body} ) {
$mech->content_contains('Add support');
$mech->submit_form_ok( { form_number => 1 } );
@@ -104,18 +102,16 @@ SKIP: {
};
}
- subtest 'check non council user cannot increment support count' => sub {
+ subtest 'check non body user cannot increment support count' => sub {
ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
- $report->discard_changes;
- $report->interest_count(1);
- ok $report->update(), 'updated interest count';
- $report->discard_changes;
+ ok $report->update({ interest_count => 1 }), 'updated interest count';
is $report->interest_count, 1, 'correct interest count';
$mech->get_ok("/report/$report_id");
$mech->content_contains( '1 supporter' );
+ # This doesn't send cookie, so is logged out
$mech->post_ok("/report/support", { id => $report_id } );
is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
@@ -135,7 +131,7 @@ subtest 'check support details not shown if not enabled in cobrand' => sub {
};
$report->discard_changes;
-$report->council( 2504 );
+$report->bodies_str( 2504 );
$report->update;
# tidy up
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 0206feed3..868977953 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -33,49 +33,61 @@ my %contact_params = (
whenedited => \'current_timestamp',
note => 'Created for test',
);
+
+for my $body (
+ { id => 2651, name => 'City of Edinburgh Council' },
+ { id => 2226, name => 'Gloucestershire County Council' },
+ { id => 2326, name => 'Cheltenham Borough Council' },
+ { id => 2482, name => 'Bromley Council' },
+ { id => 2240, name => 'Staffordshire County Council' },
+ { id => 2434, name => 'Lichfield District Council' },
+) {
+ $mech->create_body_ok($body->{id}, $body->{name});
+}
+
# Let's make some contacts to send things to!
FixMyStreet::App->model('DB::Contact')->search( {
email => { 'like', '%example.com' },
} )->delete;
my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Street lighting',
email => 'highways@example.com',
} );
my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2226, # Gloucestershire
+ body_id => 2226, # Gloucestershire
category => 'Potholes',
email => 'potholes@example.com',
} );
my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2326, # Cheltenham
+ body_id => 2326, # Cheltenham
category => 'Trees',
email => 'trees@example.com',
} );
my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2482, # Bromley
+ body_id => 2482, # Bromley
category => 'Trees',
email => 'trees@example.com',
} );
my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Trees',
email => 'trees@example.com',
} );
my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2434, # Lichfield
+ body_id => 2434, # Lichfield
category => 'Trees',
email => 'trees@example.com',
} );
my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2240, # Lichfield
+ body_id => 2240, # Lichfield
category => 'Street lighting',
email => 'highways@example.com',
} );
@@ -92,6 +104,57 @@ ok $contact7, "created test contact 7";
foreach my $test (
{
msg => 'all fields empty',
+ pc => 'OX1 3DH',
+ fields => {
+ title => '',
+ detail => '',
+ photo => '',
+ name => '',
+ may_show_name => '1',
+ email => '',
+ phone => '',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {},
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ # No category error, as no categories for Oxon at all, so is skipped
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'all fields empty, bad category',
+ pc => 'GL50 2PR',
+ fields => {
+ title => '',
+ detail => '',
+ photo => '',
+ name => '',
+ may_show_name => '1',
+ email => '',
+ phone => '',
+ category => 'Something bad',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {
+ category => '-- Pick a category --',
+ },
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please choose a category',
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'all fields empty except category',
pc => 'SW1A 1AA',
fields => {
title => '',
@@ -503,7 +566,7 @@ foreach my $test (
is $mech->get( '/report/' . $report->id )->code, 404, "report not found";
# Check the report has been assigned appropriately
- is $report->council, 2651;
+ is $report->bodies_str, 2651;
# receive token
my $email = $mech->get_email;
@@ -659,7 +722,7 @@ subtest "test report creation for a user who is signing in as they report" => su
is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
# Check the report has been assigned appropriately
- is $report->council, 2651;
+ is $report->bodies_str, 2651;
# check that no emails have been sent
$mech->email_count_is(0);
@@ -750,7 +813,7 @@ foreach my $test (
ok $report, "Found the report";
# Check the report has been assigned appropriately
- is $report->council, $test->{council};
+ is $report->bodies_str, $test->{council};
# check that we got redirected to /report/
is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
@@ -1155,7 +1218,7 @@ SKIP: {
ok $report, "Found the report";
# Check the report has been assigned appropriately
- is $report->council, $test->{council};
+ is $report->bodies_str, $test->{council};
if ( $test->{redirect} ) {
is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
@@ -1210,9 +1273,10 @@ SKIP: {
my $cobrand = FixMyStreet::Cobrand::SeeSomething->new();
+ $mech->create_body_ok(2535, 'Sandwell Borough Council');
my $bus_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2535,
+ body_id => 2535,
category => 'Bus',
email => 'bus@example.com',
non_public => 1,
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index 55c5a92e8..22d2d1f97 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -7,12 +7,12 @@ use Web::Scraper;
my $mech = FixMyStreet::TestMech->new;
-my $open311Conf = FixMyStreet::App->model('DB::Open311Conf')->find_or_create( {
- area_id => 2651,
- endpoint => 'http://example.com/open311',
- jurisdiction => 'mySociety',
- api_key => 'apikey',
-} );
+my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council');
+$body->update({
+ endpoint => 'http://example.com/open311',
+ jurisdiction => 'mySociety',
+ api_key => 'apikey',
+});
my %contact_params = (
confirmed => 1,
@@ -24,7 +24,7 @@ my %contact_params = (
# Let's make some contacts to send things to!
my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Street lighting',
email => '100',
extra => [ { description => 'Lamppost number', code => 'number', required => 'True' },
@@ -35,7 +35,7 @@ my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
} );
my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Graffiti Removal',
email => '101',
} );
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index 3986d01b5..2765ed246 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -35,7 +35,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -409,7 +409,7 @@ $report->update;
subtest 'check non authority user cannot change set state' => sub {
$mech->log_in_ok( $user->email );
- $user->from_council( 0 );
+ $user->from_body( undef );
$user->update;
$mech->get_ok("/report/$report_id");
@@ -434,10 +434,12 @@ subtest 'check non authority user cannot change set state' => sub {
is $report->state, 'confirmed', 'state unchanged';
};
+$mech->create_body_ok(2504, 'Westminster City Council');
+
for my $state ( qw/unconfirmed hidden partial/ ) {
subtest "check that update cannot set state to $state" => sub {
$mech->log_in_ok( $user->email );
- $user->from_council( 2504 );
+ $user->from_body( 2504 );
$user->update;
$mech->get_ok("/report/$report_id");
@@ -586,18 +588,18 @@ for my $test (
state => 'fixed',
},
state => 'fixed - council',
- report_councils => '2504,2505',
+ report_bodies => '2504,2505',
},
) {
subtest $test->{desc} => sub {
$report->comments->delete;
- if ( $test->{ report_councils } ) {
- $report->council( $test->{ report_councils } );
+ if ( $test->{ report_bodies } ) {
+ $report->bodies_str( $test->{ report_bodies } );
$report->update;
}
$mech->log_in_ok( $user->email );
- $user->from_council( 2504 );
+ $user->from_body( 2504 );
$user->update;
$mech->get_ok("/report/$report_id");
@@ -670,7 +672,7 @@ subtest 'check meta correct for comments marked confirmed but not marked open' =
subtest "check first comment with no status change has no status in meta" => sub {
$mech->log_in_ok( $user->email );
- $user->from_council( 0 );
+ $user->from_body( undef );
$user->update;
my $comment = $report->comments->first;
@@ -684,7 +686,7 @@ subtest "check first comment with no status change has no status in meta" => sub
subtest "check comment with no status change has not status in meta" => sub {
$mech->log_in_ok( $user->email );
- $user->from_council( 0 );
+ $user->from_body( undef );
$user->update;
my $comment = $report->comments->first;
@@ -718,7 +720,7 @@ subtest "check comment with no status change has not status in meta" => sub {
my $update_meta = $mech->extract_update_metas;
unlike $update_meta->[1], qr/marked as/, 'update meta does not include state change';
- $user->from_council( 2504 );
+ $user->from_body( 2504 );
$user->update;
$mech->get_ok("/report/$report_id");
@@ -820,11 +822,11 @@ subtest 'check meta correct for second comment marking as reopened' => sub {
like $update_meta->[1], qr/reopened$/, 'update meta says reopened';
};
-$user->from_council(0);
+$user->from_body(undef);
$user->update;
$report->state('confirmed');
-$report->council('2504');
+$report->bodies_str('2504');
$report->update;
for my $test (
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index a4dab6597..503950d8a 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -8,11 +8,15 @@ use DateTime;
ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
-$mech->delete_problems_for_council( 2504 );
-$mech->delete_problems_for_council( 2651 );
+$mech->create_body_ok(2514, 'Birmingham City Council');
+$mech->create_body_ok(2651, 'City of Edinburgh Council');
+$mech->create_body_ok(2504, 'Westminster City Council');
-my @edinburgh_problems = $mech->create_problems_for_council(3, 2651, 'All reports');
-my @westminster_problems = $mech->create_problems_for_council(5, 2504, 'All reports');
+$mech->delete_problems_for_body( 2504 );
+$mech->delete_problems_for_body( 2651 );
+
+my @edinburgh_problems = $mech->create_problems_for_body(3, 2651, 'All reports');
+my @westminster_problems = $mech->create_problems_for_body(5, 2504, 'All reports');
is scalar @westminster_problems, 5, 'correct number of westminster problems created';
is scalar @edinburgh_problems, 3, 'correct number of edinburgh problems created';
@@ -63,6 +67,7 @@ SKIP: {
skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 )
unless FixMyStreet::Cobrand->exists('fiksgatami');
+ $mech->create_body_ok(3, 'Oslo');
mySociety::MaPit::configure('http://mapit.nuug.no/');
ok $mech->host("fiksgatami.no"), 'change host to fiksgatami';
$mech->get_ok('/reports');
diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t
index 456067e6c..f04a17151 100644
--- a/t/app/controller/rss.t
+++ b/t/app/controller/rss.t
@@ -17,7 +17,7 @@ my $user1 = FixMyStreet::App->model('DB::User')
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
postcode => 'eh1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Testing',
@@ -113,6 +113,68 @@ $mech->content_contains( "Testing, 10th October" );
$mech->content_contains( '18 North Bridge, Edinburgh' );
$report->delete();
+
+my $now = DateTime->now();
+my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'WS13 6YY',
+ bodies_str => '2434',
+ areas => ',2434,2240,',
+ category => 'Other',
+ title => 'council report',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $now->ymd . ' ' . $now->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '52.727588',
+ longitude => '-1.731322',
+ user_id => $user1->id,
+ }
+);
+
+my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'WS13 6YY',
+ bodies_str => '2240',
+ areas => ',2434,2240,',
+ category => 'Other',
+ title => 'county report',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $now->ymd . ' ' . $now->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '52.727588',
+ longitude => '-1.731322',
+ user_id => $user1->id,
+ }
+);
+
+subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" => sub {
+ $mech->host('lichfielddc.fixmystreet.com');
+ $mech->get_ok("/rss/area/Lichfield");
+
+ my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id;
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('lichfielddc')->new();
+ my $expected2 = $cobrand->base_url . '/report/' . $report_to_council->id;
+
+ $mech->content_contains($expected1, 'non cobrand area report point to fixmystreet.com');
+ $mech->content_contains($expected2, 'cobrand area report point to cobrand url');
+};
+
$mech->delete_user( $user1 );
done_testing();
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index c592e9d3f..ba48300b2 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -39,7 +39,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -345,7 +345,7 @@ my $ward_alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'WS13 6YY',
- council => '2434',
+ bodies_str => '2434',
areas => ',105255,11806,11828,2247,2504,7117,',
category => 'Other',
title => 'council report',
@@ -369,7 +369,7 @@ my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'WS13 6YY',
- council => '2240',
+ bodies_str => '2240',
areas => ',105255,11806,11828,2247,2504,7117,',
category => 'Other',
title => 'county report',
@@ -393,7 +393,7 @@ my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_c
my $report_outside_district = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'WS13 6YY',
- council => '2221',
+ bodies_str => '2221',
areas => ',105255,11806,11828,2247,2504,7117,',
category => 'Other',
title => 'outside district report',
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 040790184..a92e3b079 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -44,7 +44,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your name',
}
},
@@ -56,7 +56,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
}
},
@@ -68,7 +68,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
}
},
@@ -80,7 +80,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
@@ -90,7 +90,7 @@ for my $test (
},
errors => {
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
@@ -99,22 +99,22 @@ for my $test (
detail => 'Some information about the problem',
},
errors => {
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
- desc => 'incorrectly formatted council',
+ desc => 'incorrectly formatted body',
changed => {
- council => 'my council',
+ bodies_str => 'my body',
},
errors => {
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
- desc => 'correctly formatted council',
+ desc => 'correctly formatted body',
changed => {
- council => '1001',
+ bodies_str => '1001',
},
errors => {
}
@@ -383,42 +383,56 @@ my %contact_params = (
whenedited => \'ms_current_timestamp()',
note => 'Created for test',
);
+
+for my $body (
+ { id => 2651, name => 'City of Edinburgh Council' },
+ { id => 2226, name => 'Gloucestershire County Council' },
+ { id => 2326, name => 'Cheltenham Borough Council' },
+ { id => 2434, name => 'Lichfield District Council' },
+ { id => 2240, name => 'Staffordshire County Council' },
+ { id => 14279, name => 'Ballymoney Borough Council' },
+ { id => 2636, name => 'Isle of Wight Council' },
+ { id => 2649, name => 'Fife Council' },
+) {
+ $mech->create_body_ok($body->{id}, $body->{name});
+}
+
# Let's make some contacts to send things to!
FixMyStreet::App->model('DB::Contact')->search( {
email => { 'like', '%example.com' },
} )->delete;
my @contacts;
for my $contact ( {
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'potholes',
email => 'test@example.org',
}, {
- area_id => 2226, # Gloucestershire
+ body_id => 2226, # Gloucestershire
category => 'potholes',
email => '2226@example.org',
}, {
- area_id => 2326, # Cheltenham
+ body_id => 2326, # Cheltenham
category => 'potholes',
email => '2326@example.org',
}, {
- area_id => 2434, # Lichfield
+ body_id => 2434, # Lichfield
category => 'potholes',
email => 'trees@example.com',
}, {
- area_id => 2240, # Staffordshire
+ body_id => 2240, # Staffordshire
category => 'potholes',
email => 'highways@example.com',
}, {
- area_id => 14279, # Ballymoney
+ body_id => 14279, # Ballymoney
category => 'Street lighting',
email => 'roads.western@drdni.example.org',
}, {
- area_id => 14279, # Ballymoney
+ body_id => 14279, # Ballymoney
category => 'Graffiti',
email => 'highways@example.com',
}, {
confirmed => 0,
- area_id => 2636, # Isle of Wight
+ body_id => 2636, # Isle of Wight
category => 'potholes',
email => '2636@example.com',
} ) {
@@ -438,13 +452,13 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear City of Edinburgh Council',
to => qr'City of Edinburgh Council',
- council => 2651,
+ body => 2651,
}, {
%common,
desc => 'no email sent if no unsent problems',
unset_whendef => 0,
email_count => 0,
- council => 2651,
+ body => 2651,
}, {
%common,
desc => 'email to two tier council',
@@ -452,7 +466,7 @@ foreach my $test ( {
email_count => 1,
to => qr'Gloucestershire County Council.*Cheltenham Borough Council',
dear => qr'Dear Gloucestershire County Council and Cheltenham Borough',
- council => '2226,2326',
+ body => '2226,2326',
multiple => 1,
}, {
%common,
@@ -461,7 +475,7 @@ foreach my $test ( {
email_count => 1,
to => qr'Gloucestershire County Council" <2226@example',
dear => qr'Dear Gloucestershire County Council,',
- council => '2226|2649',
+ body => '2226|2649',
missing => qr'problem might be the responsibility of Fife.*Council'ms,
}, {
%common,
@@ -470,7 +484,7 @@ foreach my $test ( {
email_count => 1,
to => qr'Lichfield District Council',
dear => qr'Dear Lichfield District Council,',
- council => '2434',
+ body => '2434',
cobrand => 'lichfielddc',
url => 'lichfielddc.',
}, {
@@ -480,7 +494,7 @@ foreach my $test ( {
email_count => 1,
to => qr'Staffordshire County Council" <highways@example',
dear => qr'Dear Staffordshire County Council,',
- council => '2240',
+ body => '2240',
cobrand => 'lichfielddc',
url => '',
}, {
@@ -490,7 +504,7 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear Ballymoney Borough Council',
to => qr'Ballymoney Borough Council',
- council => 14279,
+ body => 14279,
category => 'Graffiti',
}, {
%common,
@@ -499,7 +513,7 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear Roads Service \(Western\)',
to => qr'Roads Service \(Western\)" <roads',
- council => 14279,
+ body => 14279,
category => 'Street lighting',
}, {
%common,
@@ -507,7 +521,7 @@ foreach my $test ( {
unset_whendef => 1,
stays_unsent => 1,
email_count => 0,
- council => 2636,
+ body => 2636,
},
) {
subtest $test->{ desc } => sub {
@@ -525,7 +539,7 @@ foreach my $test ( {
$problem->discard_changes;
$problem->update( {
- council => $test->{ council },
+ bodies_str => $test->{ body },
state => 'confirmed',
confirmed => \'ms_current_timestamp()',
whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()',
@@ -547,9 +561,9 @@ foreach my $test ( {
like $email->body, $test->{ dear }, 'Salutation looks correct';
if ( $test->{multiple} ) {
- like $email->body, qr/This email has been sent to several councils /, 'multiple council text correct';
+ like $email->body, qr/This email has been sent to several councils /, 'multiple body text correct';
} elsif ( $test->{ missing } ) {
- like $email->body, $test->{ missing }, 'missing council information correct';
+ like $email->body, $test->{ missing }, 'missing body information correct';
}
if ( $test->{url} ) {
@@ -617,7 +631,7 @@ subtest 'check can turn on report sent email alerts' => sub {
$problem->comments->delete;
$problem->delete;
-$user->delete;
+$mech->delete_user( $user );
foreach (@contacts) {
$_->delete;
diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t
index 84379394d..8063c928f 100644
--- a/t/app/sendreport/email.t
+++ b/t/app/sendreport/email.t
@@ -14,9 +14,14 @@ use mySociety::Locale;
my $e = FixMyStreet::SendReport::Email->new();
+# area id 1000
+my $params = { id => 1000, name => 'Council of the Thousand' };
+my $body = FixMyStreet::App->model('DB::Body')->find_or_create($params);
+ok $body, "found/created body";
+
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
email => 'council@example.com',
- area_id => 1000,
+ body_id => 1000,
category => 'category',
confirmed => 1,
deleted => 0,
@@ -26,7 +31,7 @@ my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
);
my $row = FixMyStreet::App->model('DB::Problem')->new( {
- council => '1000',
+ bodies_str => '1000',
category => 'category',
cobrand => '',
} );
@@ -48,7 +53,7 @@ foreach my $test ( {
count => undef,
add_council => 1,
unconfirmed => 1,
- expected_note => 'Council 1000 deleted',
+ expected_note => 'Body 1000 deleted',
},
{
desc => 'unconfirmed contact note uses note from contact table',
@@ -63,7 +68,7 @@ foreach my $test ( {
my $e = FixMyStreet::SendReport::Email->new;
$contact->update( { confirmed => 0 } ) if $test->{unconfirmed};
$contact->update( { note => $test->{note} } ) if $test->{note};
- $e->add_council( 1000, { name => 'test council' } ) if $test->{add_council};
+ $e->add_body( $body ) if $test->{add_council};
is $e->build_recipient_list( $row, {} ), $test->{count}, 'correct recipient list count';
if ( $test->{unconfirmed} ) {
diff --git a/t/cobrand/closest.t b/t/cobrand/closest.t
index 464c95e67..ab97694c9 100644
--- a/t/cobrand/closest.t
+++ b/t/cobrand/closest.t
@@ -29,7 +29,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t
new file mode 100644
index 000000000..245cb1a13
--- /dev/null
+++ b/t/cobrand/get_body_sender.t
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use mySociety::Locale;
+use FixMyStreet::App;
+
+use_ok 'FixMyStreet::Cobrand';
+
+mySociety::Locale::gettext_domain( 'FixMyStreet' );
+
+my $c = FixMyStreet::Cobrand::FixMyStreet->new();
+
+FixMyStreet::App->model('DB::BodyArea')->search( { body_id => 1000 } )->delete;
+FixMyStreet::App->model('DB::Body')->search( { name => 'Body of a Thousand' } )->delete;
+
+my $body = FixMyStreet::App->model('DB::Body')->find_or_create({
+ id => 1000,
+ name => 'Body of a Thousand',
+});
+my $body_area = $body->body_areas->find_or_create({ area_id => 1000 });
+
+is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email';
+
+$body_area->update({ area_id => 2481 }); # Croydon LBO
+is_deeply $c->get_body_sender( $body ), { method => 'London' }, 'returns london report it if London borough';
+
+$body->send_method( 'TestMethod' );
+is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to London';
+
+$body_area->update({ area_id => 1000 }); # Nothing
+is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to Email';
+
+$body_area->delete;
+$body->delete;
+
+done_testing();
diff --git a/t/cobrand/get_council_sender.t b/t/cobrand/get_council_sender.t
deleted file mode 100644
index e61f36370..000000000
--- a/t/cobrand/get_council_sender.t
+++ /dev/null
@@ -1,30 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-
-use mySociety::Locale;
-use FixMyStreet::App;
-
-use_ok 'FixMyStreet::Cobrand';
-
-mySociety::Locale::gettext_domain( 'FixMyStreet' );
-
-my $c = FixMyStreet::Cobrand::FixMyStreet->new();
-
-
-is_deeply $c->get_council_sender( '1000', { type => 'DIS' } ), { method => 'Email' }, 'defaults to email';
-is_deeply $c->get_council_sender( '1000', { type => 'LBO' } ), { method=> 'London' }, 'returns london report it if London borough';
-
-my $conf = FixMyStreet::App->model('DB::Open311Conf')->find_or_create(
- area_id => 1000,
- endpoint => '',
- send_method => 'TestMethod'
-);
-
-is $c->get_council_sender( '1000', { type => 'LBO' } )->{ method }, 'TestMethod', 'uses send_method in preference to London';
-is $c->get_council_sender( '1000', { type => 'DIS' } )->{ method }, 'TestMethod', 'uses send_method in preference to Email';
-
-$conf->delete;
-
-done_testing();
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
new file mode 100644
index 000000000..a6922a00d
--- /dev/null
+++ b/t/cobrand/zurich.t
@@ -0,0 +1,168 @@
+# TODO
+# Report to third party (with third_personal)
+# Overdue alerts
+
+use strict;
+use warnings;
+use DateTime;
+use Test::More;
+
+plan skip_all => 'Skipping Zurich test without Zurich cobrand'
+ unless FixMyStreet::Cobrand->exists('zurich');
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+# Front page test
+ok $mech->host("zurich.fixmystreet.com"), "change host to Zurich";
+$mech->get_ok('/');
+$mech->content_like( qr/zurich/i );
+
+# Set up bodies
+my $zurich = $mech->create_body_ok( 1, 'Zurich' );
+my $division = $mech->create_body_ok( 2, 'Division 1' );
+$division->parent( $zurich->id );
+$division->endpoint( 'division@example.org' );
+$division->update;
+my $subdivision = $mech->create_body_ok( 3, 'Subdivision A' );
+$subdivision->parent( $division->id );
+$subdivision->endpoint( 'subdivision@example.org' );
+$subdivision->update;
+
+my @reports = $mech->create_problems_for_body( 1, 2, 'Test', {
+ state => 'unconfirmed',
+ confirmed => undef,
+ cobrand => 'zurich',
+});
+my $report = $reports[0];
+
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('moderation');
+
+# Check logging in to deal with this report
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/auth', "got sent to the sign in page";
+
+my $user = $mech->log_in_ok( 'dm1@example.org') ;
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/auth', "got sent to the sign in page";
+$user->from_body( 2 );
+$user->update;
+
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/admin', "am logged in";
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+$mech->content_contains( 'Erfasst' );
+
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('Aufgenommen');
+$mech->content_contains('Test Test');
+$mech->content_lacks('photo/' . $report->id . '.jpeg');
+$mech->email_count_is(0);
+
+# Photo publishing
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { publish_photo => 1 } } );
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('photo/' . $report->id . '.jpeg');
+
+# Internal notes
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { internal_notes => 'Some internal notes.' } } );
+$mech->content_contains( 'Some internal notes' );
+
+# Original description
+$mech->submit_form_ok( { with_fields => { detail => 'Edited details text.' } } );
+$mech->content_contains( 'Edited details text.' );
+$mech->content_contains( 'originally entered: &ldquo;Test Test 1 for 2 Detail&rdquo;' );
+
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { body_subdivision => 3 } } );
+
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('In Bearbeitung');
+$mech->content_contains('Test Test');
+
+FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+my $email = $mech->get_email;
+like $email->header('Subject'), qr/Neue Meldung/, 'subject looks okay';
+like $email->header('To'), qr/subdivision\@example.org/, 'to line looks correct';
+$mech->clear_emails_ok;
+
+$mech->log_out_ok;
+
+$user = $mech->log_in_ok( 'sdm1@example.org') ;
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/auth', "got sent to the sign in page";
+$user->from_body( 3 );
+$user->update;
+
+$mech->get_ok( '/admin' );
+is $mech->uri->path, '/admin', "am logged in";
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+$mech->content_contains( 'In Bearbeitung' );
+
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->content_contains( 'Some internal notes' );
+
+$mech->submit_form_ok( { with_fields => { status_update => 'This is an update.' } } );
+is $mech->uri->path, '/admin/report_edit/' . $report->id, "still on edit page";
+$mech->content_contains('This is an update');
+ok $mech->form_with_fields( 'status_update' );
+$mech->submit_form_ok( { button => 'no_more_updates' } );
+is $mech->uri->path, '/admin/summary', "redirected now finished with report.";
+
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('In Bearbeitung');
+$mech->content_contains('Test Test');
+
+FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+$email = $mech->get_email;
+like $email->header('Subject'), qr/Feedback/, 'subject looks okay';
+like $email->header('To'), qr/division\@example.org/, 'to line looks correct';
+$mech->clear_emails_ok;
+
+$report->discard_changes;
+is $report->state, 'planned', 'Report now in planned state';
+
+$mech->log_out_ok;
+$user = $mech->log_in_ok( 'dm1@example.org') ;
+$mech->get_ok( '/admin' );
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+
+# User confirms their email address
+my $extra = $report->extra;
+$extra->{email_confirmed} = 1;
+$report->extra ( { %$extra } );
+$report->update;
+
+$mech->get_ok( '/admin/report_edit/' . $report->id );
+$mech->submit_form_ok( { with_fields => { status_update => 'FINAL UPDATE' } } );
+$mech->form_with_fields( 'status_update' );
+$mech->submit_form_ok( { button => 'publish_response' } );
+
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains('Erledigt');
+$mech->content_contains('Test Test');
+$mech->content_contains('FINAL UPDATE');
+
+$email = $mech->get_email;
+like $email->header('To'), qr/test\@example.com/, 'to line looks correct';
+like $email->body, qr/FINAL UPDATE/, 'body looks correct';
+$mech->clear_emails_ok;
+
+$mech->delete_problems_for_body( 2 );
+$mech->delete_user( 'dm1@example.org' );
+$mech->delete_user( 'sdm1@example.org' );
+
+ok $mech->host("www.fixmystreet.com"), "change host back";
+
+done_testing();
diff --git a/t/map/tilma/original.t b/t/map/tilma/original.t
index 7f68df308..72cde5f9f 100644
--- a/t/map/tilma/original.t
+++ b/t/map/tilma/original.t
@@ -32,7 +32,7 @@ my $dt = DateTime->now();
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index ba2854460..36ed13615 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -123,7 +123,7 @@ my $problem = $problem_rs->new(
lastupdate => DateTime->now()->subtract( days => 1 ),
anonymous => 1,
external_id => time(),
- council => 2482,
+ bodies_str => 2482,
}
);
@@ -350,7 +350,7 @@ for my $test (
$problem->state( $test->{start_state} );
$problem->update;
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -389,7 +389,7 @@ foreach my $test (
$problem->comments->delete;
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -419,7 +419,7 @@ my $problem2 = $problem_rs->new(
lastupdate => DateTime->now(),
anonymous => 1,
external_id => $problem->external_id,
- council => 2651,
+ bodies_str => 2651,
}
);
@@ -458,7 +458,7 @@ for my $test (
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
- my $council_details = { areaid => $test->{area_id} };
+ my $council_details = { areas => { $test->{area_id} => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -498,7 +498,7 @@ subtest 'using start and end date' => sub {
end_date => $end_dt,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
my $start = $start_dt . '';
@@ -558,7 +558,7 @@ subtest 'check that existing comments are not duplicated' => sub {
system_user => $user,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
@@ -619,7 +619,7 @@ foreach my $test ( {
system_user => $user,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
@@ -671,7 +671,7 @@ foreach my $test ( {
suppress_alerts => $test->{suppress_alerts},
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
diff --git a/t/open311/getupdates.t b/t/open311/getupdates.t
deleted file mode 100644
index 500ac97d2..000000000
--- a/t/open311/getupdates.t
+++ /dev/null
@@ -1,198 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-use Test::More;
-
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../commonlib/perllib";
-
-use_ok( 'Open311::GetUpdates' );
-use_ok( 'Open311' );
-
-my $user = FixMyStreet::App->model('DB::User')->find_or_create(
- {
- email => 'system_user@example.com'
- }
-);
-
-
-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>
-<service_request_id>638344</service_request_id>
-<status>open</status>
-<status_notes>This is a note.</status_notes>
-<service_name>Sidewalk and Curb Issues</service_name>
-<service_code>006</service_code>
-<description></description>
-<agency_responsible></agency_responsible>
-<service_notice></service_notice>
-<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime>
-UPDATED_DATETIME
-<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime>
-<lat>37.762221815</lat>
-<long>-122.4651145</long>
-</request>
-</service_requests>
-};
-
-my $problem_rs = FixMyStreet::App->model('DB::Problem');
-my $problem = $problem_rs->new(
- {
- postcode => 'EH99 1SP',
- latitude => 1,
- longitude => 1,
- areas => 1,
- title => '',
- detail => '',
- used_map => 1,
- user_id => 1,
- name => '',
- state => 'confirmed',
- service => '',
- cobrand => 'default',
- cobrand_data => '',
- user => $user,
- created => DateTime->now()->subtract( days => 1 ),
- lastupdate => DateTime->now()->subtract( days => 1 ),
- anonymous => 1,
- external_id => 638344,
- }
-);
-
-$problem->insert;
-
-for my $test (
- {
- desc => 'element missing',
- updated_datetime => '',
- comment_count => 0,
- },
- {
- desc => 'empty element',
- updated_datetime => '<updated_datetime />',
- comment_count => 0,
- },
- {
- desc => 'element with no content',
- updated_datetime => '<updated_datetime></updated_datetime>',
- comment_count => 0,
- },
- {
- desc => 'element with old content',
- updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', DateTime->now->subtract( days => 3 ) ),
- comment_count => 0,
- },
- {
- desc => 'element with new content',
- updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', DateTime->now ),
- comment_count => 1,
- },
-) {
- subtest $test->{desc} => sub {
- $problem->comments->delete;
- $problem->lastupdate(DateTime->now()->subtract( days => 1 ) ),
- $problem->update;
-
- my $local_requests_xml = $requests_xml;
- $local_requests_xml =~ s/UPDATED_DATETIME/$test->{updated_datetime}/;
-
- 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, { name => 'Test Council' } );
- is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344', 'get url';
-
- is $problem->comments->count, $test->{comment_count}, 'added a comment';
- };
-}
-
-$requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
-<service_requests>
-<request>
-<service_request_id>638344</service_request_id>
-<status>open</status>
-<status_notes>This is a note.</status_notes>
-<service_name>Sidewalk and Curb Issues</service_name>
-<service_code>006</service_code>
-<description></description>
-<agency_responsible></agency_responsible>
-<service_notice></service_notice>
-<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime>
-<updated_datetime>UPDATED_DATETIME</updated_datetime>
-<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime>
-<lat>37.762221815</lat>
-<long>-122.4651145</long>
-</request>
-<request>
-<service_request_id>638345</service_request_id>
-<status>open</status>
-<status_notes>This is a for a different issue.</status_notes>
-<service_name>Sidewalk and Curb Issues</service_name>
-<service_code>006</service_code>
-<description></description>
-<agency_responsible></agency_responsible>
-<service_notice></service_notice>
-<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime>
-<updated_datetime>UPDATED_DATETIME2</updated_datetime>
-<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime>
-<lat>37.762221815</lat>
-<long>-122.4651145</long>
-</request>
-</service_requests>
-};
-
-my $problem2 = $problem_rs->create(
- {
- postcode => 'EH99 1SP',
- latitude => 1,
- longitude => 1,
- areas => 1,
- title => '',
- detail => '',
- used_map => 1,
- user_id => 1,
- name => '',
- state => 'confirmed',
- service => '',
- cobrand => 'default',
- cobrand_data => '',
- user => $user,
- created => DateTime->now()->subtract( days => 1 ),
- lastupdate => DateTime->now()->subtract( days => 1 ),
- anonymous => 1,
- external_id => 638345,
- }
-);
-
-$problem->comments->delete;
-subtest 'update with two requests' => sub {
- $problem->comments->delete;
- $problem->lastupdate(DateTime->now()->subtract( days => 1 ) ),
-
- my $date1 = DateTime::Format::W3CDTF->new->format_datetime( DateTime->now() );
- my $date2 = DateTime::Format::W3CDTF->new->format_datetime( DateTime->now->subtract( hours => 1) );
- my $local_requests_xml = $requests_xml;
- $local_requests_xml =~ s/UPDATED_DATETIME2/$date2/;
- $local_requests_xml =~ s/UPDATED_DATETIME/$date1/;
-
- 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, { name => 'Test Council' } );
- is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344%2C638345', 'get url';
-
- is $problem->comments->count, 1, 'added a comment to first problem';
- is $problem2->comments->count, 1, 'added a comment to second problem';
-};
-
-$problem->comments->delete;
-$problem->delete;
-$user->comments->delete;
-$user->problems->delete;
-$user->delete;
-
-done_testing();
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 00026cd9f..f33fc97b4 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -17,31 +17,41 @@ use_ok( 'Open311' );
my $processor = Open311::PopulateServiceList->new( council_list => [] );
ok $processor, 'created object';
-
+my $body = FixMyStreet::App->model('DB::Body')->find_or_create( {
+ id => 1,
+ name => 'Body Numero Uno',
+} );
+$body->body_areas->find_or_create({
+ area_id => 1
+} );
+
+my $bromley = FixMyStreet::App->model('DB::Body')->find_or_create( {
+ id => 2482,
+ name => 'Bromley Council',
+} );
+$bromley->body_areas->find_or_create({
+ area_id => 2482
+} );
subtest 'check basic functionality' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check non open311 contacts marked as deleted' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => 'contact@example.com',
category => 'An old category',
confirmed => 1,
@@ -54,27 +64,23 @@ subtest 'check non open311 contacts marked as deleted' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 4, 'correct number of contacts';
- $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1, deleted => 1 } )->count();
+ $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1, deleted => 1 } )->count();
is $contact_count, 1, 'correct number of deleted contacts';
};
subtest 'check email changed if matching category' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '009',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -89,12 +95,8 @@ subtest 'check email changed if matching category' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -102,16 +104,16 @@ subtest 'check email changed if matching category' => sub {
is $contact->confirmed, 1, 'contact still confirmed';
is $contact->deleted, 0, 'contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check category name changed if updated' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -126,12 +128,8 @@ subtest 'check category name changed if updated' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -140,16 +138,16 @@ subtest 'check category name changed if updated' => sub {
is $contact->confirmed, 1, 'contact still confirmed';
is $contact->deleted, 0, 'contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check conflicting contacts not changed' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => 'existing@example.com',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -164,7 +162,7 @@ subtest 'check conflicting contacts not changed' => sub {
my $contact2 = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -179,12 +177,8 @@ subtest 'check conflicting contacts not changed' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -199,7 +193,7 @@ subtest 'check conflicting contacts not changed' => sub {
is $contact2->confirmed, 1, 'second contact contact still confirmed';
is $contact2->deleted, 0, 'second contact contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 4, 'correct number of contacts';
};
@@ -225,7 +219,7 @@ subtest 'check meta data population' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -243,12 +237,8 @@ subtest 'check meta data population' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
- area_id => 2482
- } );
-
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $bromley );
$processor->_current_service( { service_code => 100 } );
$processor->_add_meta_to_contact( $contact );
@@ -409,7 +399,7 @@ for my $test (
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '100',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -432,12 +422,8 @@ for my $test (
my $service_list = get_xml_simple_object( $services_xml );
$service_list = { service => [ $service_list->{ service } ] };
- my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
- area_id => 1
- } );
-
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
@@ -487,7 +473,7 @@ subtest 'check attribute ordering' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -505,12 +491,8 @@ subtest 'check attribute ordering' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
- area_id => 1
- } );
-
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->_current_service( { service_code => 100 } );
$processor->_add_meta_to_contact( $contact );
@@ -593,7 +575,7 @@ subtest 'check bromely skip code' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -611,12 +593,8 @@ subtest 'check bromely skip code' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
- area_id => 2482
- } );
-
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $bromley );
$processor->_current_service( { service_code => 100 } );
$processor->_add_meta_to_contact( $contact );
@@ -636,9 +614,7 @@ subtest 'check bromely skip code' => sub {
is_deeply $contact->extra, $extra, 'only non std bromley meta data saved';
- $council->area_id(1);
-
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->_add_meta_to_contact( $contact );
$extra = [