From 70a19127923a54eee5ad16f1bb1b97675273bceb Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 10 Oct 2018 09:59:05 +0100 Subject: Tweak dashboard test for less output. --- t/app/controller/dashboard.t | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 't/app') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 3a031bec3..26c19f596 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -236,15 +236,12 @@ FixMyStreet::override_config { sub test_table { my ($content, @expected) = @_; my $res = $categories->scrape( $mech->content ); - my $i = 0; + my @actual; foreach my $row ( @{ $res->{rows} }[1 .. 11] ) { - foreach my $col ( @{ $row->{cols} } ) { - is $col, $expected[$i++]; - } + push @actual, @{$row->{cols}} if $row->{cols}; } + is_deeply \@actual, \@expected; } -END { - restore_time; - done_testing(); -} +restore_time; +done_testing(); -- cgit v1.2.3 From 42e20f742bf80b41083c02fd9319159df65ffb9f Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 10 Oct 2018 09:58:15 +0100 Subject: Add cobrand hook for dashboard viewing permission. This allows a cobrand to e.g. as the test does, allow public access to dashboard CSV export for a body, but not otherwise. --- t/app/controller/dashboard.t | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 't/app') diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 26c19f596..a5fa8772a 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -1,4 +1,17 @@ use Test::MockTime ':all'; + +package FixMyStreet::Cobrand::Tester; +use parent 'FixMyStreet::Cobrand::Default'; +# Allow access if CSV export for a body, otherwise deny +sub dashboard_permission { + my $self = shift; + my $c = $self->{c}; + return 0 unless $c->get_param('export'); + return $c->get_param('body') || 0; +} + +package main; + use strict; use warnings; @@ -230,6 +243,25 @@ FixMyStreet::override_config { $mech->get_ok('/dashboard?export=1'); like $mech->res->header('Content-type'), qr'text/csv'; $mech->content_contains('Report ID'); + $mech->delete_header('Authorization'); + }; +}; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => 'tester', + MAPIT_URL => 'http://mapit.uk/', +}, sub { + subtest 'no body or export, 404' => sub { + $mech->get('/dashboard'); + is $mech->status, '404', 'No parameters, 404'; + $mech->get('/dashboard?export=1'); + is $mech->status, '404', 'If no body, 404'; + $mech->get("/dashboard?body=$body_id"); + is $mech->status, '404', 'If no export, 404'; + }; + + subtest 'body and export, okay' => sub { + $mech->get_ok("/dashboard?body=$body_id&export=1"); }; }; -- cgit v1.2.3