Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 1; |
20 |
use Test::More tests => 2; |
21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 29-35
use Mojolicious::Lite;
Link Here
|
29 |
use Try::Tiny; |
29 |
use Try::Tiny; |
30 |
|
30 |
|
31 |
my $config = { |
31 |
my $config = { |
32 |
'log4perl.logger.rest.Koha.REST.V1' => 'ERROR, TEST', |
32 |
'log4perl.logger.rest.Koha.REST.V1' => 'DEBUG, TEST', |
33 |
'log4perl.appender.TEST' => 'Log::Log4perl::Appender::TestBuffer', |
33 |
'log4perl.appender.TEST' => 'Log::Log4perl::Appender::TestBuffer', |
34 |
'log4perl.appender.TEST.layout' => 'SimpleLayout', |
34 |
'log4perl.appender.TEST.layout' => 'SimpleLayout', |
35 |
}; |
35 |
}; |
Lines 103-108
subtest 'default_exception_handling() tests' => sub {
Link Here
|
103 |
}; |
103 |
}; |
104 |
}; |
104 |
}; |
105 |
|
105 |
|
|
|
106 |
subtest 'log_request() and log_response() tests' => sub { |
107 |
plan tests => 12; |
108 |
|
109 |
$t->app->routes->get('/response/log/json' => sub { |
110 |
$_[0]->render( status => 200, json => { wow => "it worked" } ) |
111 |
}); |
112 |
$t->app->routes->post('/response/log/other' => sub { |
113 |
$_[0]->render( status => 200, data => '<b>ERROR!</b>' ) |
114 |
}); |
115 |
$t->app->routes->put('/response/log/500' => sub { |
116 |
die; |
117 |
}); |
118 |
|
119 |
my $appender = Log::Log4perl->appenders->{TEST}; |
120 |
|
121 |
$t->get_ok('/response/log/json') |
122 |
->status_is(200) |
123 |
->json_is('/wow' => 'it worked'); |
124 |
is($appender->buffer, |
125 |
"DEBUG - Request JSON body null\nDEBUG - Request params {}\n". |
126 |
"DEBUG - Rendering response {\"json\":{\"wow\":\"it worked\"},\"status\":200}\n", |
127 |
'Found request and response content' |
128 |
); |
129 |
$appender->{appender}->{buffer} = undef; |
130 |
|
131 |
$t->post_ok('/response/log/other' => form => { param1 => "value" }) |
132 |
->status_is(200) |
133 |
->content_is('<b>ERROR!</b>'); |
134 |
is($appender->buffer, |
135 |
"DEBUG - Request JSON body null\nDEBUG - Request params {\"param1\":\"value\"}\n". |
136 |
"DEBUG - Rendering response {\"data\":\"<b>ERROR!<\\/b>\",\"status\":200}\n", |
137 |
'Found request and response content' |
138 |
); |
139 |
$appender->{appender}->{buffer} = undef; |
140 |
|
141 |
$t->put_ok('/response/log/500' => json => { param2 => "value" }) |
142 |
->status_is(500) |
143 |
->json_is('/error' => 'Something went wrong, check the logs.'); |
144 |
like($appender->buffer, |
145 |
qr{DEBUG - Request JSON body \{"param2":"value"\}\nDEBUG - Request params \{\} |
146 |
ERROR - Died at .* line \d+\.\n |
147 |
DEBUG - Rendering response \{"json":\{"error":"Something went wrong, check the logs\."\},"status":500\} |
148 |
}msi, |
149 |
'Found request and response content' |
150 |
); |
151 |
$appender->{appender}->{buffer} = undef; |
152 |
|
153 |
}; |
154 |
|
106 |
sub add_default_exception_routes { |
155 |
sub add_default_exception_routes { |
107 |
my ($t) = @_; |
156 |
my ($t) = @_; |
108 |
|
157 |
|
109 |
- |
|
|