From 7b2fb6cd9934fae59d89cfeabf5260a54713c26f Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 15 Jun 2011 16:53:28 +0100 Subject: update report display to handle new statuses --- t/app/controller/report_display.t | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 1f857a387..746f68cf6 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -119,6 +119,55 @@ subtest "test a good report" => sub { is $update_form->value($_), $fields{$_}, "$_ value" for keys %fields; }; +for my $test ( + { + state => 'confirmed', + display => 1, + }, + { + state => 'investigating', + display => 1, + }, + { + state => 'planned', + display => 1, + }, + { + state => 'in progress', + display => 1, + }, + { + state => 'fixed', + display => 0, + }, + { + state => 'fixed - council', + display => 0, + }, + { + state => 'fixed - user', + display => 0, + }, + { + state => 'will not fix', + display => 0, + }, +) { + subtest "check fixed checkbox display for state $test->{state}" => sub { + $report->state( $test->{state} ); + $report->update; + $mech->get_ok("/report/$report_id"); + + my $update_form = $mech->form_name('updateForm'); + + if ( $test->{display} ) { + ok defined $update_form->find_input('#form_fixed', 'checkbox'), "fixed checkbox display"; + } else { + is $update_form->find_input('#form_fixed', 'checkbox'), undef, "fixed checkbox display"; + } + }; +} + foreach my $meta ( { anonymous => 'f', -- cgit v1.2.3 From c9773705e4c611363474144f69182ad421187242 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 16 Jun 2011 12:17:35 +0100 Subject: handle new states in report display and updating --- t/app/controller/report_display.t | 73 +++++++++++++-------------------------- 1 file changed, 24 insertions(+), 49 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 746f68cf6..d20774560 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -119,55 +119,6 @@ subtest "test a good report" => sub { is $update_form->value($_), $fields{$_}, "$_ value" for keys %fields; }; -for my $test ( - { - state => 'confirmed', - display => 1, - }, - { - state => 'investigating', - display => 1, - }, - { - state => 'planned', - display => 1, - }, - { - state => 'in progress', - display => 1, - }, - { - state => 'fixed', - display => 0, - }, - { - state => 'fixed - council', - display => 0, - }, - { - state => 'fixed - user', - display => 0, - }, - { - state => 'will not fix', - display => 0, - }, -) { - subtest "check fixed checkbox display for state $test->{state}" => sub { - $report->state( $test->{state} ); - $report->update; - $mech->get_ok("/report/$report_id"); - - my $update_form = $mech->form_name('updateForm'); - - if ( $test->{display} ) { - ok defined $update_form->find_input('#form_fixed', 'checkbox'), "fixed checkbox display"; - } else { - is $update_form->find_input('#form_fixed', 'checkbox'), undef, "fixed checkbox display"; - } - }; -} - foreach my $meta ( { anonymous => 'f', @@ -284,6 +235,30 @@ for my $test ( banner_text => 'This problem has been fixed.', fixed => 1 }, + { + description => 'user fixed report', + date => DateTime->now, + state => 'fixed - user', + banner_id => 'fixed', + banner_text => 'This problem has been fixed.', + fixed => 1 + }, + { + description => 'council fixed report', + date => DateTime->now, + state => 'fixed - council', + banner_id => 'fixed', + banner_text => 'This problem has been fixed.', + fixed => 1 + }, + { + description => 'closed report', + date => DateTime->now, + state => 'will not fix', + banner_id => '', + banner_text => '', + fixed => 0 + }, ) { subtest "banner for $test->{description}" => sub { $report->confirmed( $test->{date}->ymd . ' ' . $test->{date}->hms ); -- cgit v1.2.3 From 4d40d4632325a999b66dee1db36841dfeb60bcda Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 16 Jun 2011 12:40:39 +0100 Subject: rename will not fix to closed --- t/app/controller/report_display.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index d20774560..5c66200c8 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -254,7 +254,7 @@ for my $test ( { description => 'closed report', date => DateTime->now, - state => 'will not fix', + state => 'closed', banner_id => '', banner_text => '', fixed => 0 -- cgit v1.2.3 From 630ed304d67f83ecd8848bf665b03fd7c27fff46 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 21 Jun 2011 16:11:42 +0100 Subject: remove more hardcoded references to fixed --- t/app/controller/questionnaire.t | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index e56734bfc..af99a058e 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -204,7 +204,12 @@ foreach my $test ( } my $result; - $result = 'fixed' if $test->{fields}{been_fixed} eq 'Yes'; + $result = 'fixed - user' + if $test->{fields}{been_fixed} eq 'Yes' + && $test->{problem_state} ne 'fixed'; + $result = 'fixed' + if $test->{fields}{been_fixed} eq 'Yes' + && $test->{problem_state} eq 'fixed'; $result = 'confirmed' if $test->{fields}{been_fixed} eq 'No'; $result = 'unknown' if $test->{fields}{been_fixed} eq 'Unknown'; @@ -214,7 +219,7 @@ foreach my $test ( # Check the right HTML page has been returned $mech->content_like( qr/[^<]*Questionnaire/m ); $mech->content_contains( 'glad to hear it’s been fixed' ) - if $result eq 'fixed'; + if $result =~ /fixed/; $mech->content_contains( 'get some more information about the status of your problem' ) if $result eq 'unknown'; $mech->content_contains( "sorry to hear that" ) -- cgit v1.2.3 From 1002c330d3895887cfdb410e9e51dcc0e182473b Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 23 Jun 2011 11:28:08 +0100 Subject: display state dropdown on updates to authority users --- t/app/controller/report_display.t | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 5c66200c8..49b524b44 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -255,8 +255,8 @@ for my $test ( description => 'closed report', date => DateTime->now, state => 'closed', - banner_id => '', - banner_text => '', + banner_id => 'closed', + banner_text => 'This problem has been closed.', fixed => 0 }, ) { @@ -284,6 +284,31 @@ for my $test ( }; } +for my $test ( + { + desc => 'no state dropdown if user not from authority', + from_authority => 0, + }, + { + desc => 'state dropdown if user from authority', + from_authority => 1, + }, +) { + subtest $test->{desc} => sub { + $mech->log_in_ok( $user->email ); + $user->from_authority( $test->{from_authority} ); + $user->update; + + $mech->get_ok("/report/$report_id"); + my $fields = $mech->visible_form_values( 'updateForm' ); + if ( $test->{from_authority} ) { + ok $fields->{state}; + } else { + ok !$fields->{state}; + } + }; +} + # tidy up $mech->delete_user('test@example.com'); done_testing(); -- cgit v1.2.3 From 59e5a595bd0a903f25eb6210209cec5afe1f699c Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 23 Jun 2011 14:06:03 +0100 Subject: prevent non authority users from changing the state on updates --- t/app/controller/report_updates.t | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 4dd1db737..bec81fb83 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -382,6 +382,40 @@ for my $test ( }; } +$report->state('confirmed'); +$report->update; + +subtest 'check non authority user cannot change set state' => sub { + $mech->log_in_ok( $user->email ); + $user->from_authority( 0 ); + $user->update; + + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok( { + form_number => 2, + fields => { + submit_update => 1, + id => $report_id, + name => $user->name, + rznvy => $user->email, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'this is a forbidden update', + state => 'fixed - council', + }, + }, + 'submitted with state', + ); + + is $mech->uri->path, "/report/update", "at /report/update"; + + my $errors = $mech->page_errors; + is_deeply $errors, [ 'There was a problem with your update. Please try again.' ], 'error message'; + + is $report->state, 'confirmed', 'state unchanged'; +}; + for my $test ( { desc => 'submit update for register user', -- cgit v1.2.3 From 159fa8ad9e2427d8b20586baec4c260a0c71b57c Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 23 Jun 2011 15:46:55 +0100 Subject: update problem status from update --- t/app/controller/report_updates.t | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index de3ff3a81..0812ddd81 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -416,6 +416,52 @@ subtest 'check non authority user cannot change set state' => sub { is $report->state, 'confirmed', 'state unchanged'; }; +for my $test ( + { + desc => 'from authority user marks report as fixed', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to fixed', + state => 'fixed', + }, + state => 'fixed - council', + }, +) { + subtest $test->{desc} => sub { + $report->comments->delete; + + $mech->log_in_ok( $user->email ); + $user->from_authority( 1 ); + $user->update; + + $mech->get_ok("/report/$report_id"); + + $mech->submit_form_ok( + { + with_fields => $test->{fields}, + }, + 'submit update' + ); + + my $update = $report->comments->first; + ok $update, 'found update'; + is $update->text, $test->{fields}->{update}, 'update text'; + is $update->problem_state, $test->{state}, 'problem state set'; + + $report->discard_changes; + is $report->state, $test->{state}, 'state set'; + }; +} + +$user->from_authority(0); +$user->update; + +$report->state('confirmed'); +$report->update; + for my $test ( { desc => 'submit update for register user', -- cgit v1.2.3 From 46848a1dd7a7e33cb8953df334f434d0450b5651 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 23 Jun 2011 16:07:43 +0100 Subject: in progress banner --- t/app/controller/report_display.t | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 49b524b44..fc844e31c 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -259,6 +259,30 @@ for my $test ( banner_text => 'This problem has been closed.', fixed => 0 }, + { + description => 'investigating report', + date => DateTime->now, + state => 'investigating', + banner_id => 'progress', + banner_text => 'This problem is in progress.', + fixed => 0 + }, + { + description => 'planned report', + date => DateTime->now, + state => 'planned', + banner_id => 'progress', + banner_text => 'This problem is in progress.', + fixed => 0 + }, + { + description => 'in progressreport', + date => DateTime->now, + state => 'in progress', + banner_id => 'progress', + banner_text => 'This problem is in progress.', + fixed => 0 + }, ) { subtest "banner for $test->{description}" => sub { $report->confirmed( $test->{date}->ymd . ' ' . $test->{date}->hms ); -- cgit v1.2.3 From fb56c38856fe33c971903ab0efde1cf5d4829426 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 23 Jun 2011 16:34:19 +0100 Subject: check that state is permitted --- t/app/controller/report_updates.t | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index e5495ebf1..45e8e8c57 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -416,6 +416,39 @@ subtest 'check non authority user cannot change set state' => sub { is $report->state, 'confirmed', 'state unchanged'; }; +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_authority( 1 ); + $user->update; + + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok( { + form_number => 2, + fields => { + submit_update => 1, + id => $report_id, + name => $user->name, + rznvy => $user->email, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'this is a forbidden update', + state => $state, + }, + }, + 'submitted with state', + ); + + is $mech->uri->path, "/report/update", "at /report/update"; + + my $errors = $mech->page_errors; + is_deeply $errors, [ 'There was a problem with your update. Please try again.' ], 'error message'; + + is $report->state, 'confirmed', 'state unchanged'; + }; +} + for my $test ( { desc => 'from authority user marks report as fixed', -- cgit v1.2.3 From 7d097bb489deea35ef4fda6002a0d6936bf6b649 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 23 Jun 2011 17:07:10 +0100 Subject: indicate changes state in update meta information --- t/app/controller/report_updates.t | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 45e8e8c57..5d6f902e3 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -450,6 +450,54 @@ for my $state ( qw/unconfirmed hidden partial/ ) { } for my $test ( + { + desc => 'from authority user marks report as investigating', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to investigating', + state => 'investigating', + }, + state => 'investigating', + }, + { + desc => 'from authority user marks report as planned', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to planned', + state => 'planned', + }, + state => 'planned', + }, + { + desc => 'from authority user marks report as in progress', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to in progress', + state => 'in progress', + }, + state => 'in progress', + }, + { + desc => 'from authority user marks report as closed', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to closed', + state => 'closed', + }, + state => 'closed', + }, { desc => 'from authority user marks report as fixed', fields => { @@ -484,6 +532,9 @@ for my $test ( is $update->text, $test->{fields}->{update}, 'update text'; is $update->problem_state, $test->{state}, 'problem state set'; + my $update_meta = $mech->extract_update_metas; + like $update_meta->[0], qr/marked as $test->{fields}->{state}$/, 'update meta includes state change'; + $report->discard_changes; is $report->state, $test->{state}, 'state set'; }; -- cgit v1.2.3 From 8deb709fa2d44bcbaba54734f7f4f4385980d8df Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 23 Jun 2011 17:11:36 +0100 Subject: add extra states to problem count --- t/app/controller/admin.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index ba5095cea..51c55c323 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -77,7 +77,7 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( ); subtest 'check summary counts' => sub { - my $problems = FixMyStreet::App->model('DB::Problem')->search( { state => { -in => [qw/confirmed fixed/] } } ); + my $problems = FixMyStreet::App->model('DB::Problem')->search( { state => { -in => [qw/confirmed fixed closed investigating planned/, 'in progress', 'fixed - user', 'fixed - council'] } } ); my $problem_count = $problems->count; $problems->update( { cobrand => '' } ); -- cgit v1.2.3 From a20fc533b0f10646814742f1348c5f9141217efa Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Mon, 27 Jun 2011 11:03:57 +0100 Subject: change to use from_council in users table and store the council id in there so we can check that the problem is for the council the user is from --- t/app/controller/report_display.t | 19 +++++++++++++------ t/app/controller/report_updates.t | 8 ++++---- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index fc844e31c..23b76fbc4 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -311,24 +311,31 @@ for my $test ( for my $test ( { desc => 'no state dropdown if user not from authority', - from_authority => 0, + from_council => 0, + no_state => 1, }, { desc => 'state dropdown if user from authority', - from_authority => 1, + from_council => 2504, + no_state => 0, + }, + { + desc => 'no state dropdown if user not from same council as problem', + from_council => 2505, + no_state => 1, }, ) { subtest $test->{desc} => sub { $mech->log_in_ok( $user->email ); - $user->from_authority( $test->{from_authority} ); + $user->from_council( $test->{from_council} ); $user->update; $mech->get_ok("/report/$report_id"); my $fields = $mech->visible_form_values( 'updateForm' ); - if ( $test->{from_authority} ) { - ok $fields->{state}; - } else { + if ( $test->{no_state} ) { ok !$fields->{state}; + } else { + ok $fields->{state}; } }; } diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index f0916610b..35e8b9e5f 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -387,7 +387,7 @@ $report->update; subtest 'check non authority user cannot change set state' => sub { $mech->log_in_ok( $user->email ); - $user->from_authority( 0 ); + $user->from_council( 0 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -419,7 +419,7 @@ subtest 'check non authority user cannot change set state' => sub { 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_authority( 1 ); + $user->from_council( 2504 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -515,7 +515,7 @@ for my $test ( $report->comments->delete; $mech->log_in_ok( $user->email ); - $user->from_authority( 1 ); + $user->from_council( 2504 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -540,7 +540,7 @@ for my $test ( }; } -$user->from_authority(0); +$user->from_council(0); $user->update; $report->state('confirmed'); -- cgit v1.2.3 From 3d181cebab78ebe87242d4bb4a9afb48ca9aa524 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Mon, 27 Jun 2011 12:35:12 +0100 Subject: Display council name next to updates from council users --- t/app/controller/report_updates.t | 2 ++ 1 file changed, 2 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 35e8b9e5f..16165e8ae 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -534,6 +534,8 @@ for my $test ( my $update_meta = $mech->extract_update_metas; like $update_meta->[0], qr/marked as $test->{fields}->{state}$/, 'update meta includes state change'; + like $update_meta->[0], qr{Test User \(Westminster City Council\)}, 'update meta includes council name'; + $mech->content_contains( 'Test User (<strong>Westminster City Council</strong>)', 'council name in bold'); $report->discard_changes; is $report->state, $test->{state}, 'state set'; -- cgit v1.2.3 From ef93992a2abbb3c800a2d6bbc112b284c4e227a6 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Mon, 27 Jun 2011 16:36:22 +0100 Subject: user searching and editing --- t/app/controller/admin.t | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 51c55c323..2ada0d2ea 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -721,6 +721,98 @@ subtest 'report search' => sub { $mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $r_id \s* </td>}xs ); }; +subtest 'user search' => sub { + $mech->get_ok('/admin/search_users'); + $mech->get_ok('/admin/search_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->content_like( qr{user_edit/$u_id">Edit</a>} ); + + $user->from_council(2509); + $user->update; + $mech->get_ok('/admin/search_users?search=2509' ); + $mech->content_contains(2509); +}; + +$log_entries = FixMyStreet::App->model('DB::AdminLog')->search( + { + object_type => 'user', + object_id => $user->id + }, + { + order_by => { -desc => 'id' }, + } +); + +is $log_entries->count, 0, 'no admin log entries'; + +for my $test ( + { + desc => 'edit user name', + fields => { + name => 'Test User', + email => 'test@example.com', + council => 2509, + }, + changes => { + name => 'Changed User', + }, + log_count => 1, + log_entries => [qw/edit/], + }, + { + desc => 'edit user email', + fields => { + name => 'Changed User', + email => 'test@example.com', + council => 2509, + }, + changes => { + email => 'changed@example.com', + }, + log_count => 2, + log_entries => [qw/edit edit/], + }, + { + desc => 'edit user council', + fields => { + name => 'Changed User', + email => 'changed@example.com', + council => 2509, + }, + changes => { + council => 2607, + }, + log_count => 3, + log_entries => [qw/edit edit edit/], + }, +) { + subtest $test->{desc} => sub { + $mech->get_ok( '/admin/user_edit/' . $user->id ); + + my $visible = $mech->visible_form_values; + is_deeply $visible, $test->{fields}, 'expected user'; + + my $expected = { + %{ $test->{fields} }, + %{ $test->{changes} } + }; + + $mech->submit_form_ok( { with_fields => $expected } ); + + $visible = $mech->visible_form_values; + is_deeply $visible, $expected, 'user updated'; + + $mech->content_contains( 'Updated!' ); + }; +} + + $mech->delete_user( $user ); $mech->delete_user( $user2 ); $mech->delete_user( $user3 ); -- cgit v1.2.3 From 0c3c4a0be17118ff4d8e01168df5938a947f28f6 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Mon, 27 Jun 2011 17:28:07 +0100 Subject: council users should be able to set state to confirmed --- t/app/controller/report_updates.t | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 16165e8ae..72006dca8 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -510,6 +510,18 @@ for my $test ( }, state => 'fixed - council', }, + { + desc => 'from authority user marks report as confirmed', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to investigating', + state => 'confirmed', + }, + state => 'confirmed', + }, ) { subtest $test->{desc} => sub { $report->comments->delete; -- cgit v1.2.3 From 2c66aa1aa7c6c07c2146ebbccbf0b25f2ea97a3e Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Tue, 28 Jun 2011 10:30:58 +0100 Subject: display update marked as fixed text on questionnaire for all fixed states --- t/app/controller/questionnaire.t | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index af99a058e..ecb243709 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -255,6 +255,55 @@ foreach my $test ( }; } + +for my $test ( + { + state => 'confirmed', + fixed => 0 + }, + { + state => 'planned', + fixed => 0 + }, + { + state => 'in progress', + fixed => 0 + }, + { + state => 'investigating', + fixed => 0 + }, + { + state => 'closed', + fixed => 0 + }, + { + state => 'fixed', + fixed => 1 + }, + { + state => 'fixed - council', + fixed => 1 + }, + { + state => 'fixed - user', + fixed => 1 + }, +) { + subtest "correct fixed text for state $test->{state}" => sub { + $report->state ( $test->{state} ); + $report->update; + + $mech->get_ok("/Q/" . $token->token); + $mech->title_like( qr/Questionnaire/ ); + if ( $test->{fixed} ) { + $mech->content_contains('An update marked this problem as fixed'); + } else { + $mech->content_lacks('An update marked this problem as fixed'); + } + }; +} + # EHA extra checking ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; -- cgit v1.2.3 From f301d83e6bd7546b2f2a80067313dd17502581f8 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Tue, 28 Jun 2011 13:23:09 +0100 Subject: store correct old state in questionnaire when creator marks problem as fixed --- t/app/controller/report_updates.t | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 72006dca8..49bfc0d1b 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -786,6 +786,34 @@ foreach my $test ( }, changed => { update => 'Update from owner' }, initial_banner => '', + initial_state => 'confirmed', + alert => 1, # we signed up for alerts before, do not unsign us + anonymous => 0, + answered => 0, + path => '/report/update', + content => +"Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?", + }, + { + desc => 'logged in reporter submits update and marks in progress problem fixed', + initial_values => { + name => 'Test User', + may_show_name => 1, + add_alert => 1, + photo => '', + update => '', + fixed => undef, + }, + email => 'test@example.com', + fields => { + submit_update => 1, + update => 'update from owner', + add_alert => undef, + fixed => 1, + }, + changed => { update => 'Update from owner' }, + initial_banner => ' This problem is in progress. ', + initial_state => 'in progress', alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, answered => 0, @@ -813,6 +841,7 @@ foreach my $test ( }, changed => { update => 'Update from owner' }, initial_banner => '', + initial_state => 'confirmed', alert => 1, # we signed up for alerts before, do not unsign us anonymous => 0, answered => 1, @@ -831,7 +860,7 @@ foreach my $test ( ok( $_->delete, 'deleted comment ' . $_->id ) for $report->comments; $report->discard_changes; - $report->state('confirmed'); + $report->state( $test->{initial_state} ); $report->update; my $questionnaire; @@ -873,6 +902,8 @@ foreach my $test ( my $results = { %{ $test->{fields} }, %{ $test->{changed} }, }; + $report->discard_changes; + my $update = $report->comments->first; ok $update, 'found update'; is $update->text, $results->{update}, 'update text'; @@ -880,6 +911,8 @@ foreach my $test ( is $update->state, 'confirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; + is $report->state, 'fixed - user', 'report state'; + SKIP: { skip( 'not answering questionnaire', 5 ) if $questionnaire; @@ -899,6 +932,8 @@ foreach my $test ( ok $questionnaire, 'questionnaire exists'; ok $questionnaire->ever_reported, 'ever reported is yes'; + is $questionnaire->old_state(), $test->{initial_state}, 'questionnaire old state'; + is $questionnaire->new_state(), 'fixed - user', 'questionnaire new state'; }; if ($questionnaire) { -- cgit v1.2.3 From 96da0c04218644450f141f20c1dee4247a0ed8fe Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Tue, 28 Jun 2011 14:51:17 +0100 Subject: correctly set mark_open/fixed in questionnaire generates updates --- t/app/controller/questionnaire.t | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index ecb243709..af3b373ac 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -240,6 +240,16 @@ foreach my $test ( { problem_id => $report->id } ); is $c->text, $test->{fields}{update} || $test->{comment}; + if ( $result =~ /fixed/ ) { + ok $c->mark_fixed, 'comment marked as fixed'; + ok !$c->mark_open, 'comment not marked as open'; + } elsif ( $result eq 'confirmed' ) { + ok $c->mark_open, 'comment marked as open'; + ok !$c->mark_fixed, 'comment not marked as fixed'; + } elsif ( $result eq 'unknown' ) { + ok !$c->mark_open, 'comment not marked as open'; + ok !$c->mark_fixed, 'comment not marked as fixed'; + } } # Reset questionnaire for next test -- cgit v1.2.3 From cad4d9856b13328fd1e64ff6b48ee47234741960 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Wed, 29 Jun 2011 17:54:26 +0100 Subject: make sure cobrand summary tests pass even if we have barnet entries in db --- t/app/controller/admin.t | 3 +++ 1 file changed, 3 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 2ada0d2ea..c5d253459 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -82,6 +82,8 @@ subtest 'check summary counts' => sub { my $problem_count = $problems->count; $problems->update( { cobrand => '' } ); + FixMyStreet::App->model('DB::Problem')->search( { council => 2489 } )->update( { council => 1 } ); + my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_new( { problem => $report, }); $q->whensent( \'ms_current_timestamp()' ); $q->in_storage ? $q->update : $q->insert; @@ -130,6 +132,7 @@ subtest 'check summary counts' => sub { $alert->cobrand(''); $alert->update; + FixMyStreet::App->model('DB::Problem')->search( { council => 1 } )->update( { council => 2489 } ); ok $mech->host('fixmystreet.com'); }; -- cgit v1.2.3 From b756440e4b5c0b356ee0d65d1647124317535c95 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 30 Jun 2011 16:53:56 +0100 Subject: some extra info on updates --- t/app/controller/admin.t | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 't/app/controller') diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index c5d253459..dcf45e983 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -639,6 +639,76 @@ for my $test ( }; } +for my $test ( + { + desc => 'user is problem owner', + problem_user => $user, + update_user => $user, + update_fixed => 0, + update_reopen => 0, + update_state => undef, + user_council => undef, + content => 'user is problem owner', + }, + { + desc => 'user is council user', + problem_user => $user, + update_user => $user2, + update_fixed => 0, + update_reopen => 0, + update_state => undef, + user_council => 2504, + content => 'user is from same council as problem - 2504', + }, + { + desc => 'update changed problem state', + problem_user => $user, + update_user => $user2, + update_fixed => 0, + update_reopen => 0, + update_state => 'planned', + user_council => 2504, + content => 'Update changed problem state to planned', + }, + { + desc => 'update marked problem as fixed', + problem_user => $user, + update_user => $user3, + update_fixed => 1, + update_reopen => 0, + update_state => undef, + user_council => undef, + content => 'Update marked problem as fixed', + }, + { + desc => 'update reopened problem', + problem_user => $user, + update_user => $user, + update_fixed => 0, + update_reopen => 1, + update_state => undef, + user_council => undef, + content => 'Update reopened problem', + }, +) { + subtest $test->{desc} => sub { + $report->user( $test->{problem_user} ); + $report->update; + + $update->user( $test->{update_user} ); + $update->problem_state( $test->{update_state} ); + $update->mark_fixed( $test->{update_fixed} ); + $update->mark_open( $test->{update_reopen} ); + $update->update; + + $test->{update_user}->from_council( $test->{user_council} ); + $test->{update_user}->update; + + $mech->get_ok('/admin/update_edit/' . $update->id ); + $mech->content_contains( $test->{content} ); + }; +} + subtest 'editing update email creates new user if required' => sub { my $user = FixMyStreet::App->model('DB::User')->find( { email => 'test4@example.com' } -- cgit v1.2.3 From e1801441beb37f37857c925a3c8c889653da4fe9 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Wed, 27 Jul 2011 13:54:46 +0100 Subject: allow council user to update state on problem sent to multiple councils --- t/app/controller/report_display.t | 17 +++++++++++++++++ t/app/controller/report_updates.t | 21 ++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 23b76fbc4..a70d5b9e9 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -313,16 +313,25 @@ for my $test ( desc => 'no state dropdown if user not from authority', from_council => 0, no_state => 1, + report_council => '2504', }, { desc => 'state dropdown if user from authority', from_council => 2504, no_state => 0, + report_council => '2504', }, { desc => 'no state dropdown if user not from same council as problem', from_council => 2505, no_state => 1, + report_council => '2504', + }, + { + desc => 'state dropdown if user from authority and problem sent to multiple councils', + from_council => 2504, + no_state => 0, + report_council => '2504,2506', }, ) { subtest $test->{desc} => sub { @@ -330,6 +339,10 @@ for my $test ( $user->from_council( $test->{from_council} ); $user->update; + $report->discard_changes; + $report->council( $test->{report_council} ); + $report->update; + $mech->get_ok("/report/$report_id"); my $fields = $mech->visible_form_values( 'updateForm' ); if ( $test->{no_state} ) { @@ -340,6 +353,10 @@ for my $test ( }; } +$report->discard_changes; +$report->council( 2504 ); +$report->update; + # tidy up $mech->delete_user('test@example.com'); done_testing(); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 0a9c5db1f..d7b234a6e 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -539,14 +539,31 @@ for my $test ( may_show_name => 1, add_alert => 0, photo => '', - update => 'Set state to investigating', + update => 'Set state to confirmed', state => 'confirmed', }, state => 'confirmed', }, + { + desc => 'from authority user marks report sent to two councils as fixed', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to fixed', + state => 'fixed', + }, + state => 'fixed - council', + report_councils => '2504,2505', + }, ) { subtest $test->{desc} => sub { $report->comments->delete; + if ( $test->{ report_councils } ) { + $report->council( $test->{ report_councils } ); + $report->update; + } $mech->log_in_ok( $user->email ); $user->from_council( 2504 ); @@ -561,6 +578,7 @@ for my $test ( 'submit update' ); + $report->discard_changes; my $update = $report->comments->first; ok $update, 'found update'; is $update->text, $test->{fields}->{update}, 'update text'; @@ -580,6 +598,7 @@ $user->from_council(0); $user->update; $report->state('confirmed'); +$report->council('2504'); $report->update; for my $test ( -- cgit v1.2.3 From b2f1646d91c334bbb082db758a75a0fbc120b25d Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Wed, 27 Jul 2011 17:15:07 +0100 Subject: use the correct council separator character --- t/app/controller/report_display.t | 2 +- t/app/controller/report_updates.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index a70d5b9e9..93f3f0f65 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -331,7 +331,7 @@ for my $test ( desc => 'state dropdown if user from authority and problem sent to multiple councils', from_council => 2504, no_state => 0, - report_council => '2504,2506', + report_council => '2504|2506', }, ) { subtest $test->{desc} => sub { diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index d7b234a6e..ec4aa7342 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -555,7 +555,7 @@ for my $test ( state => 'fixed', }, state => 'fixed - council', - report_councils => '2504,2505', + report_councils => '2504|2505', }, ) { subtest $test->{desc} => sub { -- cgit v1.2.3 From fbf99125eb1a5544dd231d3cd55a1fcfb4cb2ae6 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Thu, 18 Aug 2011 22:56:00 +0100 Subject: use correct skip --- t/app/controller/report_import.t | 122 ++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 60 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 385445565..d6bff240c 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -264,69 +264,71 @@ subtest "Submit a correct entry (with location)" => sub { subtest "Submit a correct entry (with location) to cobrand" => sub { - skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 ) - unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami}; - mySociety::MaPit::configure('http://mapit.nuug.no/'); - ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; + SKIP: { + skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 20 ) + unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami}; + mySociety::MaPit::configure('http://mapit.nuug.no/'); + ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; - $mech->get_ok('/import'); - - $mech->submit_form_ok( # - { - with_fields => { - service => 'test-script', - lat => '59', - lon => '10', - name => 'Test User ll', - email => 'test-ll@example.com', - subject => 'Test report ll', - detail => 'This is a test report ll', - photo => $sample_file, - } - }, - "fill in form" - ); - - is_deeply( $mech->import_errors, [], "got no errors" ); - is $mech->content, 'SUCCESS', "Got success response"; - - # check that we have received the email - $mech->email_count_is(1); - my $email = $mech->get_email; - $mech->clear_emails_ok; - - my ($token_url) = $email->body =~ m{(http://\S+)}; - ok $token_url, "Found a token url $token_url"; - - # go to the token url - $mech->get_ok($token_url); - - # check that we are on '/report/new' - is $mech->uri->path, '/report/new', "sent to /report/new"; - - # check that fields are prefilled for us - is_deeply $mech->visible_form_values, - { - name => 'Test User ll', - title => 'Test report ll', - detail => 'This is a test report ll', - photo => '', - phone => '', - may_show_name => '1', - }, - "check imported fields are shown"; - - my $user = - FixMyStreet::App->model('DB::User') - ->find( { email => 'test-ll@example.com' } ); - ok $user, "Found a user"; + $mech->get_ok('/import'); - my $report = $user->problems->first; - is $report->state, 'partial', 'is still partial'; - is $report->title, 'Test report ll', 'title is correct'; - is $report->lang, 'nb', 'language is correct'; + $mech->submit_form_ok( # + { + with_fields => { + service => 'test-script', + lat => '59', + lon => '10', + name => 'Test User ll', + email => 'test-ll@example.com', + subject => 'Test report ll', + detail => 'This is a test report ll', + photo => $sample_file, + } + }, + "fill in form" + ); - $mech->delete_user($user); + is_deeply( $mech->import_errors, [], "got no errors" ); + is $mech->content, 'SUCCESS', "Got success response"; + + # check that we have received the email + $mech->email_count_is(1); + my $email = $mech->get_email; + $mech->clear_emails_ok; + + my ($token_url) = $email->body =~ m{(http://\S+)}; + ok $token_url, "Found a token url $token_url"; + + # go to the token url + $mech->get_ok($token_url); + + # check that we are on '/report/new' + is $mech->uri->path, '/report/new', "sent to /report/new"; + + # check that fields are prefilled for us + is_deeply $mech->visible_form_values, + { + name => 'Test User ll', + title => 'Test report ll', + detail => 'This is a test report ll', + photo => '', + phone => '', + may_show_name => '1', + }, + "check imported fields are shown"; + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test-ll@example.com' } ); + ok $user, "Found a user"; + + my $report = $user->problems->first; + is $report->state, 'partial', 'is still partial'; + is $report->title, 'Test report ll', 'title is correct'; + is $report->lang, 'nb', 'language is correct'; + + $mech->delete_user($user); + } }; done_testing(); -- cgit v1.2.3 From 61e6d5928be1bedb68607f8fa36f0d971711a3f8 Mon Sep 17 00:00:00 2001 From: Struan Donald <struan@exo.org.uk> Date: Fri, 19 Aug 2011 00:06:45 +0100 Subject: correct council list delimiter --- t/app/controller/report_display.t | 2 +- t/app/controller/report_updates.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 't/app/controller') diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 93f3f0f65..a70d5b9e9 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -331,7 +331,7 @@ for my $test ( desc => 'state dropdown if user from authority and problem sent to multiple councils', from_council => 2504, no_state => 0, - report_council => '2504|2506', + report_council => '2504,2506', }, ) { subtest $test->{desc} => sub { diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 9606afc8e..993c6758e 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -555,7 +555,7 @@ for my $test ( state => 'fixed', }, state => 'fixed - council', - report_councils => '2504|2505', + report_councils => '2504,2505', }, ) { subtest $test->{desc} => sub { -- cgit v1.2.3