diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/dashboard.t | 14 | ||||
-rw-r--r-- | t/cobrand/bathnes.t | 22 | ||||
-rw-r--r-- | t/cobrand/bucks.t | 49 | ||||
-rw-r--r-- | t/cobrand/fixmystreet.t | 7 |
4 files changed, 55 insertions, 37 deletions
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 37903513c..ff8d1a9d5 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -167,12 +167,7 @@ FixMyStreet::override_config { areas => ",$alt_area_id,2651,", }); $mech->get_ok('/dashboard?export=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 19, '1 (header) + 18 (reports) = 19 lines'; is scalar @{$rows[0]}, 20, '20 columns present'; @@ -209,12 +204,7 @@ FixMyStreet::override_config { subtest 'export updates as csv' => sub { $mech->get_ok('/dashboard?updates=1&export=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 15, '1 (header) + 14 (updates) = 15 lines'; is scalar @{$rows[0]}, 8, '8 columns present'; diff --git a/t/cobrand/bathnes.t b/t/cobrand/bathnes.t index 4db2f058c..6586dcb96 100644 --- a/t/cobrand/bathnes.t +++ b/t/cobrand/bathnes.t @@ -64,12 +64,7 @@ subtest 'extra CSV columns are absent if permission not granted' => sub { $mech->get_ok('/dashboard?export=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; is scalar @{$rows[0]}, 20, '20 columns present'; @@ -125,12 +120,7 @@ subtest 'extra CSV columns are present if permission granted' => sub { $mech->get_ok('/dashboard?export=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 5, '1 (header) + 4 (reports) = 5 lines'; is scalar @{$rows[0]}, 24, '24 columns present'; @@ -194,13 +184,7 @@ subtest 'extra CSV columns are present if permission granted' => sub { $mech->get_ok('/dashboard?export=1&updates=1'); - open $data_handle, '<', \$mech->content; - $csv = Text::CSV->new( { binary => 1 } ); - @rows = (); - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } - + @rows = $mech->content_as_csv; is scalar @rows, 1, '1 (header) + 0 (updates)'; is scalar @{$rows[0]}, 10, '10 columns present'; is_deeply $rows[0], diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t index d9273fbf8..ba0a20ba9 100644 --- a/t/cobrand/bucks.t +++ b/t/cobrand/bucks.t @@ -6,6 +6,7 @@ my $mech = FixMyStreet::TestMech->new; my $body = $mech->create_body_ok(2217, 'Buckinghamshire', { send_method => 'Open311', api_key => 'key', endpoint => 'endpoint', jurisdiction => 'fms' }); +my $counciluser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $body); $mech->create_contact_ok(body_id => $body->id, category => 'Flytipping', email => "FLY"); $mech->create_contact_ok(body_id => $body->id, category => 'Potholes', email => "POT"); @@ -58,6 +59,10 @@ subtest 'flytipping on road sent to extra email' => sub { ($report) = $mech->create_problems_for_body(1, $body->id, 'On Road', { category => 'Potholes', cobrand => 'fixmystreet', latitude => 51.812244, longitude => -0.827363, + extra => { + contributed_as => 'another_user', + contributed_by => $counciluser->id, + }, }); subtest 'pothole on road not sent to extra email' => sub { @@ -172,6 +177,50 @@ for my $test ( }; } +subtest 'extra CSV columns are present' => sub { + $mech->log_in_ok( $counciluser->email ); + + $mech->get_ok('/dashboard?export=1'); + + my @rows = $mech->content_as_csv; + is scalar @rows, 4, '1 (header) + 3 (reports) = 4 lines'; + is scalar @{$rows[0]}, 21, '21 columns present'; + + is_deeply $rows[0], + [ + 'Report ID', 'Title', 'Detail', 'User Name', 'Category', + 'Created', 'Confirmed', 'Acknowledged', 'Fixed', 'Closed', + 'Status', 'Latitude', 'Longitude', 'Query', 'Ward', + 'Easting', 'Northing', 'Report URL', 'Site Used', + 'Reported As', 'Staff User', + ], + 'Column headers look correct'; + + is $rows[1]->[20], '', 'Staff User is empty if not made on behalf of another user'; + is $rows[2]->[20], $counciluser->email, 'Staff User is correct if made on behalf of another user'; + is $rows[3]->[20], '', 'Staff User is empty if not made on behalf of another user'; + + $mech->create_comment_for_problem($report, $counciluser, 'Staff User', 'Some update text', 'f', 'confirmed', undef, { + extra => { contributed_as => 'body' }}); + $mech->create_comment_for_problem($report, $counciluser, 'Other User', 'Some update text', 'f', 'confirmed', undef, { + extra => { contributed_as => 'another_user', contributed_by => $counciluser->id }}); + + $mech->get_ok('/dashboard?export=1&updates=1'); + + @rows = $mech->content_as_csv; + is scalar @rows, 3, '1 (header) + 2 (updates)'; + is scalar @{$rows[0]}, 9, '9 columns present'; + is_deeply $rows[0], + [ + 'Report ID', 'Update ID', 'Date', 'Status', 'Problem state', + 'Text', 'User Name', 'Reported As', 'Staff User', + ], + 'Column headers look correct'; + + is $rows[1]->[8], '', 'Staff User is empty if not made on behalf of another user'; + is $rows[2]->[8], $counciluser->email, 'Staff User is correct if made on behalf of another user'; +}; + }; done_testing(); diff --git a/t/cobrand/fixmystreet.t b/t/cobrand/fixmystreet.t index 57ab51198..b47269db4 100644 --- a/t/cobrand/fixmystreet.t +++ b/t/cobrand/fixmystreet.t @@ -59,12 +59,7 @@ FixMyStreet::override_config { }); $mech->get_ok('/reports/Birmingham/summary?csv=1'); - open my $data_handle, '<', \$mech->content; - my $csv = Text::CSV->new( { binary => 1 } ); - my @rows; - while ( my $row = $csv->getline( $data_handle ) ) { - push @rows, $row; - } + my @rows = $mech->content_as_csv; is scalar @rows, 101, '1 (header) + 100 (reports) = 101 lines'; is scalar @{$rows[0]}, 10, '10 columns present'; |