Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug route failure #358

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/backend-and-models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ jobs:

- name: Run backend tests
run: |
RAKULIB=inst#$GITHUB_WORKSPACE/.raku $GITHUB_WORKSPACE/.raku/bin/prove6 -l -v t
RAKULIB=inst#$GITHUB_WORKSPACE/.raku $GITHUB_WORKSPACE/.raku/bin/prove6 -l -v t/routes-application-debug.t
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;