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

(-)a/t/db_dependent/api/v1/checkouts.t (-36 / +8 lines)
Lines 27-39 use DateTime; Link Here
27
use MARC::Record;
27
use MARC::Record;
28
28
29
use C4::Context;
29
use C4::Context;
30
use C4::Biblio;
31
use C4::Circulation;
30
use C4::Circulation;
32
use C4::Items;
33
31
34
use Koha::Database;
32
use Koha::Database;
35
use Koha::DateUtils;
33
use Koha::DateUtils;
36
use Koha::Patron;
37
34
38
my $schema = Koha::Database->schema;
35
my $schema = Koha::Database->schema;
39
my $builder = t::lib::TestBuilder->new;
36
my $builder = t::lib::TestBuilder->new;
Lines 91-100 $t->request_ok($tx) Link Here
91
  ->status_is(200)
88
  ->status_is(200)
92
  ->json_is([]);
89
  ->json_is([]);
93
90
94
my $biblionumber = create_biblio('RESTful Web APIs');
91
my $biblionumber = $builder->build_sample_biblio({ title => 'RESTful Web APIs'})->biblionumber;
95
my $itemnumber1 = create_item($biblionumber, 'TEST000001');
92
my $itemnumber1 = $builder->build_sample_item({ biblionumber => $biblionumber, barcode => 'TEST000001'})->itemnumber;
96
my $itemnumber2 = create_item($biblionumber, 'TEST000002');
93
my $itemnumber2 = $builder->build_sample_item({ biblionumber => $biblionumber, barcode => 'TEST000002'})->itemnumber;
97
my $itemnumber3 = create_item($biblionumber, 'TEST000003');
94
my $itemnumber3 = $builder->build_sample_item({ biblionumber => $biblionumber, barcode => 'TEST000003'})->itemnumber;
98
95
99
my $date_due = DateTime->now->add(weeks => 2);
96
my $date_due = DateTime->now->add(weeks => 2);
100
my $issue1 = C4::Circulation::AddIssue($patron, 'TEST000001', $date_due);
97
my $issue1 = C4::Circulation::AddIssue($patron, 'TEST000001', $date_due);
Lines 122-136 $t->request_ok($tx) Link Here
122
  ->status_is(403)
119
  ->status_is(403)
123
  ->json_is({ error => "Authorization failure. Missing required permission(s).",
120
  ->json_is({ error => "Authorization failure. Missing required permission(s).",
124
              required_permissions => { circulate => "circulate_remaining_permissions" }
121
              required_permissions => { circulate => "circulate_remaining_permissions" }
125
						});
122
            });
126
123
127
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts?patron_id=".$loggedinuser->{borrowernumber});
124
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts?patron_id=".$loggedinuser->{borrowernumber});
128
$tx->req->cookies({name => 'CGISESSID', value => $patron_session->id});
125
$tx->req->cookies({name => 'CGISESSID', value => $patron_session->id});
129
$t->request_ok($tx)
126
$t->request_ok($tx)
130
  ->status_is(403)
127
  ->status_is(403)
131
  ->json_is({ error => "Authorization failure. Missing required permission(s).",
128
  ->json_is({ error => "Authorization failure. Missing required permission(s).",
132
						  required_permissions => { circulate => "circulate_remaining_permissions" }
129
              required_permissions => { circulate => "circulate_remaining_permissions" }
133
					  });
130
            });
134
131
135
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts?patron_id=$borrowernumber");
132
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts?patron_id=$borrowernumber");
136
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
133
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
Lines 185-191 $t->request_ok($tx) Link Here
185
  ->status_is(403)
182
  ->status_is(403)
186
  ->json_is({ error => "Authorization failure. Missing required permission(s).",
183
  ->json_is({ error => "Authorization failure. Missing required permission(s).",
187
              required_permissions => { circulate => "circulate_remaining_permissions" }
184
              required_permissions => { circulate => "circulate_remaining_permissions" }
188
						});
185
            });
189
186
190
$tx = $t->ua->build_tx(PUT => "/api/v1/checkouts/" . $issue2->issue_id);
187
$tx = $t->ua->build_tx(PUT => "/api/v1/checkouts/" . $issue2->issue_id);
191
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
188
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
Lines 199-225 $t->request_ok($tx) Link Here
199
  ->status_is(403)
196
  ->status_is(403)
200
  ->json_is({ error => 'Renewal not authorized (too_many)' });
197
  ->json_is({ error => 'Renewal not authorized (too_many)' });
201
198
202
sub create_biblio {
203
    my ($title) = @_;
204
205
    my $record = new MARC::Record;
206
    $record->append_fields(
207
        new MARC::Field('200', ' ', ' ', a => $title),
208
    );
209
210
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
211
212
    return $biblionumber;
213
}
214
215
sub create_item {
216
    my ($biblionumber, $barcode) = @_;
217
218
    my $item = {
219
        barcode => $barcode,
220
    };
221
222
    my $itemnumber = C4::Items::AddItem($item, $biblionumber);
223
224
    return $itemnumber;
225
}
226
- 

Return to bug 13895