blob: 58191a5d3a5d112e313ea7a6fde9755ad633a53c [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
17my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures');
18my $fake_backend = $t->app->plugin(
19 Mount => {
20 $mount_point =>
21 $fixtures_path->child('fake_backend.pl')
22 }
23);
24# Configure fake backend
25$fake_backend->pattern->defaults->{app}->log($t->app->log);
26
27# Query passed
28$t->get_ok('/corpus2/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
29 ->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\">!)
Akronb80341d2018-10-15 19:46:23 +020032 ;
33
Akronb8d0b402018-10-18 23:51:52 +020034$t->get_ok('/corpus2/GOE/AGF/02286/p75682-75683')
35 ->status_is(200)
36 ->json_is('/textSigle', 'GOE/AGF/02286')
37 ->json_is('/title','Materialien zur Geschichte der Farbenlehre')
38 ;
39
40# TODO:
41# It's surprising, that it doesn't return a 404!
42$t->get_ok('/corpus2/notfound/X/X/p0-1')
43 ->status_is(200)
44 ->json_is('/textSigle', 'NOTFOUND/X/X')
45 ->json_is('/corpusID', undef)
46 ;
47
48# TODO:
49# Should probably return a 500!
50$t->get_ok('/corpus2/fail/x/x/p0-0')
51 ->status_is(200)
52 ->json_is('/notifications/0/0', 'error')
Akron7093b812018-10-19 17:28:21 +020053 ->json_is('/notifications/0/1', 'Unable to load query response from /home/ndiewald/Repositories/korap-git/Kalamar/t/fixtures/response_matchinfo_fail_x_x_p0-0.json')
Akronb8d0b402018-10-18 23:51:52 +020054 ;
55
56# TODO:
57# Should probably return a 4xx!
58$t->get_ok('/corpus2/GOE/AGF/02286/p-2-0')
59 ->status_is(200)
60 ->json_is('/notifications/0/0', 'error')
61 ->json_is('/notifications/0/1', '730: Invalid match identifier')
62 ;
63
64# TODO:
65# It's surprising, that it doesn't return a 404!
66$t->get_ok('/corpus2/notfound2/X/X/p0-1')
Akron7093b812018-10-19 17:28:21 +020067 ->status_is(404)
Akronb8d0b402018-10-18 23:51:52 +020068 ->json_is('/notifications/0/0', 'error')
69 ->json_is('/notifications/0/1', '404: Not Found')
70 ;
71
Akrond0ec3082018-10-19 18:53:09 +020072$t->get_ok('/corpus2/brokenerr/X/X/p0-1')
73 ->status_is(409)
74 ->json_is('/notifications/0/0', 'error')
75 ->json_is('/notifications/0/1', 'Message structure failed')
76 ;
77
78$t->get_ok('/corpus2/brokenwarn/X/X/p0-1')
79 ->status_is(200)
80 ->json_is('/notifications/0/0', 'warning')
81 ->json_is('/notifications/0/1', '1: Warning 1')
82 ->json_is('/notifications/1/0', 'error')
83 ->json_is('/notifications/1/1', 'Message structure failed')
84 ;
85
86$t->get_ok('/corpus2/brokenerr2/X/X/p0-1')
87 ->status_is(417)
88 ->json_is('/notifications/0/0', 'error')
89 ->json_is('/notifications/0/1', 'Message structure failed')
90 ;
91
Akronb8d0b402018-10-18 23:51:52 +020092
Akronb80341d2018-10-15 19:46:23 +020093done_testing;
Akron7093b812018-10-19 17:28:21 +020094__END__