Skip to content

Commit

Permalink
Merge pull request #1219 from metacpan/haarg/fix-fake-rating
Browse files Browse the repository at this point in the history
fix parsing of rating end points
  • Loading branch information
haarg authored May 14, 2024
2 parents 1621321 + 6137a2a commit 3a565fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
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

0 comments on commit 3a565fe

Please sign in to comment.