Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use Test::More; |
| 3 | use Test::Mojo; |
| 4 | use Mojo::File qw/path/; |
| 5 | |
| 6 | # Get the fixture path |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 7 | my $mock_server = path(Mojo::File->new(__FILE__)->dirname, 'server')->child('mock.pl'); |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 8 | |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 9 | my $t = Test::Mojo->new($mock_server); |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 10 | |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 11 | $t->get_ok('/v1.0') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 12 | ->status_is(200) |
Akron | 6d49c1f | 2018-10-11 14:22:21 +0200 | [diff] [blame] | 13 | ->content_is('Fake server available'); |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 14 | |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 15 | $t->get_ok('/v1.0/search?ql=cosmas3') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 16 | ->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 | |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 21 | my $err = $t->get_ok('/v1.0/search?q=server_fail') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 22 | ->status_is(500) |
| 23 | ->content_like(qr!Oooops!) |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 24 | ->tx->res->dom->at('#error') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 25 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 26 | is(defined $err ? $err->text : '', ''); |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 27 | |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 28 | $err = $t->get_ok('/v1.0/search?q=[orth=das&ql=poliqarp&offset=0&count=25') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 29 | ->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 <<<.') |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 34 | ->tx->res->dom->at('#error') |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 35 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 36 | is(defined $err ? $err->text : '', ''); |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 37 | |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 38 | |
| 39 | $err = $t->get_ok('/v1.0/search?q=baum&ql=poliqarp&offset=0&count=25') |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 40 | ->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") |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 44 | ->tx->res->dom->at('#error') |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 45 | ; |
Akron | 58c6099 | 2021-09-07 13:11:43 +0200 | [diff] [blame] | 46 | is(defined $err ? $err->text : '', ''); |
| 47 | |
Akron | 2fc697a | 2024-06-28 10:35:10 +0200 | [diff] [blame^] | 48 | $err = $t->get_ok('/v1.0/search?q=baum&ql=poliqarp&offset=0&count=25&fields=textSigle') |
| 49 | ->status_is(200) |
| 50 | ->json_is('/meta/count', 25) |
| 51 | ->json_is('/meta/serialQuery', "tokens:s:Baum") |
| 52 | ->json_hasnt('/matches/0/docSigle') |
| 53 | ->json_is('/matches/0/textSigle', "GOE/AGI/00000") |
| 54 | ->tx->res->dom->at('#error') |
| 55 | ; |
| 56 | is(defined $err ? $err->text : '', ''); |
| 57 | |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 58 | |
Akron | 06d4d1f | 2024-06-05 11:59:20 +0200 | [diff] [blame] | 59 | $t->get_ok('/v1.0/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*') |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 60 | ->status_is(200) |
| 61 | ->json_is('/textSigle', 'WPD15/232/39681') |
| 62 | ; |
Akron | 3239663 | 2018-10-11 17:08:37 +0200 | [diff] [blame] | 63 | |
Akron | 0e1ed24 | 2018-10-11 13:22:00 +0200 | [diff] [blame] | 64 | done_testing; |
| 65 | __END__ |
Akron | 6d49c1f | 2018-10-11 14:22:21 +0200 | [diff] [blame] | 66 | |