blob: 7403d52a278587117b6495637411ca423173fb5d [file] [log] [blame]
Akronb80341d2018-10-15 19:46:23 +02001use Mojo::Base -strict;
2use Test::Mojo;
3use Test::More;
4use Mojo::File qw/path/;
5
6
7#####################
8# Start Fake server #
9#####################
10my $mount_point = '/api/';
11$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');
Akronb80341d2018-10-15 19:46:23 +020018my $fake_backend = $t->app->plugin(
19 Mount => {
20 $mount_point =>
Akron73f36082018-10-25 15:34:59 +020021 $fixtures_path->child('mock.pl')
Akronb80341d2018-10-15 19:46:23 +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/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
Akronb80341d2018-10-15 19:46:23 +020029 ->status_is(200)
30 ->json_is('/textSigle', 'WPD15/232/39681')
Akronb8d0b402018-10-18 23:51:52 +020031 ->json_like('/snippet', qr!<span class=\"context-left\">!)
Akron8ea84292018-10-24 13:41:52 +020032 ->header_isnt('X-Kalamar-Cache', 'true')
Akronb80341d2018-10-15 19:46:23 +020033 ;
34
Akron8ea84292018-10-24 13:41:52 +020035$t->get_ok('/corpus/GOE/AGF/02286/p75682-75683')
Akronb8d0b402018-10-18 23:51:52 +020036 ->status_is(200)
37 ->json_is('/textSigle', 'GOE/AGF/02286')
38 ->json_is('/title','Materialien zur Geschichte der Farbenlehre')
39 ;
40
41# TODO:
42# It's surprising, that it doesn't return a 404!
Akron8ea84292018-10-24 13:41:52 +020043$t->get_ok('/corpus/notfound/X/X/p0-1')
Akronb8d0b402018-10-18 23:51:52 +020044 ->status_is(200)
45 ->json_is('/textSigle', 'NOTFOUND/X/X')
46 ->json_is('/corpusID', undef)
47 ;
48
49# TODO:
50# Should probably return a 500!
Akron8ea84292018-10-24 13:41:52 +020051$t->get_ok('/corpus/fail/x/x/p0-0')
Akronb8d0b402018-10-18 23:51:52 +020052 ->status_is(200)
53 ->json_is('/notifications/0/0', 'error')
Akron2e2098e2018-10-24 20:16:24 +020054 ->json_like('/notifications/0/1', qr!Unable to load query response from .+?response_matchinfo_fail_x_x_p0-0\.json!)
Akronb8d0b402018-10-18 23:51:52 +020055 ;
56
57# TODO:
58# Should probably return a 4xx!
Akron8ea84292018-10-24 13:41:52 +020059$t->get_ok('/corpus/GOE/AGF/02286/p-2-0')
Akronb8d0b402018-10-18 23:51:52 +020060 ->status_is(200)
61 ->json_is('/notifications/0/0', 'error')
62 ->json_is('/notifications/0/1', '730: Invalid match identifier')
63 ;
64
65# TODO:
66# It's surprising, that it doesn't return a 404!
Akron8ea84292018-10-24 13:41:52 +020067$t->get_ok('/corpus/notfound2/X/X/p0-1')
Akron7093b812018-10-19 17:28:21 +020068 ->status_is(404)
Akronb8d0b402018-10-18 23:51:52 +020069 ->json_is('/notifications/0/0', 'error')
70 ->json_is('/notifications/0/1', '404: Not Found')
71 ;
72
Akron8ea84292018-10-24 13:41:52 +020073$t->get_ok('/corpus/brokenerr/X/X/p0-1')
Akrond0ec3082018-10-19 18:53:09 +020074 ->status_is(409)
75 ->json_is('/notifications/0/0', 'error')
76 ->json_is('/notifications/0/1', 'Message structure failed')
77 ;
78
Akron8ea84292018-10-24 13:41:52 +020079$t->get_ok('/corpus/brokenwarn/X/X/p0-1')
Akrond0ec3082018-10-19 18:53:09 +020080 ->status_is(200)
81 ->json_is('/notifications/0/0', 'warning')
82 ->json_is('/notifications/0/1', '1: Warning 1')
83 ->json_is('/notifications/1/0', 'error')
84 ->json_is('/notifications/1/1', 'Message structure failed')
85 ;
86
Akron8ea84292018-10-24 13:41:52 +020087$t->get_ok('/corpus/brokenerr2/X/X/p0-1')
Akrond0ec3082018-10-19 18:53:09 +020088 ->status_is(417)
89 ->json_is('/notifications/0/0', 'error')
90 ->json_is('/notifications/0/1', 'Message structure failed')
91 ;
92
Akronf21eb492018-10-22 15:17:56 +020093# Get from cache
Akron8ea84292018-10-24 13:41:52 +020094$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
Akronf21eb492018-10-22 15:17:56 +020095 ->status_is(200)
96 ->json_is('/textSigle', 'WPD15/232/39681')
97 ->json_like('/snippet', qr!<span class=\"context-left\">!)
Akron8ea84292018-10-24 13:41:52 +020098 ->header_is('X-Kalamar-Cache', 'true')
Akronf21eb492018-10-22 15:17:56 +020099 ;
100
Akronb8d0b402018-10-18 23:51:52 +0200101
Akronb80341d2018-10-15 19:46:23 +0200102done_testing;
Akron7093b812018-10-19 17:28:21 +0200103__END__