Improve test-lib & unit test (#1851)

This commit is contained in:
Christophe Maudoux 2019-07-21 23:21:20 +02:00
parent 3972861ba4
commit 81aa2fb37b
3 changed files with 33 additions and 9 deletions

View File

@ -239,11 +239,16 @@ sub notificationServer {
return $self->p->sendError( $req, $@, 500 ) if ($@);
}
elsif ( $req->method =~ /^GET$/i ) {
my $content = $req->content || '{}';
my $json;
eval { $json = from_json( $content, { allow_nonref => 1 } ) };
return $self->p->sendError( $req, "Unable to decode JSON file: $@",
400 )
if ($@);
my $notifs;
my $user = $json->{uid} || '';
( $notifs, $err ) =
# !!!!!! TO BE FIXED HERE => USE JSON TO SELECT USER IF EXISTS !!!!!!
eval { $self->notifObject->getNotifications( 'dwho') };
eval { $self->notifObject->getNotifications( $user ) };
return $self->p->sendError( $req, $@, 500 ) if ($@);
$res = [];
foreach ( keys %$notifs ) {

View File

@ -33,10 +33,11 @@ my $json2 = '{
}';
my $deljson = '{"uid":"dwho","reference":"testref2"}';
my $listjson = '{"uid":"dwho"}';
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'debug',
logLevel => 'error',
useSafeJail => 1,
notification => 1,
notificationServer => 1,
@ -78,14 +79,16 @@ ok(
$res = $client->_get(
'/notifications',
type => 'application/json',
length => length($listjson),
body => IO::String->new($listjson),
),
'List notifications'
);
ok( $res->[2]->[0] =~ /"result"\s*:\s*/, 'Result found' )
or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ /"reference":"testref"/, 'First notifications found' )
ok( $res->[2]->[0] =~ /"reference":"testref"/, 'First notification found' )
or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ /"reference":"testref2"/, 'Second notifications found' )
ok( $res->[2]->[0] =~ /"reference":"testref2"/, 'Second notification found' )
or print STDERR Dumper( $res->[2]->[0] );
count(4);

View File

@ -659,13 +659,27 @@ sub _get {
$args{remote_user} ? ( 'REMOTE_USER' => $args{remote_user} )
: ()
),
'REQUEST_METHOD' => $args{method} || 'GET',
'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ),
'REQUEST_METHOD' => $args{method}
|| 'GET',
'REQUEST_URI' => $path . ( $args{query} ? "?$args{query}" : '' ),
( $args{query} ? ( QUERY_STRING => $args{query} ) : () ),
'SCRIPT_NAME' => '',
'SERVER_NAME' => 'auth.example.com',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
(
$args{body}
? (
'psgi.input' => $args{body},
'psgix.input.buffered' => 0,
'CONTENT_LENGTH' => $args{length}
// scalar( ( stat $args{body} )[7] ),
'CONTENT_TYPE' => $args{type}
|| 'application/x-www-form-urlencoded',
)
: ()
),
( $args{custom} ? %{ $args{custom} } : () ),
}
);
@ -736,7 +750,9 @@ Call C<_get()> with method set to DELETE.
sub _delete {
my ( $self, $path, %args ) = @_;
$args{method} = 'DELETE';
return $args{body} ? $self->_post( $path, $args{body}, %args ) : $self->_get( $path, %args );
return $args{body}
? $self->_post( $path, $args{body}, %args )
: $self->_get( $path, %args );
}
=head4 _put( $path, $body, %args )