Retrieve all notifications & Improve unit test (#2012)
This commit is contained in:
parent
3831b81255
commit
39f93b0eb0
|
@ -200,7 +200,7 @@ sub notifications {
|
|||
result => 1,
|
||||
count => $count,
|
||||
values => $res,
|
||||
total => $total
|
||||
total => $total
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -220,8 +220,15 @@ sub notifications {
|
|||
@r = sort { $a->{$f} cmp $b->{$f} } @r;
|
||||
}
|
||||
}
|
||||
return $self->sendJSONresponse( $req,
|
||||
{ result => 1, count => scalar(@r), values => \@r, total => $total } );
|
||||
return $self->sendJSONresponse(
|
||||
$req,
|
||||
{
|
||||
result => 1,
|
||||
count => scalar(@r),
|
||||
values => \@r,
|
||||
total => $total
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -343,7 +343,10 @@ sub notificationServer {
|
|||
}
|
||||
else {
|
||||
push @$res,
|
||||
{ "uid" => $json->{uid}, "reference" => $json->{reference} };
|
||||
{
|
||||
"uid" => $json->{uid},
|
||||
"reference" => ( $json->{reference} || $json->{ref} )
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use Test::More;
|
||||
use strict;
|
||||
use IO::String;
|
||||
use JSON qw(from_json);
|
||||
|
||||
BEGIN {
|
||||
require 't/test-lib.pm';
|
||||
|
@ -132,6 +133,36 @@ ok( $res->[2]->[0] =~ /"uid":"everyone"/, 'Wildcard found' )
|
|||
or print STDERR Dumper( $res->[2]->[0] );
|
||||
count(4);
|
||||
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/notifications/bad_uid', type => 'application/json',
|
||||
),
|
||||
'List notifications for bad uid'
|
||||
);
|
||||
ok(
|
||||
$res->[2]->[0] =~ /"reference":"testrefall"/,
|
||||
'Notification for all users found'
|
||||
) or print STDERR Dumper( $res->[2]->[0] );
|
||||
count(2);
|
||||
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/notifications/_all_', type => 'application/json',
|
||||
),
|
||||
'List ALL notifications'
|
||||
);
|
||||
ok( $json = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' );
|
||||
ok( scalar @{ $json->{result} } == 3, 'Three notifications found' )
|
||||
or print STDERR Dumper($json);
|
||||
|
||||
foreach ( @{$json->{result}} ) {
|
||||
ok( $_->{reference} =~ /^testref/, "Reference \'$_->{reference}\' found" )
|
||||
or print STDERR Dumper($json);
|
||||
ok( $_->{uid} =~ /^(dwho|everyone)$/, "UID \'$_->{uid}\' found" )
|
||||
or print STDERR Dumper($json);
|
||||
}
|
||||
count(9);
|
||||
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/notifications/dwho', type => 'application/json',
|
||||
|
|
Loading…
Reference in New Issue
Block a user