aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/admin.t
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller/admin.t')
-rw-r--r--t/app/controller/admin.t178
1 files changed, 105 insertions, 73 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 9ec15ec21..e369968b4 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',
@@ -53,6 +53,7 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
used_map => 't',
name => 'Test User',
anonymous => 'f',
+ external_id => '13',
state => 'confirmed',
confirmed => $dt->ymd . ' ' . $dt->hms,
lang => 'en-gb',
@@ -84,7 +85,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()' );
@@ -93,7 +94,11 @@ subtest 'check summary counts' => sub {
my $alerts = FixMyStreet::App->model('DB::Alert')->search( { confirmed => { '>' => 0 } } );
my $a_count = $alerts->count;
- $mech->get_ok('/admin');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ }, sub {
+ $mech->get_ok('/admin');
+ };
$mech->title_like(qr/Summary/);
@@ -105,10 +110,9 @@ subtest 'check summary counts' => sub {
$mech->content_contains( "$q_count questionnaires sent" );
- SKIP: {
- skip( "Need 'barnet' in ALLOWED_COBRANDS config", 7 )
- unless FixMyStreet::Cobrand->exists('barnet');
-
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'barnet' ],
+ }, sub {
ok $mech->host('barnet.fixmystreet.com');
$mech->get_ok('/admin');
@@ -118,7 +122,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,36 +135,42 @@ 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;
$alert->cobrand('');
$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');
+FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ MAPIT_TYPES => [ 'UTA' ],
+ BASE_URL => 'http://www.example.org',
+}, sub {
+ $mech->get_ok('/admin/body/2650');
+};
$mech->content_contains('Aberdeen City Council');
$mech->content_like(qr{AB\d\d});
-$mech->content_contains("$host/around");
+$mech->content_contains("http://www.example.org/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 +200,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 +226,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 +266,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 +286,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');
};
@@ -563,7 +563,7 @@ foreach my $test (
$report->discard_changes;
if ( $report->state eq 'confirmed' ) {
- $mech->content_contains( 'type="submit" name="resend"', 'no resend button' );
+ $mech->content_contains( 'type="submit" name="resend"', 'resend button' );
} else {
$mech->content_lacks( 'type="submit" name="resend"', 'no resend button' );
}
@@ -845,6 +845,8 @@ for my $test (
};
}
+$mech->create_body_ok(2504, 'Westminster City Council');
+
for my $test (
{
desc => 'user is problem owner',
@@ -853,17 +855,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 +875,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 +885,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 +895,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 +909,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,41 +1035,47 @@ 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->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} );
+
+ $mech->get_ok('/admin/reports?search=' . $report->external_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=ref:' . $report->external_id);
+ $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} );
+
+ $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>} );
- $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/#update_$u_id">$u_id</a>} );
+ $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} );
+ $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id#update_$u_id"[^>]*>$u_id</a>} );
$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->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $r_id \s* </td>}xs );
+ $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->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id</a>} );
+ $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 +1085,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 +1125,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 +1147,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'test@example.com',
- council => 2509,
+ body => 2509,
flagged => undef,
},
changes => {
@@ -1145,15 +1157,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 +1175,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'changed@example.com',
- council => 2607,
+ body => 2607,
flagged => undef,
},
changes => {
@@ -1177,7 +1189,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'changed@example.com',
- council => 2607,
+ body => 2607,
flagged => 'on',
},
changes => {
@@ -1207,6 +1219,26 @@ for my $test (
};
}
+subtest "Test setting a report from unconfirmed to something else doesn't cause a front end error" => sub {
+ $report->update( { confirmed => undef, state => 'unconfirmed', non_public => 0 } );
+ $mech->get_ok("/admin/report_edit/$report_id");
+ $mech->submit_form_ok( { with_fields => { state => 'investigating' } } );
+ $report->discard_changes;
+ ok( $report->confirmed, 'report has a confirmed timestamp' );
+ $mech->get_ok("/report/$report_id");
+};
+
+subtest "Check admin_base_url" => sub {
+ my $rs = FixMyStreet::App->model('DB::Problem');
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($report->cobrand)->new();
+
+ is (FixMyStreet::App->model('DB::Problem')->get_admin_url(
+ $cobrand,
+ $report),
+ (sprintf 'https://secure.mysociety.org/admin/bci/report_edit/%d', $report_id),
+ 'get_admin_url OK');
+};
+
$mech->delete_user( $user );
$mech->delete_user( $user2 );
$mech->delete_user( $user3 );