File: scroll.t

package info (click to toggle)
libmetacpan-client-perl 2.033000-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 552 kB
  • sloc: perl: 2,564; makefile: 6
file content (39 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!perl

use strict;
use warnings;

use Test::More tests => 6;
use Ref::Util qw< is_hashref >;
use HTTP::Tiny;
use MetaCPAN::Client::Scroll;
use MetaCPAN::Client::Release;

my $scroller = MetaCPAN::Client::Scroll->new(
   ua       => HTTP::Tiny->new,
   base_url => 'https://fastapi.metacpan.org/v1/',
   type     => 'release',
   body     => { query => { term => { distribution => 'MetaCPAN-Client' } } },
   size     => 50,
);
isa_ok( $scroller, 'MetaCPAN::Client::Scroll' );

can_ok(
    $scroller,
    qw< aggregations base_url body _buffer
        BUILDARGS DEMOLISH _fetch_next _id
        next size time total type ua >
);

my $next = $scroller->next;
ok( is_hashref($next), 'next doc returns a hashref' );

my $rel = MetaCPAN::Client::Release->new_from_request( $next->{'_source'} );
isa_ok( $rel, 'MetaCPAN::Client::Release' );
is( $rel->distribution, 'MetaCPAN-Client', 'release object can be created from next doc' );

my $got = 1;  # we call ->next once above
while ( my $n = $scroller->next ) { $got++ }
is( $got, $scroller->total, 'can read all matching docs' );

1;