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

(-)a/Koha/REST/V1/Acquisitions/Vendor/Issues.pm (+72 lines)
Line 0 Link Here
1
package Koha::REST::V1::Acquisitions::Vendor::Issues;
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 Mojo::Base 'Mojolicious::Controller';
21
22
use Try::Tiny qw( catch try );
23
24
=head1 NAME
25
26
Koha::REST::V1::Acquisitions::Vendor::Issues
27
28
=head1 API
29
30
=head2 Class methods
31
32
=head3 list
33
34
Controller function that handles vendor issues
35
36
=cut
37
38
=head3 list
39
40
Return the list of issues for a given vendor
41
42
=cut
43
44
sub list {
45
    my $c = shift->openapi->valid_input or return;
46
47
    return try {
48
49
        my $vendor_id = $c->validation->param('vendor_id');
50
        my $vendor = Koha::Acquisition::Booksellers->find($vendor_id);
51
52
        unless ($vendor) {
53
            return $c->render(
54
                status  => 404,
55
                openapi => { error => "Vendor not found." }
56
            );
57
        }
58
59
        my $issues_rs = $vendor->issues;
60
        my $issues    = $c->objects->search( $issues_rs );
61
62
        return $c->render(
63
            status  => 200,
64
            openapi => $issues,
65
        );
66
    }
67
    catch {
68
        $c->unhandled_exception($_);
69
    };
70
}
71
72
1;
(-)a/t/db_dependent/Koha/Acquisition/Booksellers.t (-1 / +29 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 6;
21
21
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
23
Lines 225-227 subtest 'interfaces' => sub { Link Here
225
225
226
    $schema->storage->txn_rollback();
226
    $schema->storage->txn_rollback();
227
};
227
};
228
229
subtest 'issues' => sub {
230
231
    plan tests => 4;
232
233
    $schema->storage->txn_begin();
234
235
    my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
236
237
    is( $vendor->issues->count, 0, 'Vendor has no issues' );
238
239
    Koha::Acquisition::Bookseller::Issue->new(
240
        {
241
            vendor_id => $vendor->id,
242
            type      => 'MAINTENANCE',
243
            notes     => 'a vendor issue'
244
        }
245
    )->store;
246
247
    $vendor = $vendor->get_from_storage;
248
    my $issues = $vendor->issues;
249
    is( $issues->count, 1, '1 issue stored' );
250
    is( ref($issues), 'Koha::Acquisition::Bookseller::Issues', 'Type is correct' );
251
252
    is( $issues->next->strings_map->{type}->{str}, 'Maintenance' );
253
254
    $schema->storage->txn_rollback();
255
};
(-)a/t/db_dependent/api/v1/acquisitions_vendor_issues.t (-1 / +82 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env 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
use Test::Mojo;
22
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
26
use Koha::Acquisition::Booksellers;
27
use Koha::Database;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
my $t = Test::Mojo->new('Koha::REST::V1');
33
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
34
35
subtest 'list() tests' => sub {
36
37
    plan tests => 11;
38
39
    $schema->storage->txn_begin;
40
41
    my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } );
42
    my $vendor_id = $vendor->id;
43
44
    my $librarian = $builder->build_object(
45
        {
46
            class => 'Koha::Patrons',
47
            value => { flags => 2 ** 11 }
48
        }
49
    );
50
    my $password = 'thePassword123';
51
    $librarian->set_password( { password => $password, skip_validation => 1 } );
52
    my $userid = $librarian->userid;
53
54
    # No issues, so empty array should be returned
55
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues")
56
      ->status_is(200)
57
      ->json_is( [] );
58
59
    my $issue = Koha::Acquisition::Bookseller::Issue->new(
60
        {
61
            vendor_id => $vendor_id,
62
            type      => 'MAINTENANCE',
63
            notes     => 'a vendor issue'
64
        }
65
    )->store;
66
    # One issue created, should get returned
67
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues")
68
      ->status_is(200)
69
      ->json_is( [$issue->to_api] );
70
    # Embed the AV description
71
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues"
72
        => { 'x-koha-embed' => '+strings' })
73
      ->status_is(200)
74
      ->json_is( [$issue->to_api({ strings => 1 })] );
75
76
    $vendor->delete;
77
    # No vendor, should get 404
78
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues")
79
      ->status_is(404);
80
81
    $schema->storage->txn_rollback;
82
};

Return to bug 33105