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

(-)a/t/db_dependent/api/v1/ill_backends.t (+214 lines)
Line 0 Link Here
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
22
use Test::MockModule;
23
use Test::MockObject;
24
use Test::Mojo;
25
26
use t::lib::TestBuilder;
27
use t::lib::Mocks;
28
29
use Koha::AuthorisedValueCategories;
30
use Koha::Illrequests;
31
32
my $schema  = Koha::Database->new->schema;
33
my $builder = t::lib::TestBuilder->new;
34
35
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
36
37
my $t = Test::Mojo->new('Koha::REST::V1');
38
39
subtest 'list() tests' => sub {
40
41
    plan tests => 16;
42
43
    # Mock Illrequest::Config (as module)
44
    my $illconfig_module = Test::MockModule->new('Koha::Illrequest::Config');
45
46
    # Start with no backends installed
47
    $illconfig_module->mock( 'available_backends', sub { () } );
48
49
    # Mock ILLBackend (as object)
50
    my $backend = Test::MockObject->new;
51
    $backend->set_isa('Koha::Illbackends::Mock');
52
    $backend->set_always( 'name',         'Mock' );
53
    $backend->set_always( 'capabilities', sub { return 'bar'; } );
54
    $backend->mock(
55
        'metadata',
56
        sub {
57
            my ( $self, $rq ) = @_;
58
            return {
59
                ID    => $rq->illrequest_id,
60
                Title => $rq->patron->borrowernumber
61
            };
62
        }
63
    );
64
65
    #Add a backend-specific status
66
    $backend->mock(
67
        'status_graph',
68
        sub {
69
            return {
70
                READY => {
71
                    prev_actions   => [ 'NEW', 'ERROR' ],
72
                    id             => 'READY',
73
                    name           => 'Request ready',
74
                    ui_method_name => 'Mark request as ready',
75
                    method         => 'ready',
76
                    next_actions   => [],
77
                    ui_method_icon => 'fa-check',
78
                }
79
            };
80
        }
81
    );
82
83
    # Mock Koha::Illrequest::load_backend (to load Mocked Backend)
84
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
85
    $illreqmodule->mock( 'load_backend',
86
        sub { my $self = shift; $self->{_my_backend} = $backend; return $self }
87
    );
88
89
    $schema->storage->txn_begin;
90
91
    Koha::Illrequests->search->delete;
92
93
    # create an authorized user
94
    my $librarian = $builder->build_object(
95
        {
96
            class => 'Koha::Patrons',
97
            value => { flags => 2**22 }    # 22 => ill
98
        }
99
    );
100
    my $password = 'thePassword123';
101
    $librarian->set_password( { password => $password, skip_validation => 1 } );
102
    my $userid = $librarian->userid;
103
104
    # create an unauthorized user
105
    my $patron = $builder->build_object(
106
        {
107
            class => 'Koha::Patrons',
108
            value => { flags => 0 }
109
        }
110
    );
111
112
    $patron->set_password( { password => $password, skip_validation => 1 } );
113
    my $unauth_userid = $patron->userid;
114
115
    # Make sure the ILL_STATUS_ALIAS authorised value category is defined
116
    unless (
117
        Koha::AuthorisedValueCategories->search(
118
            { category_name => 'ILL_STATUS_ALIAS' }
119
        )->count > 0
120
      )
121
    {
122
        $builder->build_object(
123
            {
124
                class => 'Koha::AuthorisedValueCategories',
125
                value => { category_name => 'ILL_STATUS_ALIAS' }
126
            }
127
        );
128
    }
129
130
    my $tag     = "Print copy";
131
    my $av_code = "print_copy";
132
    my $av      = $builder->build_object(
133
        {
134
            class => 'Koha::AuthorisedValues',
135
            value => {
136
                category         => 'ILL_STATUS_ALIAS',
137
                authorised_value => $av_code,
138
                lib              => $tag,
139
            }
140
        }
141
    );
142
143
    # No backends, expect empty
144
    $t->get_ok("//$userid:$password@/api/v1/ill/backends")->status_is(200)
145
      ->json_is( [] );
146
147
    # Mock one existing backend
148
    $illconfig_module->mock( 'available_backends', sub { ["Mock"] } );
149
150
    #One backend exists, expect that
151
    $t->get_ok("//$userid:$password@/api/v1/ill/backends")->status_is(200)
152
      ->json_has( '/0/ill_backend_id', 'Mock' );
153
154
    # Prepare status
155
    my $backend_status = {
156
        code => "READY",
157
        str  => "Request ready"
158
    };
159
    my $core_status = {
160
        code => "COMP",
161
        str  => "Completed"
162
    };
163
164
    my $alias_status = {
165
        code => $av_code,
166
        str  => $tag,
167
    };
168
169
    # Create some ILL requests
170
    my $backend_status_req = $builder->build_object(
171
        {
172
            class => 'Koha::Illrequests',
173
            value =>
174
              { status => $backend_status->{code}, backend => $backend->name }
175
        }
176
    );
177
    my $core_status_req = $builder->build_object(
178
        {
179
            class => 'Koha::Illrequests',
180
            value =>
181
              { status => $core_status->{code}, backend => $backend->name }
182
        }
183
    );
184
    my $alias_status_req = $builder->build_object(
185
        {
186
            class => 'Koha::Illrequests',
187
            value => {
188
                status       => $core_status->{code},
189
                backend      => $backend->name,
190
                status_alias => $av->authorised_value
191
            }
192
        }
193
    );
194
195
    #Check for backend existing statuses
196
    $t->get_ok("//$userid:$password@/api/v1/ill/backends/Mock/statuses")
197
      ->status_is(200)
198
      ->json_is( [ $backend_status, $core_status, $alias_status ] );
199
200
    #Check for backend existing statuses of a backend that doesn't exist
201
    $t->get_ok("//$userid:$password@/api/v1/ill/backends/GhostBackend/statuses")
202
      ->status_is(200)
203
      ->json_is( [] );
204
205
    # Unauthorized attempt to list
206
    $t->get_ok("//$unauth_userid:$password@/api/v1/ill/backends")
207
      ->status_is(403);
208
209
    # DELETE method not supported
210
    $t->delete_ok("//$unauth_userid:$password@/api/v1/ill/backends")
211
      ->status_is(404);
212
213
    $schema->storage->txn_rollback;
214
};
(-)a/t/db_dependent/api/v1/ill_requests.t (+237 lines)
Line 0 Link Here
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
22
use Test::MockModule;
23
use Test::MockObject;
24
use Test::Mojo;
25
26
use JSON qw(encode_json);
27
28
use t::lib::TestBuilder;
29
use t::lib::Mocks;
30
31
use Koha::AuthorisedValueCategories;
32
use Koha::Illrequests;
33
use Koha::DateUtils qw( format_sqldatetime );
34
35
my $schema  = Koha::Database->new->schema;
36
my $builder = t::lib::TestBuilder->new;
37
38
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
39
40
my $t = Test::Mojo->new('Koha::REST::V1');
41
42
subtest 'list() tests' => sub {
43
44
    plan tests => 34;
45
46
    # Mock ILLBackend (as object)
47
    my $backend = Test::MockObject->new;
48
    $backend->set_isa('Koha::Illbackends::Mock');
49
    $backend->set_always('name', 'Mock');
50
    $backend->set_always('capabilities', sub { return 'bar'; } );
51
    $backend->mock(
52
        'metadata',
53
        sub {
54
            my ( $self, $rq ) = @_;
55
            return {
56
                ID => $rq->illrequest_id,
57
                Title => $rq->patron->borrowernumber
58
            }
59
        }
60
    );
61
    $backend->mock(
62
        'status_graph', sub {},
63
    );
64
65
    # Mock Koha::Illrequest::load_backend (to load Mocked Backend)
66
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
67
    $illreqmodule->mock( 'load_backend',
68
        sub { my $self = shift; $self->{_my_backend} = $backend; return $self }
69
    );
70
71
    $schema->storage->txn_begin;
72
73
    Koha::Illrequests->search->delete;
74
75
    # create an authorized user
76
    my $librarian = $builder->build_object(
77
        {
78
            class => 'Koha::Patrons',
79
            value => { flags => 2 ** 22 } # 22 => ill
80
        }
81
    );
82
    my $password = 'thePassword123';
83
    $librarian->set_password( { password => $password, skip_validation => 1 } );
84
    my $userid = $librarian->userid;
85
86
    # create an unauthorized user
87
    my $patron = $builder->build_object(
88
        {
89
            class => 'Koha::Patrons',
90
            value => { flags => 0 }
91
        }
92
    );
93
94
    $patron->set_password( { password => $password, skip_validation => 1 } );
95
    my $unauth_userid = $patron->userid;
96
97
    # Make sure the ILL_STATUS_ALIAS authorised value category is defined
98
    unless ( Koha::AuthorisedValueCategories->search( { category_name => 'ILL_STATUS_ALIAS' } )->count > 0 ) {
99
        $builder->build_object(
100
            { class => 'Koha::AuthorisedValueCategories', value => { category_name => 'ILL_STATUS_ALIAS' } } );
101
    }
102
103
    my $tag = "Print copy";
104
    my $av_code = "print_copy";
105
    my $av  = $builder->build_object(
106
        {   class => 'Koha::AuthorisedValues',
107
            value => {
108
                category => 'ILL_STATUS_ALIAS',
109
                authorised_value => $av_code,
110
                lib      => $tag,
111
            }
112
        }
113
    );
114
115
    # No requests, expect empty
116
    $t->get_ok("//$userid:$password@/api/v1/ill/requests")
117
      ->status_is(200)
118
      ->json_is( [] );
119
120
121
    # Prepare some expected response structure
122
    my $request_status = {
123
        code =>"REQ",
124
        str =>"Requested"
125
    };
126
127
    my $response_status = {
128
        backend => $backend->name,
129
        code =>$request_status->{code},
130
        str =>$request_status->{str},
131
        type =>"ill_status"
132
    };
133
134
    my $response_status_av = {
135
        category => "ILL_STATUS_ALIAS",
136
        code => $av_code,
137
        str => $tag,
138
        type => "av"
139
    };
140
141
    # Create some ILL requests
142
    my $req_1 = $builder->build_object({ class => 'Koha::Illrequests', value => { borrowernumber => $patron->borrowernumber, status => $request_status->{code}, backend =>$backend->name } });
143
    my $req_2 = $builder->build_object({ class => 'Koha::Illrequests', value => { status => $request_status->{code}, backend =>$backend->name , status_alias => $av->authorised_value } } );
144
    my $ret   = $builder->build_object({ class => 'Koha::Illrequests', value => { status => 'RET' } } );
145
146
    # Three requests exist, expect all three to be returned
147
    $t->get_ok("//$userid:$password@/api/v1/ill/requests")
148
      ->status_is(200)
149
      ->json_is( [ $req_1->to_api, $req_2->to_api, $ret->to_api ]);
150
151
    my $status_query = encode_json({ status => 'REQ' });
152
    my $status_alias_query = encode_json({ status_av => $av_code });
153
154
    # x-koha-embed: +strings
155
    # Two requests exist with status 'REQ', expect them to be returned
156
    # One of which also has a status_alias, expect that to be in that request's body
157
    $t->get_ok("//$userid:$password@/api/v1/ill/requests?q=$status_query" => {"x-koha-embed" => "+strings"} )
158
      ->status_is(200)
159
      ->json_is( [
160
                { _strings => { status => $response_status }, %{$req_1->to_api} },
161
                { _strings => { status => $response_status, status_av => $response_status_av }, %{$req_2->to_api} }
162
            ]
163
        );
164
165
    # One request with status_alias 'print_copy' exists, expect that to be returned
166
    $t->get_ok("//$userid:$password@/api/v1/ill/requests?q=$status_alias_query" => {"x-koha-embed" => "+strings"} )
167
      ->status_is(200)
168
      ->json_is( [
169
                { _strings => { status => $response_status, status_av => $response_status_av }, %{$req_2->to_api} }
170
            ]
171
        );
172
173
    # x-koha-embed: patron
174
    my $patron_query = encode_json({ borrowernumber => $patron->borrowernumber });
175
176
    # One request related to $patron, make sure it comes back
177
    $t->get_ok("//$userid:$password@/api/v1/ill/requests" => {"x-koha-embed" => "patron"} )
178
      ->status_is(200)
179
      ->json_has('/0/patron', $patron->to_api);
180
181
    # x-koha-embed: comments
182
    # Create comment
183
    my $comment_text = "This is the comment";
184
    my $comment = $builder->build_object({ class => 'Koha::Illcomments', value => { illrequest_id => $req_1->illrequest_id, comment => $comment_text , borrowernumber => $patron->borrowernumber } } );
185
186
    # Make sure comments come back
187
    $t->get_ok("//$userid:$password@/api/v1/ill/requests" => {"x-koha-embed" => "comments"} )
188
      ->status_is(200)
189
      ->json_has('/0/comments', $comment_text);
190
191
    # x-koha-embed: id_prefix
192
    # Mock Illrequest::Config to return a static prefix
193
    my $id_prefix = 'ILL';
194
    my $config = Test::MockObject->new;
195
    $config->set_isa('Koha::Illrequest::Config::Mock');
196
    $config->set_always('getPrefixes', $id_prefix);
197
198
    # Make sure id_prefix comes back
199
    $t->get_ok("//$userid:$password@/api/v1/ill/requests" => {"x-koha-embed" => "id_prefix"} )
200
      ->status_is(200)
201
      ->json_has('/0/id_prefix', $id_prefix);
202
203
    # ILLHiddenRequestStatuses syspref
204
    # Hide 'REQ', expect to return just 1 'RET'
205
    t::lib::Mocks::mock_preference( 'ILLHiddenRequestStatuses', 'REQ' );
206
    $t->get_ok( "//$userid:$password@/api/v1/ill/requests" )
207
      ->status_is(200)
208
      ->json_is( [ $ret->to_api ] );
209
210
    # Hide 'RET', expect to return 2 'REQ'
211
    t::lib::Mocks::mock_preference( 'ILLHiddenRequestStatuses', 'RET' );
212
    $t->get_ok( "//$userid:$password@/api/v1/ill/requests" )
213
      ->status_is(200)
214
      ->json_is( [ $req_1->to_api, $req_2->to_api ]);
215
216
    # Status code
217
    # Warn on unsupported query parameter
218
    $t->get_ok( "//$userid:$password@/api/v1/ill/requests?request_blah=blah" )
219
      ->status_is(400)
220
      ->json_is(
221
        [{ path => '/query/request_blah', message => 'Malformed query string'}]
222
    );
223
224
    # Unauthorized attempt to list
225
    $t->get_ok(
226
        "//$unauth_userid:$password@/api/v1/ill/requests")
227
      ->status_is(403);
228
229
    # DELETE method not supported
230
    $t->delete_ok(
231
        "//$unauth_userid:$password@/api/v1/ill/requests/1")
232
      ->status_is(404);
233
234
    #TODO; test complex query on extended_attributes
235
236
    $schema->storage->txn_rollback;
237
};
(-)a/t/db_dependent/api/v1/illrequests.t (-249 lines)
Lines 1-248 Link Here
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 => 2;
21
22
use Test::MockModule;
23
use Test::MockObject;
24
use Test::Mojo;
25
26
use JSON qw(encode_json);
27
28
use t::lib::TestBuilder;
29
use t::lib::Mocks;
30
31
use Koha::Illrequests;
32
use Koha::DateUtils qw( format_sqldatetime );
33
34
my $schema  = Koha::Database->new->schema;
35
my $builder = t::lib::TestBuilder->new;
36
37
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
38
39
my $t = Test::Mojo->new('Koha::REST::V1');
40
41
subtest 'list_legacy() tests' => sub {
42
43
    plan tests => 30;
44
45
    # Mock ILLBackend (as object)
46
    my $backend = Test::MockObject->new;
47
    $backend->set_isa('Koha::Illbackends::Mock');
48
    $backend->set_always('name', 'Mock');
49
    $backend->set_always('capabilities', sub { return 'bar'; } );
50
    $backend->mock(
51
        'metadata',
52
        sub {
53
            my ( $self, $rq ) = @_;
54
            return {
55
                ID => $rq->illrequest_id,
56
                Title => $rq->patron->borrowernumber
57
            }
58
        }
59
    );
60
    $backend->mock(
61
        'status_graph', sub {},
62
    );
63
64
    # Mock Koha::Illrequest::load_backend (to load Mocked Backend)
65
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
66
    $illreqmodule->mock( 'load_backend',
67
        sub { my $self = shift; $self->{_my_backend} = $backend; return $self }
68
    );
69
70
    $schema->storage->txn_begin;
71
72
    Koha::Illrequests->search->delete;
73
74
    # create an authorized user
75
    my $patron = $builder->build_object({
76
        class => 'Koha::Patrons',
77
        value => { flags => 2 ** 22 } # 22 => ill
78
    });
79
    my $password = 'thePassword123';
80
    $patron->set_password({ password => $password, skip_validation => 1 });
81
    my $userid = $patron->userid;
82
83
    ## Authorized user tests
84
    # No requests, so empty array should be returned
85
    $t->get_ok( "//$userid:$password@/api/v1/illrequests" )
86
      ->status_is(200)
87
      ->json_is( [] );
88
89
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
90
    my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } );
