blob: a11fb8b934c3aacdec356a524a3e60a8960faa59 [file] [log] [blame]
Akron751e9e42019-03-13 09:54:55 +01001use 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/';
Akron751e9e42019-03-13 09:54:55 +010011$ENV{KALAMAR_API} = $mount_point;
12
13# New test with new cache
14my $t = Test::Mojo->new('Kalamar' => {
15 Kalamar => {},
16 CHI => {
17 default => {
18 driver => 'Memory',
19 global => 1,
20 },
21 default => {
22 driver => 'Memory',
23 global => 1,
24 },
25 }
26});
27
28is($t->app->config('CHI')->{default}->{serializer}, 'JSON');
29
30is($t->app->chi->driver_class, 'CHI::Driver::Memory');
31
32# Mount fake backend
33# Get the fixture path
34my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server');
35my $fake_backend = $t->app->plugin(
36 Mount => {
37 $mount_point =>
38 $fixtures_path->child('mock.pl')
39 }
40);
41# Configure fake backend
42$fake_backend->pattern->defaults->{app}->log($t->app->log);
43
44# Query passed
45$t->get_ok('/corpus')
46 ->status_is(200)
47 ->content_like(qr!"tokens":5991667065!)
48 ->json_is('/documents', 20216975)
49 ->json_is('/tokens', 5991667065)
50 ->json_is('/sentences', 403923016)
51 ->json_is('/paragraphs', 129385487)
52 ->header_isnt('X-Kalamar-Cache', 'true')
53 ;
54
55# Query passed
56$t->get_ok('/corpus')
57 ->status_is(200)
58 ->content_like(qr!"tokens":5991667065!)
59 ->json_is('/documents', 20216975)
60 ->json_is('/tokens', 5991667065)
61 ->json_is('/sentences', 403923016)
62 ->json_is('/paragraphs', 129385487)
63 ->header_is('X-Kalamar-Cache', 'true')
64 ;
65
66
67done_testing;
68__END__