blob: 410793123d7d8428b4e6e4a61283a72e611df18f [file] [log] [blame]
Akron80a84b22018-10-24 17:44:24 +02001use Mojo::Base -strict;
2use Test::Mojo;
3use Test::More;
4use Mojo::File qw/path/;
5
6
7#####################
8# Start Fake server #
9#####################
Akron63d963b2019-07-05 15:35:51 +020010my $mount_point = '/realapi/';
Akron80a84b22018-10-24 17:44:24 +020011$ENV{KALAMAR_API} = $mount_point;
12
13my $t = Test::Mojo->new('Kalamar');
14
15# Mount fake backend
16# Get the fixture path
Akron73f36082018-10-25 15:34:59 +020017my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'server');
Akron80a84b22018-10-24 17:44:24 +020018my $fake_backend = $t->app->plugin(
19 Mount => {
20 $mount_point =>
Akron73f36082018-10-25 15:34:59 +020021 $fixtures_path->child('mock.pl')
Akron80a84b22018-10-24 17:44:24 +020022 }
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
Akron910828a2025-06-27 15:38:48 +020034$t->get_ok('/corpus/GOE/AGI/00000?response-pipe=glemm')
35 ->status_is(200)
36 ->json_is('/document/fields/0/key', 'textSigle')
37 ->json_is('/document/fields/0/value', 'GOE/AGI/00000')
38 ->json_is('/meta/responsePipes', 'glemm')
39 ;
40
41
Akron80a84b22018-10-24 17:44:24 +020042# Not found - should probably be 404
43$t->get_ok('/corpus/GOE/AGY/00000')
44 ->status_is(200)
45 ->json_is('/notifications/0/1', '630: Document not found')
46 ;
47
Akron4e413fb2023-09-26 13:11:11 +020048# Real example from NKJP
49$t->get_ok('/corpus/NKJP/NKJP/forumowisko.pl_57')
50 ->status_is(200)
51 ->json_like('/notifications/0/1', qr!^Unable to load!)
52 ;
53
54
Akron80a84b22018-10-24 17:44:24 +020055
56done_testing;
57__END__