91
    my $patron_2 = $builder->build_object( { class => 'Koha::Patrons' } );
92
93
    # Create an ILL request
94
    my $illrequest = $builder->build_object(
95
        {
96
            class => 'Koha::Illrequests',
97
            value => {
98
                backend        => 'Mock',
99
                biblio_id      => undef,
100
                branchcode     => $library->branchcode,
101
                borrowernumber => $patron_1->borrowernumber,
102
                status         => 'STATUS1',
103
            }
104
        }
105
    );
106
107
    # The api response is always augmented with the id_prefix
108
    my $response = $illrequest->unblessed;
109
    $response->{id_prefix} = $illrequest->id_prefix;
110
111
    my $req_formatted = add_formatted($response);
112
113
    # One illrequest created, should get returned
114
    $t->get_ok( "//$userid:$password@/api/v1/illrequests" )
115
      ->status_is(200)
116
      ->json_is( [ $req_formatted ] );
117
118
    # One illrequest created, returned with augmented data
119
    $t->get_ok( "//$userid:$password@/api/v1/illrequests?embed=patron,library,capabilities,metadata,requested_partners" )
120
      ->status_is(200)
121
      ->json_has( '/0/patron', 'patron embedded' )
122
      ->json_is( '/0/patron/patron_id', $patron_1->borrowernumber, 'The right patron is embeded')
