Skip to content

Commit

Permalink
fix parsing of rating end points
Browse files Browse the repository at this point in the history
The fake rating search end points need the Deserialize ActionClass to
parse their body.

Also, MetaCPAN::Client has a bug that prevents it from properly using
its testing user agent, so just give the results for normal MC::C UAs.
  • Loading branch information
haarg committed May 14, 2024
1 parent 37fe00c commit b528e58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions lib/MetaCPAN/Server/Controller/Rating.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ 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->params->{'query'};
if ( $query
&& $query->[0]
&& $query->[0]{term}
Expand Down Expand Up @@ -72,7 +70,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

0 comments on commit b528e58

Please sign in to comment.