Skip to content

Commit

Permalink
Route test without and with newline
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucker committed Mar 17, 2021
1 parent e681736 commit 69e6380
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Agrammon/Web/Routes.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ sub api-routes (Str $schema, $ws) {
}
operation 'exportPDF', -> LoggedIn $user {
request-body -> %params {
note "*** senderName:";
dd %params<senderName>;

my $pdf = $ws.get-pdf-export($user, %params);
# prevent header injection
my $filename = cleanup-filename "%params<datasetName>.pdf";
Expand Down
117 changes: 117 additions & 0 deletions t/routes-application-debug.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
use v6;

use Agrammon::Web::Routes;
use Agrammon::Web::Service;
use Agrammon::Web::SessionUser;
use Spreadsheet::XLSX;

use Cro::HTTP::Test;
use Test::Mock;
use Test;

# plan 14;

# routing tests related to application logic

sub make-fake-auth($role) {
mocked(
Agrammon::Web::SessionUser,
returning => { :id(42), :logged-in, }
)
}

my $role = 'user';
my $fake-auth = make-fake-auth($role);

my $fake-store = mocked(Agrammon::Web::Service,
returning => {
get-cfg => %( :title('Agrammon'), :version('SHL') ),
load-branch-data => ( 1, 2 ),
},
overriding => {
get-input-variables => {
%(
inputs => [
{
:variable("Livestock::DairyCow[]::Excretion::CMilk::milk_yield")
},
],
graphs => [],
reports => [],
),
},
get-output-variables => -> $user, $dataset-name {
%( :variable('x'), :value(2) )
},
get-excel-export => -> $user, %params {
# diag %params;
Spreadsheet::XLSX.new;
},
get-pdf-export => -> $user, %params {
# diag %params;
},
delete-instance => -> $user, $dataset-name, $instance, $pattern {
},
rename-instance => -> $user, $dataset-name, $old-name, $new-name, $variable-pattern {
},
order-instances => -> $user, $dataset-name, @instances {
%( sorted => 1 )
},
store-branch-data => -> $user, %data, $dataset-name {
%( stored => 1 )
},
store-input-comment => -> $user, $dataset-name, $variable, $comment {
},
store-data => -> $user, $dataset, $variable, $value, @branches?, @options?, $row? {
},
}
);


subtest 'Get PDF report without newline' => {
test-service routes($fake-store), :$fake-auth, {
test-given '/export/pdf', {
test post(
content-type => 'application/x-www-form-urlencoded',
body => {
:datasetName('TestSingle'),
:language('de'),
:type('submission'),
:senderName("Fritz ZauckerXXX4600 Olten"),
:farmNumber(42),
:farmSituation('Before'),
:recipientName('lawa'),
:recipientEmail('[email protected]'),
:comment('No comment'),
}),
status => 200;
};
check-mock $fake-store,
*.called('get-pdf-export', times => 1);
}
}

subtest 'Get PDF report with newline' => {
test-service routes($fake-store), :$fake-auth, {
test-given '/export/pdf', {
test post(
content-type => 'application/x-www-form-urlencoded',
body => {
:datasetName('TestSingle'),
:language('de'),
:type('submission'),
:senderName("Fritz Zaucker\n4600 Olten"),
:farmNumber(42),
:farmSituation('Before'),
:recipientName('lawa'),
:recipientEmail('[email protected]'),
:comment('No comment'),
}),
status => 500;
};
check-mock $fake-store,
*.called('get-pdf-export', times => 1);
}
}

done-testing;

0 comments on commit 69e6380

Please sign in to comment.