123
      ->json_has( '/0/requested_partners', 'requested_partners embedded' )
124
      ->json_has( '/0/capabilities', 'capabilities embedded' )
125
      ->json_has( '/0/library', 'library embedded'  )
126
      ->json_has( '/0/metadata', 'metadata embedded'  )
127
      ->json_hasnt( '/1', 'Only one request was created' );
128
129
    # Create another ILL request
130
    my $illrequest2 = $builder->build_object(
131
        {
132
            class => 'Koha::Illrequests',
133
            value => {
134
                backend        => 'Mock',
135
                biblio_id      => undef,
136
                branchcode     => $library->branchcode,
137
                borrowernumber => $patron_2->borrowernumber,
138
                status         => 'STATUS2',
139
            }
140
        }
141
    );
142
143
    # The api response is always augmented with the id_prefix
144
    my $response2 = $illrequest2->unblessed;
145
    $response2->{id_prefix} = $illrequest2->id_prefix;
146
147
    my $req2_formatted = add_formatted($response2);
148
149
    # Two illrequest created, should get returned
150
    $t->get_ok( "//$userid:$password@/api/v1/illrequests" )
151
      ->status_is(200)
152
      ->json_is( [ $req_formatted, $req2_formatted ] );
153
154
    # Warn on unsupported query parameter
