blob: ecbf2dd6353fcbe8c9ec8dcb5ca3e2a7d66488cc [file] [log] [blame]
Akronbe61f4c2018-10-20 00:52:58 +02001use Mojo::Base -strict;
2use Test::Mojo;
3use Test::More;
4use Mojo::File qw/path/;
5
6
7#####################
8# Start Fake server #
9#####################
Akron63d963b2019-07-05 15:35:51 +020010my $mount_point = '/realapi/';
Akronbe61f4c2018-10-20 00:52:58 +020011$ENV{KALAMAR_API} = $mount_point;
12
13my $t = Test::Mojo->new('Kalamar');
14
15# Mount fake backend
16# Get the fixture path
Akron73f36082018-10-25 15:34:59 +020017my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server');
Akronbe61f4c2018-10-20 00:52:58 +020018my $fake_backend = $t->app->plugin(
19 Mount => {
20 $mount_point =>
Akron73f36082018-10-25 15:34:59 +020021 $fixtures_path->child('mock.pl')
Akronbe61f4c2018-10-20 00:52:58 +020022 }
23);
24# Configure fake backend
25$fake_backend->pattern->defaults->{app}->log($t->app->log);
26
27# Query passed
Akron8ea84292018-10-24 13:41:52 +020028$t->get_ok('/corpus')
Akronbe61f4c2018-10-20 00:52:58 +020029 ->status_is(200)
Akron751e9e42019-03-13 09:54:55 +010030 ->content_like(qr!"tokens":5991667065!)
31 ->json_is('/documents', 20216975)
32 ->json_is('/tokens', 5991667065)
33 ->json_is('/sentences', 403923016)
34 ->json_is('/paragraphs', 129385487)
Akron8ea84292018-10-24 13:41:52 +020035 ->header_isnt('X-Kalamar-Cache', 'true')
Akronbe61f4c2018-10-20 00:52:58 +020036 ;
37
Akron8ea84292018-10-24 13:41:52 +020038$t->get_ok('/corpus?cq=docSigle+%3D+\"GOE/AGA\"')
Akron7d96fa42018-10-22 13:13:16 +020039 ->status_is(200)
Akronbe61f4c2018-10-20 00:52:58 +020040 ->json_is('/documents', 5)
41 ->json_is('/tokens', 108557)
42 ->json_is('/sentences', 3835)
43 ->json_is('/paragraphs', 124)
Akron8ea84292018-10-24 13:41:52 +020044 ->header_isnt('X-Kalamar-Cache', 'true')
Akronbe61f4c2018-10-20 00:52:58 +020045 ;
46
Akron8ea84292018-10-24 13:41:52 +020047$t->get_ok('/corpus?cq=4')
Akron7d96fa42018-10-22 13:13:16 +020048 ->status_is(400)
49 ->json_is('/notifications/0/1', "302: Could not parse query >>> (4) <<<.")
50 ;
51
Akronf21eb492018-10-22 15:17:56 +020052# Query passed
Akron8ea84292018-10-24 13:41:52 +020053$t->get_ok('/corpus')
Akronf21eb492018-10-22 15:17:56 +020054 ->status_is(200)
Akron751e9e42019-03-13 09:54:55 +010055 ->content_like(qr!"tokens":5991667065!)
56 ->json_is('/documents', 20216975)
57 ->json_is('/tokens', 5991667065)
58 ->json_is('/sentences', 403923016)
59 ->json_is('/paragraphs', 129385487)
Akron8ea84292018-10-24 13:41:52 +020060 ->header_is('X-Kalamar-Cache', 'true')
Akronf21eb492018-10-22 15:17:56 +020061 ;
62
63
Akronbe61f4c2018-10-20 00:52:58 +020064done_testing;
65__END__