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 | ##################### |
| 10 | my $mount_point = '/api/'; |
| 11 | $ENV{KALAMAR_API} = $mount_point; |
| 12 | |
| 13 | my $t = Test::Mojo->new('Kalamar'); |
| 14 | |
| 15 | # Mount fake backend |
| 16 | # Get the fixture path |
| 17 | my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures'); |
| 18 | my $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') |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 31 | ->json_like('/snippet', qr!<span class=\"context-left\">!) |
Akron | f21eb49 | 2018-10-22 15:17:56 +0200 | [diff] [blame^] | 32 | ->json_is('/X-cached', undef) |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 33 | ; |
| 34 | |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 35 | $t->get_ok('/corpus2/GOE/AGF/02286/p75682-75683') |
| 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! |
| 43 | $t->get_ok('/corpus2/notfound/X/X/p0-1') |
| 44 | ->status_is(200) |
| 45 | ->json_is('/textSigle', 'NOTFOUND/X/X') |
| 46 | ->json_is('/corpusID', undef) |
| 47 | ; |
| 48 | |
| 49 | # TODO: |
| 50 | # Should probably return a 500! |
| 51 | $t->get_ok('/corpus2/fail/x/x/p0-0') |
| 52 | ->status_is(200) |
| 53 | ->json_is('/notifications/0/0', 'error') |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 54 | ->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') |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 55 | ; |
| 56 | |
| 57 | # TODO: |
| 58 | # Should probably return a 4xx! |
| 59 | $t->get_ok('/corpus2/GOE/AGF/02286/p-2-0') |
| 60 | ->status_is(200) |
| 61 | ->json_is('/notifications/0/0', 'error') |
| 62 | ->json_is('/notifications/0/1', '730: Invalid match identifier') |
| 63 | ; |
| 64 | |
| 65 | # TODO: |
| 66 | # It's surprising, that it doesn't return a 404! |
| 67 | $t->get_ok('/corpus2/notfound2/X/X/p0-1') |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 68 | ->status_is(404) |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 69 | ->json_is('/notifications/0/0', 'error') |
| 70 | ->json_is('/notifications/0/1', '404: Not Found') |
| 71 | ; |
| 72 | |
Akron | d0ec308 | 2018-10-19 18:53:09 +0200 | [diff] [blame] | 73 | $t->get_ok('/corpus2/brokenerr/X/X/p0-1') |
| 74 | ->status_is(409) |
| 75 | ->json_is('/notifications/0/0', 'error') |
| 76 | ->json_is('/notifications/0/1', 'Message structure failed') |
| 77 | ; |
| 78 | |
| 79 | $t->get_ok('/corpus2/brokenwarn/X/X/p0-1') |
| 80 | ->status_is(200) |
| 81 | ->json_is('/notifications/0/0', 'warning') |
| 82 | ->json_is('/notifications/0/1', '1: Warning 1') |
| 83 | ->json_is('/notifications/1/0', 'error') |
| 84 | ->json_is('/notifications/1/1', 'Message structure failed') |
| 85 | ; |
| 86 | |
| 87 | $t->get_ok('/corpus2/brokenerr2/X/X/p0-1') |
| 88 | ->status_is(417) |
| 89 | ->json_is('/notifications/0/0', 'error') |
| 90 | ->json_is('/notifications/0/1', 'Message structure failed') |
| 91 | ; |
| 92 | |
Akron | f21eb49 | 2018-10-22 15:17:56 +0200 | [diff] [blame^] | 93 | # Get from cache |
| 94 | $t->get_ok('/corpus2/WPD15/232/39681/p2133-2134?spans=false&foundry=*') |
| 95 | ->status_is(200) |
| 96 | ->json_is('/textSigle', 'WPD15/232/39681') |
| 97 | ->json_like('/snippet', qr!<span class=\"context-left\">!) |
| 98 | ->json_is('/X-cached', 1) |
| 99 | ; |
| 100 | |
Akron | b8d0b40 | 2018-10-18 23:51:52 +0200 | [diff] [blame] | 101 | |
Akron | b80341d | 2018-10-15 19:46:23 +0200 | [diff] [blame] | 102 | done_testing; |
Akron | 7093b81 | 2018-10-19 17:28:21 +0200 | [diff] [blame] | 103 | __END__ |