Skip to content

Commit 4477792

Browse files
oaldersranguard
authored andcommitted
Add tests for search model.
1 parent 3014de6 commit 4477792

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

t/model/search.t

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use strict;
2+
use warnings;
3+
4+
use MetaCPAN::Model::Search ();
5+
use MetaCPAN::TestServer ();
6+
use Test::More;
7+
8+
# Just use this to get an es object.
9+
my $server = MetaCPAN::TestServer->new;
10+
my $search = MetaCPAN::Model::Search->new(
11+
es => $server->es_client,
12+
index => 'cpan',
13+
);
14+
15+
ok( $search, 'search' );
16+
ok( $search->_not_rogue, '_not_rogue' );
17+
18+
{
19+
my $results = $search->search_web('Fooxxxx');
20+
is_deeply( $results, {}, 'no results on fake module' );
21+
}
22+
23+
{
24+
my $results = $search->search_web('Foo');
25+
is( scalar @{ $results->{results}->[0] }, 2, 'got results' );
26+
}
27+
28+
{
29+
my $results = $search->search_web('author:Mo');
30+
is( @{ $results->{results} }, 5, '5 results on author search' );
31+
}
32+
33+
{
34+
my $long_form = $search->search_web('distribution:Pod-Pm');
35+
my $short_form = $search->search_web('dist:Pod-Pm');
36+
37+
is_deeply(
38+
$long_form->{results},
39+
$short_form->{results},
40+
'dist == distribution search'
41+
);
42+
}
43+
44+
is_deeply( $search->search_favorites, {},
45+
'empty hashref when no distributions' );
46+
is_deeply( $search->search_favorites('Pod-Pm')->{favorites},
47+
{}, 'no favorites found' );
48+
49+
is_deeply( $search->search_descriptions,
50+
{}, 'empty hashref when no ids for descriptions' );
51+
done_testing();

0 commit comments

Comments
 (0)