Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 1 | use Mojo::Base -strict; |
| 2 | use Test::Mojo; |
| 3 | use Test::More; |
| 4 | use Mojo::File qw/path/; |
| 5 | |
| 6 | |
| 7 | ##################### |
| 8 | # Start Fake server # |
| 9 | ##################### |
Akron | 63d963b | 2019-07-05 15:35:51 +0200 | [diff] [blame] | 10 | my $mount_point = '/realapi/'; |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 11 | $ENV{KALAMAR_API} = $mount_point; |
| 12 | |
| 13 | my $t = Test::Mojo->new('Kalamar'); |
| 14 | |
| 15 | # Mount fake backend |
| 16 | # Get the fixture path |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 17 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server'); |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 18 | my $fake_backend = $t->app->plugin( |
| 19 | Mount => { |
| 20 | $mount_point => |
Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 21 | $fixtures_path->child('mock.pl') |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 22 | } |
| 23 | ); |
| 24 | # Configure fake backend |
| 25 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 26 | |
| 27 | # Query passed |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 28 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*&format=json') |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 29 | ->status_is(200) |
| 30 | ->json_is('/textSigle', 'WPD15/232/39681') |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 31 | ->json_like('/snippet', qr!<span class=\"context-left\">!) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 32 | ->header_isnt('X-Kalamar-Cache', 'true') |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 33 | ; |
| 34 | |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 35 | $t->get_ok('/corpus/GOE/AGF/02286/p75682-75683?format=json') |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 36 | ->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! |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 43 | $t->get_ok('/corpus/notfound/X/X/p0-1?format=json') |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 44 | ->status_is(200) |
| 45 | ->json_is('/textSigle', 'NOTFOUND/X/X') |
| 46 | ->json_is('/corpusID', undef) |
| 47 | ; |
| 48 | |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 49 | $t->get_ok('/corpus/fail/x/x/p0-0?format=json') |
| 50 | ->status_is(400) |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 51 | ->json_is('/notifications/0/0', 'error') |
Akron | 2e2098e | 2018-10-24 20:16:24 +0200 | [diff] [blame] | 52 | ->json_like('/notifications/0/1', qr!Unable to load query response from .+?response_matchinfo_fail_x_x_p0-0\.json!) |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 53 | ; |
| 54 | |
| 55 | # TODO: |
| 56 | # Should probably return a 4xx! |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 57 | $t->get_ok('/corpus/GOE/AGF/02286/p-2-0?format=json') |
| 58 | ->status_is(400) |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 59 | ->json_is('/notifications/0/0', 'error') |
| 60 | ->json_is('/notifications/0/1', '730: Invalid match identifier') |
| 61 | ; |
| 62 | |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 63 | $t->get_ok('/corpus/notfound2/X/X/p0-1?format=json') |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 64 | ->status_is(404) |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 65 | ->json_is('/notifications/0/0', 'error') |
| 66 | ->json_is('/notifications/0/1', '404: Not Found') |
| 67 | ; |
| 68 | |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 69 | $t->get_ok('/corpus/brokenerr/X/X/p0-1?format=json') |
Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 70 | ->status_is(409) |
| 71 | ->json_is('/notifications/0/0', 'error') |
| 72 | ->json_is('/notifications/0/1', 'Message structure failed') |
| 73 | ; |
| 74 | |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 75 | $t->get_ok('/corpus/brokenwarn/X/X/p0-1?format=json') |
Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 76 | ->status_is(200) |
Akron | a3c353c | 2019-02-14 23:50:00 +0100 | [diff] [blame] | 77 | ->json_is('/notifications/0/0', 'warn') |
Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 78 | ->json_is('/notifications/0/1', '1: Warning 1') |
| 79 | ->json_is('/notifications/1/0', 'error') |
| 80 | ->json_is('/notifications/1/1', 'Message structure failed') |
| 81 | ; |
| 82 | |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 83 | $t->get_ok('/corpus/brokenerr2/X/X/p0-1?format=json') |
Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 84 | ->status_is(417) |
| 85 | ->json_is('/notifications/0/0', 'error') |
| 86 | ->json_is('/notifications/0/1', 'Message structure failed') |
| 87 | ; |
| 88 | |
Akron | f21eb49 | 2018-10-22 15:17:56 +0200 | [diff] [blame] | 89 | # Get from cache |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 90 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*&format=json') |
Akron | f21eb49 | 2018-10-22 15:17:56 +0200 | [diff] [blame] | 91 | ->status_is(200) |
| 92 | ->json_is('/textSigle', 'WPD15/232/39681') |
| 93 | ->json_like('/snippet', qr!<span class=\"context-left\">!) |
Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 94 | ->header_is('X-Kalamar-Cache', 'true') |
Akron | f21eb49 | 2018-10-22 15:17:56 +0200 | [diff] [blame] | 95 | ; |
| 96 | |
Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 97 | # Check for validation error |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 98 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no&format=json') |
Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 99 | ->status_is(400) |
| 100 | ->json_is('/notifications/0/1', 'Parameter "spans" invalid') |
| 101 | ; |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 102 | |
Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame^] | 103 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no&format=html') |
| 104 | ->status_is(400) |
| 105 | ->text_is('p.no-results', 'Unable to perform the action.') |
| 106 | ->text_is('div.notify', 'Parameter "spans" invalid') |
| 107 | ; |
| 108 | |
| 109 | |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 110 | done_testing; |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 111 | __END__ |