blob: 8a17bd72683dd2421043c82c93fd31f6edba4005 [file] [log] [blame]
Akron0e1ed242018-10-11 13:22:00 +02001use Mojo::Base -strict;
2use Test::More;
3use Test::Mojo;
4use Mojo::File qw/path/;
5
6# Get the fixture path
Akron73f36082018-10-25 15:34:59 +02007my $mock_server = path(Mojo::File->new(__FILE__)->dirname, 'server')->child('mock.pl');
Akron0e1ed242018-10-11 13:22:00 +02008
Akron73f36082018-10-25 15:34:59 +02009my $t = Test::Mojo->new($mock_server);
Akron0e1ed242018-10-11 13:22:00 +020010
Akron63d963b2019-07-05 15:35:51 +020011$t->get_ok('/v1.0')
Akron0e1ed242018-10-11 13:22:00 +020012 ->status_is(200)
Akron6d49c1f2018-10-11 14:22:21 +020013 ->content_is('Fake server available');
Akron0e1ed242018-10-11 13:22:00 +020014
Akron63d963b2019-07-05 15:35:51 +020015$t->get_ok('/v1.0/search?ql=cosmas3')
Akron0e1ed242018-10-11 13:22:00 +020016 ->status_is(400)
17 ->json_is('/errors/0/0',"307")
18 ->json_is('/errors/0/1',"cosmas3 is not a supported query language!")
19 ;
20
Akron58c60992021-09-07 13:11:43 +020021my $err = $t->get_ok('/v1.0/search?q=server_fail')
Akron0e1ed242018-10-11 13:22:00 +020022 ->status_is(500)
23 ->content_like(qr!Oooops!)
Akron58c60992021-09-07 13:11:43 +020024 ->tx->res->dom->at('#error')
Akron0e1ed242018-10-11 13:22:00 +020025 ;
Akron58c60992021-09-07 13:11:43 +020026is(defined $err ? $err->text : '', '');
Akron0e1ed242018-10-11 13:22:00 +020027
Akron58c60992021-09-07 13:11:43 +020028$err = $t->get_ok('/v1.0/search?q=[orth=das&ql=poliqarp&offset=0&count=25')
Akron0e1ed242018-10-11 13:22:00 +020029 ->status_is(400)
30 ->json_is('/errors/0/0',302)
31 ->json_is('/errors/0/1','Parantheses/brackets unbalanced.')
32 ->json_is('/errors/1/0',302)
33 ->json_is('/errors/1/1','Could not parse query >>> [orth=das <<<.')
Akron58c60992021-09-07 13:11:43 +020034 ->tx->res->dom->at('#error')
Akron0e1ed242018-10-11 13:22:00 +020035 ;
Akron58c60992021-09-07 13:11:43 +020036is(defined $err ? $err->text : '', '');
Akron0e1ed242018-10-11 13:22:00 +020037
Akron58c60992021-09-07 13:11:43 +020038
39$err = $t->get_ok('/v1.0/search?q=baum&ql=poliqarp&offset=0&count=25')
Akron32396632018-10-11 17:08:37 +020040 ->status_is(200)
41 ->json_is('/meta/count', 25)
42 ->json_is('/meta/serialQuery', "tokens:s:Baum")
43 ->json_is('/matches/0/docSigle', "GOE/AGI")
Akron58c60992021-09-07 13:11:43 +020044 ->tx->res->dom->at('#error')
Akron32396632018-10-11 17:08:37 +020045 ;
Akron58c60992021-09-07 13:11:43 +020046is(defined $err ? $err->text : '', '');
47
Akron32396632018-10-11 17:08:37 +020048
Akron63d963b2019-07-05 15:35:51 +020049$t->get_ok('/v1.0/corpus/WPD15/232/39681/p2133-2134/matchInfo?spans=false&foundry=*')
Akronb80341d2018-10-15 19:46:23 +020050 ->status_is(200)
51 ->json_is('/textSigle', 'WPD15/232/39681')
52 ;
Akron32396632018-10-11 17:08:37 +020053
Akron0e1ed242018-10-11 13:22:00 +020054done_testing;
55__END__
Akron6d49c1f2018-10-11 14:22:21 +020056