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

(-)a/t/db_dependent/Koha/Edifact/File.t (+72 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2023 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>
19
20
use Modern::Perl;
21
22
use Test::More tests => 2;
23
24
use Koha::Edifact::Files;
25
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
subtest 'vendor() tests' => sub {
33
34
    plan tests => 2;
35
36
    $schema->storage->txn_begin;
37
38
    my $file = $builder->build_object( { class => 'Koha::Edifact::Files' } );
39
40
    my $vendor = $file->vendor;
41
    is(
42
        ref($vendor), 'Koha::Acquisition::Bookseller',
43
        'Koha::Edifact::File->vendor should return a Koha::Acquisition::Bookseller'
44
    );
45
46
    $file->vendor_id(undef)->store;
47
    is( $file->vendor, undef, 'Koha::Edifact::File->vendor should return undef if no vendor linked' );
48
49
    $schema->storage->txn_rollback;
50
};
51
52
subtest 'basket() tests' => sub {
53
54
    plan tests => 2;
55
56
    $schema->storage->txn_begin;
57
58
    my $file = $builder->build_object( { class => 'Koha::Edifact::Files' } );
59
60
    my $basket = $file->basket;
61
    is(
62
        ref($basket), 'Koha::Acquisition::Basket',
63
        'Koha::Edifact::File->basket should return a Koha::Acquisition::Basket'
64
    );
65
66
    $file->basketno(undef)->store;
67
    is( $file->basket, undef, 'Koha::Edifact::File->basket should return undef if no basket linked' );
68
69
    $schema->storage->txn_rollback;
70
};
71
72
1;
(-)a/t/db_dependent/api/v1/edifact_files.t (-1 / +110 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 JSON qw(encode_json);
27
28
use Koha::Edifact::Files;
29
use Koha::Database;
30
31
my $schema  = Koha::Database->new->schema;
32
my $builder = t::lib::TestBuilder->new;
33
34
my $t = Test::Mojo->new('Koha::REST::V1');
35
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
36
37
subtest 'list() tests' => sub {
38
39
    plan tests => 20;
40
41
    $schema->storage->txn_begin;
42
43
    Koha::Edifact::Files->search->delete;
44
45
    my $librarian = $builder->build_object(
46
        {
47
            class => 'Koha::Patrons',
48
            value => { flags => 2**11 }    #acquisition
49
        }
50
    );
51
    my $password = 'thePassword123';
52
    $librarian->set_password( { password => $password, skip_validation => 1 } );
53
    my $userid = $librarian->userid;
54
55
    my $patron = $builder->build_object(
56
        {
57
            class => 'Koha::Patrons',
58
            value => { flags => 0 }
59
        }
60
    );
61
62
    $patron->set_password( { password => $password, skip_validation => 1 } );
63
    my $unauth_userid = $patron->userid;
64
65
    ## Authorized user tests
66
    # No acquisitions\/edifiles, so empty array should be returned
67
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is( [] );
68
69
    my $file = $builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'ORDER' } } );
70
71
    # One file created, should get returned
72
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is( [ $file->to_api ] );
73
74
    my $another_file_ORDER =
75
        $builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'ORDER' } } );
76
    my $another_file_QUOTE =
77
        $builder->build_object( { class => 'Koha::Edifact::Files', value => { message_type => 'QUOTE' } } );
78
79
    # Two files created, they should both be returned
80
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles")->status_is(200)->json_is(
81
        [
82
            $file->to_api,
83
            $another_file_ORDER->to_api,
84
            $another_file_QUOTE->to_api
85
        ]
86
    );
87
88
    # Filtering works, two files sharing type
89
    my $api_filter = encode_json( { 'me.type' => ['ORDER'] } );
90
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?q=$api_filter")->status_is(200)->json_is(
91
        [
92
            $file->to_api,
93
            $another_file_ORDER->to_api
94
        ]
95
    );
96
97
    $api_filter = encode_json( { 'me.filename' => $file->filename } );
98
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?q=$api_filter")->status_is(200)
99
        ->json_is( [ $file->to_api ] );
100
101
    # Warn on unsupported query parameter
102
    $api_filter = encode_json( { 'me.file_blah' => 'blah' } );
103
    $t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?file_blah=blah")->status_is(400)
104
        ->json_is( [ { path => '/query/file_blah', message => 'Malformed query string' } ] );
105
106
    # Unauthorized access
107
    $t->get_ok("//$unauth_userid:$password@/api/v1/acquisitions/edifiles")->status_is(403);
108
109
    $schema->storage->txn_rollback;
110
};

Return to bug 30070