155
    $t->get_ok( "//$userid:$password@/api/v1/illrequests?request_blah=blah" )
156
      ->status_is(400)
157
      ->json_is(
158
        [{ path => '/query/request_blah', message => 'Malformed query string'}]
159
    );
160
161
    # Test the borrowernumber parameter
162
    $t->get_ok( "//$userid:$password@/api/v1/illrequests?borrowernumber=" . $patron_2->borrowernumber )
163
      ->status_is(200)
164
      ->json_is( [ $response2 ] );
165
166
    # Test the ILLHiddenRequestStatuses syspref
167
    t::lib::Mocks::mock_preference( 'ILLHiddenRequestStatuses', 'STATUS1' );
168
    $t->get_ok( "//$userid:$password@/api/v1/illrequests" )
169
      ->status_is(200)
170
      ->json_is( [ $req2_formatted ] );
171
172
    t::lib::Mocks::mock_preference( 'ILLHiddenRequestStatuses', 'STATUS2' );
173
    $t->get_ok( "//$userid:$password@/api/v1/illrequests" )
174
      ->status_is(200)
175
      ->json_is( [ $req_formatted ] );
176
177
    $schema->storage->txn_rollback;
178
};
179
180
subtest 'list() tests' => sub {
181
182
    plan tests => 9;
183
184
    $schema->storage->txn_begin;
185
186
    Koha::Illrequests->search->delete;
187
188
    my $librarian = $builder->build_object(
189
        {
190
            class => 'Koha::Patrons',
191
            value => { flags => 2 ** 22 } # 22 => ill
192
        }
193
    );
194
    my $password = 'thePassword123';
195
    $librarian->set_password( { password => $password, skip_validation => 1 } );
196
    my $userid = $librarian->userid;
197
198
    my $patron = $builder->build_object(
199
        {
200
            class => 'Koha::Patrons',
201
            value => { flags => 0 }
202
        }
203
    );
204
205
    $patron->set_password( { password => $password, skip_validation => 1 } );
206
    my $unauth_userid = $patron->userid;
207
208
    $t->get_ok("//$userid:$password@/api/v1/ill_requests")
209
      ->status_is(200)
210
      ->json_is( [] );
211
212
    my $req_1 = $builder->build_object({ class => 'Koha::Illrequests', value => { biblio_id => undef, status => 'REQ' } });
213
    my $req_2 = $builder->build_object({ class => 'Koha::Illrequests', value => { biblio_id => undef, status => 'REQ' } } );
214
    my $ret   = $builder->build_object({ class => 'Koha::Illrequests', value => { biblio_id => undef, status => 'RET' } } );
215
216
    $t->get_ok("//$userid:$password@/api/v1/ill_requests")
217
      ->status_is(200)
218
      ->json_is( [ $req_1->to_api, $req_2->to_api, $ret->to_api ]);
219
220
    my $query = encode_json({ status => 'REQ' });
221
222
    # Filtering works
223
    $t->get_ok("//$userid:$password@/api/v1/ill_requests?q=$query" )
224
      ->status_is(200)
225
      ->json_is( [ $req_1->to_api, $req_2->to_api ]);
226
227
    $schema->storage->txn_rollback;
228
};
229
230
sub add_formatted {
231
    my $req = shift;
232
    my @format_dates = ( 'placed', 'updated', 'completed' );
233
    # We need to embellish the request with properties that the API
234
    # controller calculates on the fly
235
    # Create new "formatted" columns for each date column
236
    # that needs formatting
237
    foreach my $field(@format_dates) {
238
        if (defined $req->{$field}) {
239
            $req->{$field . "_formatted"} = format_sqldatetime(
240
                $req->{$field},
241
                undef,
242
                undef,
243
                1
244
            );
245
        }
246
    }
247
    return $req;
248
}
249
- 

Return to bug 22440