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

fix parsing of rating end points #1219

Merged
merged 1 commit into from
May 14, 2024
Merged
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
15 changes: 6 additions & 9 deletions lib/MetaCPAN/Server/Controller/Rating.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@ sub _mapping : Path('_mapping') : Args(0) {
$c->detach('/not_found');
}

sub find : Path('_search') : Args(0) {
sub find : Path('_search') : Args(0) : ActionClass('~Deserialize') {
my ( $self, $c, $scroll ) = @_;

my @hits;

# fake results for MetaCPAN::Client so it doesn't fail its tests
if ( ( $c->req->user_agent // '' )
=~ m{^MetaCPAN::Client-testing/([0-9.]+)} )
{
if ( ( $c->req->user_agent // '' ) =~ m{^MetaCPAN::Client/([0-9.]+)} ) {
if ( $1 <= 2.031001 ) {
my $query = $c->read_param('query');
my $query = $c->req->data->{'query'};
if ( $query
&& $query->[0]
&& $query->[0]{term}
&& ( $query->[0]{term}{distribution} // '' ) eq 'Moose' )
&& $query->{term}
&& ( $query->{term}{distribution} // '' ) eq 'Moose' )
{

push @hits,
Expand Down Expand Up @@ -72,7 +69,7 @@ sub find : Path('_search') : Args(0) {
} );
}

sub all : Path('') : Args(0) {
sub all : Path('') : Args(0) : ActionClass('~Deserialize') {
my ( $self, $c ) = @_;
$c->forward('find');
}
Expand Down
2 changes: 1 addition & 1 deletion t/server/controller/rating.t
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test_psgi app, sub {
ok(
$res = $cb->(
POST '/rating/_search',
'User-Agent' => 'MetaCPAN::Client-testing/2.031001',
'User-Agent' => 'MetaCPAN::Client/2.031001',
Content => '{"query":{"term":{"distribution":"Moose"}}}',
),
'POST /rating with MetaCPAN::Client test UA'
Expand Down