diff options
Diffstat (limited to 't/app/controller/dashboard.t')
-rw-r--r-- | t/app/controller/dashboard.t | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 72fc00128..fd491b540 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -20,6 +20,8 @@ use strict; use warnings; use FixMyStreet::TestMech; +use File::Temp 'tempdir'; +use Path::Tiny; use Web::Scraper; set_absolute_time('2014-02-01T12:00:00'); @@ -70,6 +72,7 @@ foreach my $problem (@fixed_problems) { foreach my $problem (@closed_problems) { $problem->update({ state => 'closed' }); + $mech->create_comment_for_problem($problem, $counciluser, 'Name', 'in progress text', 0, 'confirmed', 'in progress'); $mech->create_comment_for_problem($problem, $counciluser, 'Title', 'text', 0, 'confirmed', 'closed'); } @@ -80,9 +83,15 @@ my $categories = scraper { }, }; +my $UPLOAD_DIR = tempdir( CLEANUP => 1 ); + FixMyStreet::override_config { ALLOWED_COBRANDS => 'no2fa', + COBRAND_FEATURES => { category_groups => { no2fa => 1 } }, MAPIT_URL => 'http://mapit.uk/', + PHOTO_STORAGE_OPTIONS => { + UPLOAD_DIR => $UPLOAD_DIR, + }, }, sub { subtest 'not logged in, redirected to login' => sub { @@ -173,13 +182,14 @@ FixMyStreet::override_config { subtest 'export as csv' => sub { $mech->create_problems_for_body(1, $body->id, 'Title', { detail => "this report\nis split across\nseveral lines", + category => 'Problem one', areas => ",$alt_area_id,2651,", }); $mech->get_ok('/dashboard?export=1'); my @rows = $mech->content_as_csv; is scalar @rows, 19, '1 (header) + 18 (reports) = 19 lines'; - is scalar @{$rows[0]}, 20, '20 columns present'; + is scalar @{$rows[0]}, 21, '21 columns present'; is_deeply $rows[0], [ @@ -188,6 +198,7 @@ FixMyStreet::override_config { 'Detail', 'User Name', 'Category', + 'Subcategory', 'Created', 'Confirmed', 'Acknowledged', @@ -206,15 +217,15 @@ FixMyStreet::override_config { ], 'Column headers look correct'; - is $rows[5]->[14], 'Trowbridge', 'Ward column is name not ID'; - is $rows[5]->[15], '529025', 'Correct Easting conversion'; - is $rows[5]->[16], '179716', 'Correct Northing conversion'; + is $rows[5]->[15], 'Trowbridge', 'Ward column is name not ID'; + is $rows[5]->[16], '529025', 'Correct Easting conversion'; + is $rows[5]->[17], '179716', 'Correct Northing conversion'; }; subtest 'export updates as csv' => sub { $mech->get_ok('/dashboard?updates=1&export=1'); my @rows = $mech->content_as_csv; - is scalar @rows, 15, '1 (header) + 14 (updates) = 15 lines'; + is scalar @rows, 18, '1 (header) + 17 (updates) = 18 lines'; is scalar @{$rows[0]}, 8, '8 columns present'; is_deeply $rows[0], @@ -235,19 +246,50 @@ FixMyStreet::override_config { subtest 'export as csv using token' => sub { $mech->log_out_ok; - $counciluser->set_extra_metadata('access_token', '1234567890abcdefgh'); + my $u = FixMyStreet::DB->resultset("User")->new({ password => '1234567890abcdefgh' }); + $counciluser->set_extra_metadata('access_token', $u->password); $counciluser->update(); $mech->get_ok('/dashboard?export=1'); like $mech->res->header('Content-type'), qr'text/html'; $mech->content_lacks('Report ID'); - $mech->add_header('Authorization', 'Bearer 1234567890abcdefgh'); + $mech->add_header('Authorization', 'Bearer ' . $counciluser->id . '-1234567890abcdefgh'); $mech->get_ok('/dashboard?export=1'); like $mech->res->header('Content-type'), qr'text/csv'; $mech->content_contains('Report ID'); $mech->delete_header('Authorization'); + + my $token = 'access_token=' . $counciluser->id . '-1234567890abcdefgh'; + $mech->get_ok("/dashboard?export=2&$token"); + is $mech->res->code, 202; + my $loc = $mech->res->header('Location'); + like $loc, qr{/dashboard/csv/.*\.csv$}; + $mech->get_ok("$loc?$token"); + like $mech->res->header('Content-type'), qr'text/csv'; + $mech->content_contains('Report ID'); }; + + subtest 'view status page' => sub { + # Simulate a partly done file + my $f = Path::Tiny->tempfile(SUFFIX => '.csv-part', DIR => path($UPLOAD_DIR, 'dashboard_csv', $counciluser->id)); + (my $name = $f->basename) =~ s/-part$//;; + + my $token = 'access_token=' . $counciluser->id . '-1234567890abcdefgh'; + $mech->get_ok("/dashboard/csv/$name?$token"); + is $mech->res->code, 202; + + $mech->log_in_ok( $counciluser->email ); + $mech->get_ok('/dashboard/status'); + $mech->content_contains('/dashboard/csv/www.example.org-body-' . $body->id . '-start_date-2014-01-02.csv'); + $mech->content_like(qr/$name\s*<br>0KB\s*<i>In progress/); + + $f->remove; + $mech->get_ok('/dashboard/status'); + $mech->content_contains('/dashboard/csv/www.example.org-body-' . $body->id . '-start_date-2014-01-02.csv'); + $mech->content_lacks('In progress'); + $mech->content_lacks('setTimeout'); + } }; FixMyStreet::override_config { |