View | Details | Raw Unified | Return to bug 33996
Collapse All | Expand All

(-)a/Koha/Authority.pm (-3 / +24 lines)
Lines 30-36 Koha::Authority - Koha Authority Object class Link Here
30
30
31
=head1 API
31
=head1 API
32
32
33
=head2 Instance Methods
33
=head2 Class methods
34
34
35
=head3 get_usage_count
35
=head3 get_usage_count
36
36
Lines 168-176 sub record_schema { Link Here
168
      : 'MARC21';
168
      : 'MARC21';
169
}
169
}
170
170
171
=head2 Class Methods
171
=head3 to_api_mapping
172
172
173
=head3 type
173
This method returns the mapping for representing a Koha::Authority object
174
on the API.
175
176
=cut
177
178
sub to_api_mapping {
179
    return {
180
        authid            => 'authority_id',
181
        authtrees         => undef,
182
        authtypecode      => 'framework_id',
183
        datecreated       => 'creation_date',
184
        linkid            => undef,
185
        marc              => undef,
186
        marcxml           => undef,
187
        modification_time => 'updated_on',
188
        origincode        => undef,
189
    };
190
}
191
192
=head2 Internal methods
193
194
=head3 _type
174
195
175
=cut
196
=cut
176
197
(-)a/t/db_dependent/api/v1/authorities.t (-40 / +32 lines)
Lines 28-33 use Test::Warn; Link Here
28
use t::lib::Mocks;
28
use t::lib::Mocks;
29
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
30
30
31
use Mojo::JSON qw(encode_json);
32
31
use C4::Auth;
33
use C4::Auth;
32
34
33
use Koha::Authorities;
35
use Koha::Authorities;
Lines 67-100 subtest 'get() tests' => sub { Link Here
67
</record>|
69
</record>|
68
    } });
70
    } });
69
71
70
    $t->get_ok("//$userid:$password@/api/v1/authorities/" . $authority->authid)
72
    $t->get_ok("//$userid:$password@/api/v1/authorities/" . $authority->id)
71
      ->status_is(403);
73
      ->status_is(403);
72
74
73
    $patron->flags(4)->store;
75
    $patron->flags(4)->store;
74
76
75
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
77
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
76
                => { Accept => 'application/weird+format' } )
78
                => { Accept => 'application/weird+format' } )
77
      ->status_is(400);
79
      ->status_is(400);
78
80
79
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
81
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
80
                 => { Accept => 'application/json' } )
82
                 => { Accept => 'application/json' } )
81
      ->status_is(200)
83
      ->status_is(200)
82
      ->json_is( '/authid', $authority->authid )
84
      ->json_is( '/authority_id', $authority->id )
83
      ->json_is( '/authtypecode', $authority->authtypecode );
85
      ->json_is( '/framework_id', $authority->authtypecode );
84
86
85
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
87
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
86
                 => { Accept => 'application/marcxml+xml' } )
88
                 => { Accept => 'application/marcxml+xml' } )
87
      ->status_is(200);
89
      ->status_is(200);
88
90
89
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
91
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
90
                 => { Accept => 'application/marc-in-json' } )
92
                 => { Accept => 'application/marc-in-json' } )
91
      ->status_is(200);
93
      ->status_is(200);
92
94
93
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
95
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
94
                 => { Accept => 'application/marc' } )
96
                 => { Accept => 'application/marc' } )
95
      ->status_is(200);
97
      ->status_is(200);
96
98
97
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
99
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
98
                 => { Accept => 'text/plain' } )
100
                 => { Accept => 'text/plain' } )
99
      ->status_is(200)
101
      ->status_is(200)
100
      ->content_is(q|LDR 00079     2200049   4500
102
      ->content_is(q|LDR 00079     2200049   4500
Lines 103-109 subtest 'get() tests' => sub { Link Here
103
       _aMy Corporation|);
105
       _aMy Corporation|);
104
106
105
    $authority->delete;
107
    $authority->delete;
106
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
108
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id
107
                 => { Accept => 'application/marc' } )
109
                 => { Accept => 'application/marc' } )
108
      ->status_is(404)
110
      ->status_is(404)
109
      ->json_is( '/error', 'Object not found.' );
111
      ->json_is( '/error', 'Object not found.' );
Lines 138-153 subtest 'delete() tests' => sub { Link Here
138
</record>|
140
</record>|
139
    } });
141
    } });
140
142
141
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid)
143
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->id)
142
      ->status_is(403, 'Not enough permissions makes it return the right code');
144
      ->status_is(403, 'Not enough permissions makes it return the right code');
143
145
144
    $patron->flags( 2 ** 14 )->store; # 14 => editauthorities userflag
146
    $patron->flags( 2 ** 14 )->store; # 14 => editauthorities userflag
