Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Test::More tests => 1; |
21 |
|
22 |
use Test::Mojo; |
23 |
|
24 |
use t::lib::TestBuilder; |
25 |
use t::lib::Mocks; |
26 |
|
27 |
my $schema = Koha::Database->new->schema; |
28 |
my $builder = t::lib::TestBuilder->new; |
29 |
|
30 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
31 |
|
32 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
33 |
|
34 |
subtest 'validate patrons_export OpenAPI definition' => sub { |
35 |
|
36 |
my @related_sources = _get_related_sources(); |
37 |
plan tests => scalar @related_sources; |
38 |
|
39 |
$schema->storage->txn_begin; |
40 |
|
41 |
# Load OpenAPI schema |
42 |
my $validator = JSON::Validator::OpenAPI::Mojolicious->new; |
43 |
my $intradir = C4::Context->config('intranetdir'); |
44 |
my $swagger_schema = "$intradir/api/v1/swagger/swagger.json"; |
45 |
my $api_spec = $validator->bundle( |
46 |
{ |
47 |
replace => 1, |
48 |
schema => $swagger_schema |
49 |
} |
50 |
); |
51 |
# Get patron export properties |
52 |
my $objs = $api_spec->{definitions}->{patron_export}->{properties}; |
53 |
|
54 |
# Test OpenAPI property existence for all related sources |
55 |
my $result_source = Koha::Patron->new->_result()->result_source; |
56 |
foreach my $rel ( _get_related_sources() ) { |
57 |
my $related_source = $schema->source($rel); |
58 |
ok( |
59 |
exists $objs->{$related_source->source_name}, |
60 |
$related_source->source_name |
61 |
); |
62 |
} |
63 |
|
64 |
$schema->storage->txn_rollback; |
65 |
}; |
66 |
|
67 |
sub _get_related_sources { |
68 |
my $sources = {}; |
69 |
my $res_source = Koha::Patron->new->_result()->result_source; |
70 |
foreach my $rel ( Koha::Patron->new->_result()->relationships() ) { |
71 |
my $related_source = $res_source->related_source($rel); |
72 |
my $info = $res_source->relationship_info( $rel ); |
73 |
next if $info->{'attrs'}->{'is_depends_on'}; |
74 |
next if $sources->{$related_source->source_name}; |
75 |
$sources->{$related_source->source_name} = 1; |
76 |
} |
77 |
$sources->{'Borrower'} = 1; # add Borrower itself |
78 |
my @sorted = sort keys %$sources; |
79 |
return @sorted; |
80 |
} |