diff options
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/dashboard.t | 45 | ||||
-rw-r--r-- | t/app/sendreport/angus.t | 56 |
2 files changed, 37 insertions, 64 deletions
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 3a031bec3..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,21 +243,37 @@ 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"); }; }; 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(); diff --git a/t/app/sendreport/angus.t b/t/app/sendreport/angus.t deleted file mode 100644 index 41379b4ff..000000000 --- a/t/app/sendreport/angus.t +++ /dev/null @@ -1,56 +0,0 @@ -use FixMyStreet::Test; - -use_ok("FixMyStreet::SendReport::Angus"); - -my $u = FixMyStreet::DB->resultset('User')->new( { email => 'test@example.org', name => 'A User' } ); - -my $p = FixMyStreet::DB->resultset('Problem')->new( { - latitude => 1, - longitude => 1, - title => 'title', - detail => 'detail', - user => $u, - id => 1, - name => 'A User', - cobrand => 'fixmystreet', -} ); - -my $angus = FixMyStreet::SendReport::Angus->new(); - -subtest 'parses authentication token correctly' => sub { - my $authxml = <<EOT; - <AuthenticateResponse> - - <AuthenticateResult> - TVRreUxqRTJPQzR5TlRVdU1qSjhNakF4Tmpvd01Ub3lNam94TlRvME16b3pPUT09VGhvdVNoYWx0Tm90UGFzcw== - </AuthenticateResult> - <success> - True - </success> - <message></message> - - </AuthenticateResponse> -EOT -; - is $angus->get_auth_token($authxml), 'TVRreUxqRTJPQzR5TlRVdU1qSjhNakF4Tmpvd01Ub3lNam94TlRvME16b3pPUT09VGhvdVNoYWx0Tm90UGFzcw==', 'token correct'; -}; - -subtest 'parses report external id correctly' => sub { - my $respxml = <<EOT; -<CreateRequestResponse> - - <CreateRequestResult> - <RequestId>7245</RequestId> - </CreateRequestResult> - - <success>True</success> - <message></message> - -</CreateRequestResponse> -EOT -; - is $angus->get_external_id($respxml), '7245', 'external id correct'; -}; - - -done_testing(); |