Skip to content

Commit

Permalink
add test for the URL parameters: test 'source'
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Sep 10, 2016
1 parent 5a012af commit 122110a
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions t/server/controller/url_parameters.pm
@@ -0,0 +1,52 @@
use strict;
use warnings;

use Cpanel::JSON::XS ();
use HTTP::Request::Common qw( GET );
use MetaCPAN::Server ();
use Plack::Test;
use Test::More;
use Ref::Util qw( is_arrayref is_hashref );

my $app = MetaCPAN::Server->new->to_app();
my $test = Plack::Test->create($app);

subtest "parem 'source'" => sub {
my $source = Cpanel::JSON::XS::encode_json {
query => {
term => { distribution => "Moose" }
},
aggs => {
count => {
terms => { field => "distribution" }
}
},
size => 0,
};

# test different types, as the parameter is generic to all
for ( [ release => 2 ], [ file => 27 ] ) {
my ( $type, $count ) = @$_;

my $url = "/$type/_search?source=$source";

subtest "check with '$type' controller" => sub {
my $res = $test->request( GET $url );
ok( $res, "GET $url" );
is( $res->code, 200, "code 200" );
is(
$res->header('content-type'),
'application/json; charset=utf-8',
'Content-type'
);
my $content = Cpanel::JSON::XS::decode_json $res->content;
ok( is_hashref($content), 'content is a JSON object' );
my $buckets = $content->{aggregations}{count}{buckets};
ok( is_arrayref($buckets), 'we have aggregation buckets' );
is( @{$buckets}, 1, 'one key (Moose)' );
is( $buckets->[0]{doc_count}, $count, "record count is $count" );
};
}
};

done_testing;

0 comments on commit 122110a

Please sign in to comment.