Akron | 80a84b2 | 2018-10-24 17:44:24 +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 | 80a84b2 | 2018-10-24 17:44:24 +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 | 80a84b2 | 2018-10-24 17:44:24 +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 | 80a84b2 | 2018-10-24 17:44:24 +0200 | [diff] [blame] | 22 | } |
| 23 | ); |
| 24 | # Configure fake backend |
| 25 | $fake_backend->pattern->defaults->{app}->log($t->app->log); |
| 26 | |
| 27 | # Query passed |
| 28 | $t->get_ok('/corpus/GOE/AGI/00000') |
| 29 | ->status_is(200) |
| 30 | ->json_is('/document/fields/0/key', 'textSigle') |
| 31 | ->json_is('/document/fields/0/value', 'GOE/AGI/00000') |
| 32 | ; |
| 33 | |
| 34 | # Not found - should probably be 404 |
| 35 | $t->get_ok('/corpus/GOE/AGY/00000') |
| 36 | ->status_is(200) |
| 37 | ->json_is('/notifications/0/1', '630: Document not found') |
| 38 | ; |
| 39 | |
Akron | 4e413fb | 2023-09-26 13:11:11 +0200 | [diff] [blame] | 40 | # Real example from NKJP |
| 41 | $t->get_ok('/corpus/NKJP/NKJP/forumowisko.pl_57') |
| 42 | ->status_is(200) |
| 43 | ->json_like('/notifications/0/1', qr!^Unable to load!) |
| 44 | ; |
| 45 | |
| 46 | |
Akron | 80a84b2 | 2018-10-24 17:44:24 +0200 | [diff] [blame] | 47 | |
| 48 | done_testing; |
| 49 | __END__ |