145
147
146
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid)
148
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->id)
147
      ->status_is(204, 'SWAGGER3.2.4')
149
      ->status_is(204, 'SWAGGER3.2.4')
148
      ->content_is('', 'SWAGGER3.3.4');
150
      ->content_is('', 'SWAGGER3.3.4');
149
151
150
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid)
152
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->id)
151
      ->status_is(404);
153
      ->status_is(404);
152
154
153
    $schema->storage->txn_rollback;
155
    $schema->storage->txn_rollback;
Lines 261-267 subtest 'put() tests' => sub { Link Here
261
</record>|
263
</record>|
262
    } });
264
    } });
263
265
264
    my $authid       = $authority->authid;
266
    my $authid       = $authority->id;
265
    my $authtypecode = $authority->authtypecode;
267
    my $authtypecode = $authority->authtypecode;
266
268
267
    my $marcxml = q|<?xml version="1.0" encoding="UTF-8"?>
269
    my $marcxml = q|<?xml version="1.0" encoding="UTF-8"?>
Lines 333-339 subtest 'list() tests' => sub { Link Here
333
    $patron->discard_changes;
335
    $patron->discard_changes;
334
    my $userid = $patron->userid;
336
    my $userid = $patron->userid;
335
337
336
    my $authid1 = $builder->build_object({ 'class' => 'Koha::Authorities', value => {
338
    my $auth_id_1 = $builder->build_object({ 'class' => 'Koha::Authorities', value => {
337
      marcxml => q|<?xml version="1.0" encoding="UTF-8"?>
339
      marcxml => q|<?xml version="1.0" encoding="UTF-8"?>
338
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
340
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
339
    <controlfield tag="001">1001</controlfield>
341
    <controlfield tag="001">1001</controlfield>
Lines 344-350 subtest 'list() tests' => sub { Link Here
344
</record>|
346
</record>|
345
    } })->authid;
347
    } })->authid;
346
348
347
    my $authid2 = $builder->build_object({ 'class' => 'Koha::Authorities', value => {
349
    my $auth_id_2 = $builder->build_object({ 'class' => 'Koha::Authorities', value => {
348
      marcxml => q|<?xml version="1.0" encoding="UTF-8"?>
350
      marcxml => q|<?xml version="1.0" encoding="UTF-8"?>
349
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
351
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
350
    <controlfield tag="001">1001</controlfield>
352
    <controlfield tag="001">1001</controlfield>
Lines 355-391 subtest 'list() tests' => sub { Link Here
355
</record>|
357
</record>|
356
    } })->authid;
358
    } })->authid;
357
359
358
    my $search =
360
    my $query = encode_json( [ { authority_id => $auth_id_1 }, { authority_id => $auth_id_2 } ] );
359
"[{\"authid\": \"$authid1\"}, {\"authid\": \"$authid2\"}]";
361
360
    $t->get_ok(
362
    $t->get_ok("//$userid:$password@/api/v1/authorities?q=$query")->status_is(403);
361
        "//$userid:$password@/api/v1/authorities/" => { 'x-koha-query' => $search }
362
    )->status_is(403);
363
363
364
    $patron->flags(4)->store;
364
    $patron->flags(4)->store;
365
365
366
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" =>
366
    $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/weird+format' } )
367
          { Accept => 'application/weird+format', 'x-koha-query' => $search } )
367
        ->status_is(400);
368
      ->status_is(400);
369
368
370
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" =>
369
    $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/json' } )
371
          { Accept => 'application/json', 'x-koha-query' => $search } )
370
        ->status_is(200);
372
      ->status_is(200);
373
371
374
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" =>
372
    $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/marcxml+xml' } )
375
          { Accept => 'application/marcxml+xml', 'x-koha-query' => $search } )
373
        ->status_is(200);
376
      ->status_is(200);
377
374
378
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" =>
375
    $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/marc-in-json' } )
379
          { Accept => 'application/marc-in-json', 'x-koha-query' => $search } )
376
        ->status_is(200);
380
      ->status_is(200);
381
377
382
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" =>
378
    $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'application/marc' } )
383
          { Accept => 'application/marc', 'x-koha-query' => $search } )
379
        ->status_is(200);
384
      ->status_is(200);
385
380
386
    $t->get_ok( "//$userid:$password@/api/v1/authorities/" =>
381
    $t->get_ok( "//$userid:$password@/api/v1/authorities?q=$query" => { Accept => 'text/plain' } )->status_is(200);
387
          { Accept => 'text/plain', 'x-koha-query' => $search } )
388
      ->status_is(200);
389
382
390
    $schema->storage->txn_rollback;
383
    $schema->storage->txn_rollback;
391
};
384
};
392
- 

Return to bug 33996