Improve test-lib & unit test (#1851)

This commit is contained in:
Christophe Maudoux 2019-07-21 21:54:20 +02:00
parent 8c776c0c27
commit 34039ef7ef
2 changed files with 39 additions and 1 deletions

View File

@ -24,6 +24,8 @@ my $json2 = '{
"text": "This is a second test text"
}';
my $deljson = '{"uid":"dwho","reference":"testref"}';
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
@ -49,6 +51,42 @@ ok(
);
count(1);
ok(
$res = $client->_put(
'/notifications', IO::String->new($deljson),
type => 'application/json',
length => length($deljson)
),
'Try to delete notification with bad method'
);
ok( $res->[2]->[0] =~ /"error"\s*:\s*"Bad request"/, 'Bad method is refused' );
count(2);
ok(
$res = $client->_delete(
'/notifications',
type => 'application/json',
length => length($deljson),
body => IO::String->new($deljson),
),
'Delete notification'
);
ok( $res->[2]->[0] =~ /"result"\s*:\s*1/, 'Notification has been deleted' )
or print STDERR Dumper( $res->[2]->[0] );
count(2);
ok(
$res = $client->_post(
'/notifications', IO::String->new($json),
type => 'application/json',
length => length($json)
),
'Create notification'
);
ok( $res->[2]->[0] =~ /"result"\s*:\s*1/, 'Notification has been inserted' )
or print STDERR Dumper( $res->[2]->[0] );
count(2);
ok(
$res = $client->_post(
'/notifications', IO::String->new($json2),

View File

@ -736,7 +736,7 @@ Call C<_get()> with method set to DELETE.
sub _delete {
my ( $self, $path, %args ) = @_;
$args{method} = 'DELETE';
return $self->_get( $path, %args );
return $args{body} ? $self->_post( $path, $args{body}, %args ) : $self->_get( $path, %args );
}
=head4 _put( $path, $body, %args )