| 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 | |
| Akron | 3352659 | 2026-09-02 13:27:46 +0200 | [diff] [blame] | 13 | my $t = Test::Mojo->new('Kalamar' => { |
| 14 | Kalamar => { |
| 15 | defaults => { |
| 16 | match_info_extended => 'max' |
| 17 | } |
| 18 | } |
| 19 | }); |
| Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 20 | |
| 21 | # Mount fake backend |
| 22 | # Get the fixture path |
| Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 23 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server'); |
| Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 24 | my $fake_backend = $t->app->plugin( |
| 25 | Mount => { |
| 26 | $mount_point => |
| Akron | 73f3608 | 2018-10-25 15:34:59 +0200 | [diff] [blame] | 27 | $fixtures_path->child('mock.pl') |
| Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 28 | } |
| 29 | ); |
| 30 | # Configure fake backend |
| 31 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 32 | |
| Akron | 3352659 | 2026-09-02 13:27:46 +0200 | [diff] [blame] | 33 | # The config is exposed on rendered pages |
| 34 | $t->get_ok('/') |
| 35 | ->status_is(200) |
| 36 | ->element_exists('body[data-match-info-extended="max"]') |
| 37 | ; |
| 38 | |
| Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 39 | # Query passed |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 40 | $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] | 41 | ->status_is(200) |
| Akron | 69481a4 | 2021-03-22 10:31:16 +0100 | [diff] [blame] | 42 | ->content_type_is('application/json;charset=UTF-8') |
| Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 43 | ->json_is('/textSigle', 'WPD15/232/39681') |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 44 | ->json_like('/snippet', qr!<span class=\"context-left\">!) |
| Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 45 | ->header_isnt('X-Kalamar-Cache', 'true') |
| Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 46 | ; |
| 47 | |
| Akron | 910828a | 2025-06-27 15:38:48 +0200 | [diff] [blame] | 48 | $t->get_ok('/corpus/GOE/AGF/02286/p75682-75683?_format=json&response-pipe=glemm') |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 49 | ->status_is(200) |
| 50 | ->json_is('/textSigle', 'GOE/AGF/02286') |
| 51 | ->json_is('/title','Materialien zur Geschichte der Farbenlehre') |
| Akron | 910828a | 2025-06-27 15:38:48 +0200 | [diff] [blame] | 52 | ->json_is('/meta/responsePipes','glemm') |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 53 | ; |
| 54 | |
| Akron | 3352659 | 2026-09-02 13:27:46 +0200 | [diff] [blame] | 55 | # Extended match-info request is accepted and forwarded |
| 56 | $t->get_ok('/corpus/GOE/AGF/02286/p75682-75683?extended=max&_format=json') |
| 57 | ->status_is(200) |
| 58 | ->json_is('/textSigle', 'GOE/AGF/02286') |
| 59 | ; |
| 60 | |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 61 | # TODO: |
| 62 | # It's surprising, that it doesn't return a 404! |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 63 | $t->get_ok('/corpus/notfound/X/X/p0-1?_format=json') |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 64 | ->status_is(200) |
| 65 | ->json_is('/textSigle', 'NOTFOUND/X/X') |
| 66 | ->json_is('/corpusID', undef) |
| 67 | ; |
| 68 | |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 69 | $t->get_ok('/corpus/fail/x/x/p0-0?_format=json') |
| Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 70 | ->status_is(400) |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 71 | ->json_is('/notifications/0/0', 'error') |
| Akron | 2e2098e | 2018-10-24 20:16:24 +0200 | [diff] [blame] | 72 | ->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] | 73 | ; |
| 74 | |
| 75 | # TODO: |
| 76 | # Should probably return a 4xx! |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 77 | $t->get_ok('/corpus/GOE/AGF/02286/p-2-0?_format=json') |
| Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 78 | ->status_is(400) |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 79 | ->json_is('/notifications/0/0', 'error') |
| 80 | ->json_is('/notifications/0/1', '730: Invalid match identifier') |
| 81 | ; |
| 82 | |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 83 | $t->get_ok('/corpus/notfound2/X/X/p0-1?_format=json') |
| Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 84 | ->status_is(404) |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 85 | ->json_is('/notifications/0/0', 'error') |
| 86 | ->json_is('/notifications/0/1', '404: Not Found') |
| 87 | ; |
| 88 | |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 89 | $t->get_ok('/corpus/brokenerr/X/X/p0-1?_format=json') |
| Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 90 | ->status_is(409) |
| 91 | ->json_is('/notifications/0/0', 'error') |
| 92 | ->json_is('/notifications/0/1', 'Message structure failed') |
| 93 | ; |
| 94 | |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 95 | $t->get_ok('/corpus/brokenwarn/X/X/p0-1?_format=json') |
| Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 96 | ->status_is(200) |
| Akron | a3c353c | 2019-02-14 23:50:00 +0100 | [diff] [blame] | 97 | ->json_is('/notifications/0/0', 'warn') |
| Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 98 | ->json_is('/notifications/0/1', '1: Warning 1') |
| 99 | ->json_is('/notifications/1/0', 'error') |
| 100 | ->json_is('/notifications/1/1', 'Message structure failed') |
| 101 | ; |
| 102 | |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 103 | $t->get_ok('/corpus/brokenerr2/X/X/p0-1?_format=json') |
| Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 104 | ->status_is(417) |
| 105 | ->json_is('/notifications/0/0', 'error') |
| 106 | ->json_is('/notifications/0/1', 'Message structure failed') |
| 107 | ; |
| 108 | |
| Akron | f21eb49 | 2018-10-22 15:17:56 +0200 | [diff] [blame] | 109 | # Get from cache |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 110 | $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] | 111 | ->status_is(200) |
| 112 | ->json_is('/textSigle', 'WPD15/232/39681') |
| 113 | ->json_like('/snippet', qr!<span class=\"context-left\">!) |
| Akron | 8ea8429 | 2018-10-24 13:41:52 +0200 | [diff] [blame] | 114 | ->header_is('X-Kalamar-Cache', 'true') |
| Akron | f21eb49 | 2018-10-22 15:17:56 +0200 | [diff] [blame] | 115 | ; |
| 116 | |
| Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 117 | # Check for validation error |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 118 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no&_format=json') |
| Akron | c4be819 | 2018-10-25 16:07:53 +0200 | [diff] [blame] | 119 | ->status_is(400) |
| 120 | ->json_is('/notifications/0/1', 'Parameter "spans" invalid') |
| 121 | ; |
| Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 122 | |
| Akron | 3b3a434 | 2021-05-31 11:14:48 +0200 | [diff] [blame] | 123 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no&_format=html') |
| Akron | 69481a4 | 2021-03-22 10:31:16 +0100 | [diff] [blame] | 124 | ->content_type_is('text/html;charset=UTF-8') |
| 125 | ->status_is(400) |
| 126 | ->text_is('p.no-results', 'Unable to perform the action.') |
| 127 | ->text_is('div.notify', 'Parameter "spans" invalid') |
| 128 | ; |
| 129 | |
| 130 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no') |
| 131 | ->content_type_is('text/html;charset=UTF-8') |
| Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 132 | ->status_is(400) |
| 133 | ->text_is('p.no-results', 'Unable to perform the action.') |
| 134 | ->text_is('div.notify', 'Parameter "spans" invalid') |
| 135 | ; |
| 136 | |
| Akron | 910828a | 2025-06-27 15:38:48 +0200 | [diff] [blame] | 137 | $t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=no') |
| 138 | ->content_type_is('text/html;charset=UTF-8') |
| 139 | ->status_is(400) |
| 140 | ->text_is('p.no-results', 'Unable to perform the action.') |
| 141 | ->text_is('div.notify', 'Parameter "spans" invalid') |
| 142 | ; |
| 143 | |
| Akron | 3c390c4 | 2020-03-30 09:06:21 +0200 | [diff] [blame] | 144 | |
| Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 145 | done_testing; |
| Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 146 | __END__ |