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

(-)a/Koha/REST/V1/Checkout.pm (+39 lines)
Lines 23-28 use C4::Auth qw( haspermission ); Link Here
23
use C4::Context;
23
use C4::Context;
24
use C4::Circulation;
24
use C4::Circulation;
25
use Koha::Issues;
25
use Koha::Issues;
26
use Koha::OldIssues;
26
27
27
sub list {
28
sub list {
28
    my ($c, $args, $cb) = @_;
29
    my ($c, $args, $cb) = @_;
Lines 86-89 sub renew { Link Here
86
    return $c->$cb($checkout->unblessed, 200);
87
    return $c->$cb($checkout->unblessed, 200);
87
}
88
}
88
89
90
sub listhistory {
91
    my ($c, $args, $cb) = @_;
92
93
    my $borrowernumber = $c->param('borrowernumber');
94
95
    my %attributes = ( itemnumber => { "!=", undef } );
96
    if ($borrowernumber) {
97
        return $c->$cb({
98
            error => "Patron doesn't exist"
99
        }, 404) unless Koha::Patrons->find($borrowernumber);
100
101
        $attributes{borrowernumber} = $borrowernumber;
102
    }
103
104
    # Retrieve all the issues in the history, but only the issue_id due to possible perfomance issues
105
    my $checkouts = Koha::OldIssues->search(
106
      \%attributes,
107
      { columns => [qw/issue_id/]}
108
    );
109
110
    $c->$cb($checkouts->unblessed, 200);
111
}
112
113
sub gethistory {
114
    my ($c, $args, $cb) = @_;
115
116
    my $checkout_id = $args->{checkout_id};
117
    my $checkout = Koha::OldIssues->find($checkout_id);
118
119
    if (!$checkout) {
120
        return $c->$cb({
121
            error => "Checkout doesn't exist"
122
        }, 404);
123
    }
124
125
    return $c->$cb($checkout->unblessed, 200);
126
}
127
89
1;
128
1;
(-)a/api/v1/swagger.json (+516 lines)
Line 0 Link Here
1
{
2
  "swagger": "2.0",
3
  "info": {
4
    "title": "Koha REST API",
5
    "version": "1",
6
    "license": {
7
      "name": "GPL v3",
8
      "url": "http://www.gnu.org/licenses/gpl.txt"
9
    },
10
    "contact": {
11
      "name": "Koha Team",
12
      "url": "http://koha-community.org/"
13
    }
14
  },
15
  "basePath": "/api/v1",
16
  "paths": {
17
    "/patrons": {
18
      "get": {
19
        "operationId": "listPatrons",
20
        "tags": ["patrons"],
21
        "produces": [
22
          "application/json"
23
        ],
24
        "responses": {
25
          "200": {
26
            "description": "A list of patrons",
27
            "schema": {
28
              "type": "array",
29
              "items": {
30
                "$ref": "#/definitions/patron"
31
              }
32
            }
33
          },
34
          "403": {
35
            "description": "Access forbidden",
36
            "schema": {
37
              "$ref": "#/definitions/error"
38
            }
39
          }
40
        }
41
      }
42
    },
43
    "/patrons/{borrowernumber}": {
44
      "get": {
45
        "operationId": "getPatron",
46
        "tags": ["patrons"],
47
        "parameters": [
48
          {
49
            "$ref": "#/parameters/borrowernumberPathParam"
50
          }
51
        ],
52
        "produces": [
53
          "application/json"
54
        ],
55
        "responses": {
56
          "200": {
57
            "description": "A patron",
58
            "schema": {
59
              "$ref": "#/definitions/patron"
60
            }
61
          },
62
          "403": {
63
            "description": "Access forbidden",
64
            "schema": {
65
              "$ref": "#/definitions/error"
66
            }
67
          },
68
          "404": {
69
            "description": "Patron not found",
70
            "schema": {
71
              "$ref": "#/definitions/error"
72
            }
73
          }
74
        }
75
      }
76
    },
77
    "/holds": {
78
      "get": {
79
        "operationId": "listHolds",
80
        "tags": ["borrowers", "holds"],
81
        "parameters": [
82
          {
83
            "name": "reserve_id",
84
            "in": "query",
85
            "description": "Internal reserve identifier",
86
            "type": "integer"
87
          },
88
          {
89
            "name": "borrowernumber",
90
            "in": "query",
91
            "description": "Internal borrower identifier",
92
            "type": "integer"
93
          },
94
          {
95
            "name": "reservedate",
96
            "in": "query",
97
            "description": "Reserve date",
98
            "type": "string"
99
          },
100
          {
101
            "name": "biblionumber",
102
            "in": "query",
103
            "description": "Internal biblio identifier",
104
            "type": "integer"
105
          },
106
          {
107
            "name": "branchcode",
108
            "in": "query",
109
            "description": "Branch code",
110
            "type": "string"
111
          },
112
          {
113
            "name": "notificationdate",
114
            "in": "query",
115
            "description": "Notification date",
116
            "type": "string"
117
          },
118
          {
119
            "name": "reminderdate",
120
            "in": "query",
121
            "description": "Reminder date",
122
            "type": "string"
123
          },
124
          {
125
            "name": "cancellationdate",
126
            "in": "query",
127
            "description": "Cancellation date",
128
            "type": "string"
129
          },
130
          {
131
            "name": "reservenotes",
132
            "in": "query",
133
            "description": "Reserve notes",
134
            "type": "string"
135
          },
136
          {
137
            "name": "priority",
138
            "in": "query",
139
            "description": "Priority",
140
            "type": "integer"
141
          },
142
          {
143
            "name": "found",
144
            "in": "query",
145
            "description": "Found status",
146
            "type": "string"
147
          },
148
          {
149
            "name": "timestamp",
150
            "in": "query",
151
            "description": "Time of latest update",
152
            "type": "string"
153
          },
154
          {
155
            "name": "itemnumber",
156
            "in": "query",
157
            "description": "Internal item identifier",
158
            "type": "integer"
159
          },
160
          {
161
            "name": "waitingdate",
162
            "in": "query",
163
            "description": "Date the item was marked as waiting for the patron",
164
            "type": "string"
165
          },
166
          {
167
            "name": "expirationdate",
168
            "in": "query",
169
            "description": "Date the hold expires",
170
            "type": "string"
171
          },
172
          {
173
            "name": "lowestPriority",
174
            "in": "query",
175
            "description": "Lowest priority",
176
            "type": "integer"
177
          },
178
          {
179
            "name": "suspend",
180
            "in": "query",
181
            "description": "Suspended",
182
            "type": "integer"
183
          },
184
          {
185
            "name": "suspend_until",
186
            "in": "query",
187
            "description": "Suspended until",
188
            "type": "string"
189
          }
190
        ],
191
        "produces": ["application/json"],
192
        "responses": {
193
          "200": {
194
            "description": "A list of holds",
195
            "schema": { "$ref": "#/definitions/holds" }
196
          },
197
          "404": {
198
            "description": "Borrower not found",
199
            "schema": { "$ref": "#/definitions/error" }
200
          }
201
        }
202
      },
203
      "post": {
204
        "operationId": "addHold",
205
        "tags": ["borrowers", "holds"],
206
        "parameters": [
207
          {
208
            "name": "body",
209
            "in": "body",
210
            "description": "A JSON object containing informations about the new hold",
211
            "required": true,
212
            "schema": {
213
              "type": "object",
214
              "properties": {
215
                "borrowernumber": {
216
                  "description": "Borrower internal identifier",
217
                  "type": "integer"
218
                },
219
                "biblionumber": {
220
                  "description": "Biblio internal identifier",
221
                  "type": "integer"
222
                },
223
                "itemnumber": {
224
                  "description": "Item internal identifier",
225
                  "type": "integer"
226
                },
227
                "branchcode": {
228
                  "description": "Pickup location",
229
                  "type": "string"
230
                },
231
                "expirationdate": {
232
                  "description": "Hold end date",
233
                  "type": "string",
234
                  "format": "date"
235
                }
236
              }
237
            }
238
          }
239
        ],
240
        "consumes": ["application/json"],
241
        "produces": ["application/json"],
242
        "responses": {
243
          "201": {
244
            "description": "Created hold",
245
            "schema": { "$ref": "#/definitions/hold" }
246
          },
247
          "400": {
248
            "description": "Missing or wrong parameters",
249
            "schema": { "$ref": "#/definitions/error" }
250
          },
251
          "403": {
252
            "description": "Hold not allowed",
253
            "schema": { "$ref": "#/definitions/error" }
254
          },
255
          "404": {
256
            "description": "Borrower not found",
257
            "schema": { "$ref": "#/definitions/error" }
258
          },
259
          "500": {
260
            "description": "Internal error",
261
            "schema": { "$ref": "#/definitions/error" }
262
          }
263
        }
264
      }
265
    },
266
    "/holds/{reserve_id}": {
267
      "put": {
268
        "operationId": "editHold",
269
        "tags": ["holds"],
270
        "parameters": [
271
          { "$ref": "#/parameters/holdIdPathParam" },
272
          {
273
            "name": "body",
274
            "in": "body",
275
            "description": "A JSON object containing fields to modify",
276
            "required": true,
277
            "schema": {
278
              "type": "object",
279
              "properties": {
280
                "priority": {
281
                  "description": "Position in waiting queue",
282
                  "type": "integer",
283
                  "minimum": 1
284
                },
285
                "branchcode": {
286
                  "description": "Pickup location",
287
                  "type": "string"
288
                },
289
                "suspend_until": {
290
                  "description": "Suspend until",
291
                  "type": "string",
292
                  "format": "date"
293
                }
294
              }
295
            }
296
          }
297
        ],
298
        "consumes": ["application/json"],
299
        "produces": ["application/json"],
300
        "responses": {
301
          "200": {
302
            "description": "Updated hold",
303
            "schema": { "$ref": "#/definitions/hold" }
304
          },
305
          "400": {
306
            "description": "Missing or wrong parameters",
307
            "schema": { "$ref": "#/definitions/error" }
308
          },
309
          "404": {
310
            "description": "Hold not found",
311
            "schema": { "$ref": "#/definitions/error" }
312
          }
313
        }
314
      },
315
      "delete": {
316
        "operationId": "deleteHold",
317
        "tags": ["holds"],
318
        "parameters": [
319
          { "$ref": "#/parameters/holdIdPathParam" }
320
        ],
321
        "produces": ["application/json"],
322
        "responses": {
323
          "200": {
324
            "description": "Successful deletion",
325
            "schema": {
326
              "type": "object"
327
            }
328
          },
329
          "404": {
330
            "description": "Hold not found",
331
            "schema": { "$ref": "#/definitions/error" }
332
          }
333
        }
334
      }
335
    },
336
    "/checkouts": {
337
      "get": {
338
        "operationId": "listCheckouts",
339
        "tags": ["borrowers", "checkouts"],
340
        "parameters": [
341
          {
342
            "name": "borrowernumber",
343
            "in": "query",
344
            "description": "Internal patron identifier",
345
            "required": false,
346
            "type": "integer"
347
          }
348
        ],
349
        "produces": [
350
          "application/json"
351
        ],
352
        "responses": {
353
          "200": {
354
            "description": "A list of checkouts",
355
            "schema": {
356
              "$ref": "#/definitions/checkouts"
357
            }
358
          },
359
          "403": {
360
            "description": "Access forbidden",
361
            "schema": { "$ref": "#/definitions/error" }
362
          },
363
          "404": {
364
            "description": "Borrower not found",
365
            "schema": {
366
              "$ref": "#/definitions/error"
367
            }
368
          }
369
        }
370
      }
371
    },
372
    "/checkouts/{checkout_id}": {
373
      "get": {
374
        "operationId": "getCheckout",
375
        "tags": ["borrowers", "checkouts"],
376
        "parameters": [
377
          {
378
            "name": "checkout_id",
379
            "in": "path",
380
            "description": "Internal checkout identifier",
381
            "required": true,
382
            "type": "integer"
383
          }
384
        ],
385
        "produces": ["application/json"],
386
        "responses": {
387
          "200": {
388
            "description": "Updated borrower's checkout",
389
            "schema": { "$ref": "#/definitions/checkout" }
390
          },
391
          "403": {
392
            "description": "Access forbidden",
393
            "schema": { "$ref": "#/definitions/error" }
394
          },
395
          "404": {
396
            "description": "Checkout not found",
397
            "schema": { "$ref": "#/definitions/error" }
398
          }
399
        }
400
      },
401
      "put": {
402
        "operationId": "renewCheckout",
403
        "tags": ["borrowers", "checkouts"],
404
        "parameters": [
405
          {
406
            "name": "checkout_id",
407
            "in": "path",
408
            "description": "Internal checkout identifier",
409
            "required": true,
410
            "type": "integer"
411
          }
412
        ],
413
        "produces": ["application/json"],
414
        "responses": {
415
          "200": {
416
            "description": "Updated borrower's checkout",
417
            "schema": { "$ref": "#/definitions/checkout" }
418
          },
419
          "403": {
420
            "description": "Cannot renew checkout",
421
            "schema": { "$ref": "#/definitions/error" }
422
          },
423
          "404": {
424
            "description": "Checkout not found",
425
            "schema": { "$ref": "#/definitions/error" }
426
          }
427
        }
428
      }
429
    },
430
    "/checkouts/history": {
431
      "get": {
432
        "operationId": "listhistoryCheckouts",
433
        "tags": ["patrons", "checkouts"],
434
        "parameters": [
435
          {
436
            "name": "borrowernumber",
437
            "in": "query",
438
            "description": "Internal patron identifier",
439
            "required": false,
440
            "type": "integer"
441
          }
442
        ],
443
        "produces": [
444
          "application/json"
445
        ],
446
        "responses": {
447
          "200": {
448
            "description": "A list of checkouts history",
449
            "schema": {
450
              "$ref": "#/definitions/checkouts"
451
            }
452
          },
453
          "403": {
454
            "description": "Access forbidden",
455
            "schema": { "$ref": "#/definitions/error" }
456
          },
457
          "404": {
458
            "description": "Borrower not found",
459
            "schema": {
460
              "$ref": "#/definitions/error"
461
            }
462
          }
463
        }
464
      }
465
    },
466
    "/checkouts/history/{checkout_id}": {
467
      "get": {
468
        "operationId": "gethistoryCheckout",
469
        "tags": ["patrons", "checkouts"],
470
        "parameters": [
471
          {
472
            "name": "checkout_id",
473
            "in": "path",
474
            "description": "Internal checkout identifier",
475
            "required": true,
476
            "type": "integer"
477
          }
478
        ],
479
        "produces": ["application/json"],
480
        "responses": {
481
          "200": {
482
            "description": "Got borrower's checkout",
483
            "schema": { "$ref": "#/definitions/checkout" }
484
          },
485
          "403": {
486
            "description": "Access forbidden",
487
            "schema": { "$ref": "#/definitions/error" }
488
          },
489
          "404": {
490
            "description": "Checkout not found",
491
            "schema": { "$ref": "#/definitions/error" }
492
          }
493
        }
494
      }
495
    }
496
  },
497
  "definitions": {
498
    "$ref": "./definitions/index.json"
499
  },
500
  "parameters": {
501
    "borrowernumberPathParam": {
502
      "name": "borrowernumber",
503
      "in": "path",
504
      "description": "Internal patron identifier",
505
      "required": true,
506
      "type": "integer"
507
    },
508
    "holdIdPathParam": {
509
      "name": "reserve_id",
510
      "in": "path",
511
      "description": "Internal hold identifier",
512
      "required": true,
513
      "type": "integer"
514
    }
515
  }
516
}
(-)a/api/v1/swagger/paths.json (+6 lines)
Lines 11-16 Link Here
11
  "/checkouts/{checkout_id}": {
11
  "/checkouts/{checkout_id}": {
12
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}"
12
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}"
13
  },
13
  },
14
  "/checkouts/history": {
15
    "$ref": "paths/checkouts.json#/~1checkouts~1history"
16
  },
17
  "/checkouts/history/{checkout_id}": {
18
    "$ref": "paths/checkouts.json#/~1checkouts~1history~1{checkout_id}"
19
  },
14
  "/patrons": {
20
  "/patrons": {
15
    "$ref": "paths/patrons.json#/~1patrons"
21
    "$ref": "paths/patrons.json#/~1patrons"
16
  },
22
  },
(-)a/api/v1/swagger/paths/checkouts.json (+68 lines)
Lines 93-97 Link Here
93
        }
93
        }
94
      }
94
      }
95
    }
95
    }
96
  },
97
  "/checkouts/history": {
98
    "get": {
99
      "operationId": "listhistoryCheckouts",
100
      "tags": ["patrons", "checkouts"],
101
      "parameters": [
102
        { "$ref": "../parameters.json#/borrowernumberQueryParam" }
103
      ],
104
      "produces": [
105
        "application/json"
106
      ],
107
      "responses": {
108
        "200": {
109
          "description": "A list of checkouts history",
110
          "schema": {
111
            "$ref": "../definitions.json#/checkouts"
112
          }
113
        },
114
        "403": {
115
          "description": "Access forbidden",
116
          "schema": { "$ref": "../definitions.json#/error" }
117
        },
118
        "404": {
119
          "description": "Borrower not found",
120
          "schema": {
121
            "$ref": "../definitions.json#/error"
122
          }
123
        }
124
      },
125
      "x-koha-authorization": {
126
        "allow-owner": true,
127
        "allow-guarantor": true,
128
        "permissions": {
129
          "circulate_remaining_permissions": "1"
130
        }
131
      }
132
    }
133
  },
134
  "/checkouts/history/{checkout_id}": {
135
    "get": {
136
      "operationId": "gethistoryCheckout",
137
      "tags": ["patrons", "checkouts"],
138
      "parameters": [
139
        { "$ref": "../parameters.json#/checkoutIdPathParam" }
140
      ],
141
      "produces": ["application/json"],
142
      "responses": {
143
        "200": {
144
          "description": "Got borrower's checkout",
145
          "schema": { "$ref": "../definitions.json#/checkout" }
146
        },
147
        "403": {
148
          "description": "Access forbidden",
149
          "schema": { "$ref": "../definitions.json#/error" }
150
        },
151
        "404": {
152
          "description": "Checkout not found",
153
          "schema": { "$ref": "../definitions.json#/error" }
154
        }
155
      },
156
      "x-koha-authorization": {
157
        "allow-owner": true,
158
        "allow-guarantor": true,
159
        "permissions": {
160
          "circulate_remaining_permissions": "1"
161
        }
162
      }
163
    }
96
  }
164
  }
97
}
165
}
(-)a/t/db_dependent/api/v1/checkoutshistory.t (-1 / +187 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 under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Test::More tests => 31;
21
use Test::MockModule;
22
use Test::Mojo;
23
use t::lib::TestBuilder;
24
25
use DateTime;
26
use MARC::Record;
27
28
use C4::Context;
29
use C4::Biblio;
30
use C4::Circulation;
31
use C4::Items;
32
33
use Koha::Database;
34
use Koha::Patron;
35
use Koha::OldIssue;
36
use Koha::OldIssues;
37
38
my $schema = Koha::Database->schema;
39
$schema->storage->txn_begin;
40
my $dbh = C4::Context->dbh;
41
my $builder = t::lib::TestBuilder->new;
42
$dbh->{RaiseError} = 1;
43
44
$ENV{REMOTE_ADDR} = '127.0.0.1';
45
my $t = Test::Mojo->new('Koha::REST::V1');
46
47
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
48
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
49
50
$dbh->do('DELETE FROM issues');
51
$dbh->do('DELETE FROM items');
52
$dbh->do('DELETE FROM issuingrules');
53
my $loggedinuser = $builder->build({ source => 'Borrower' });
54
55
$dbh->do(q{
56
    INSERT INTO user_permissions (borrowernumber, module_bit, code)
57
    VALUES (?, 1, 'circulate_remaining_permissions')
58
}, undef, $loggedinuser->{borrowernumber});
59
60
my $session = C4::Auth::get_session('');
61
$session->param('number', $loggedinuser->{ borrowernumber });
62
$session->param('id', $loggedinuser->{ userid });
63
$session->param('ip', '127.0.0.1');
64
$session->param('lasttime', time());
65
$session->flush;
66
67
my $nopermission = $builder->build({
68
    source => 'Borrower',
69
    value => {
70
        branchcode   => $branchcode,
71
        categorycode => $categorycode,
72
        flags        => 0,
73
    }
74
});
75
76
my $session_nopermission = C4::Auth::get_session('');
77
$session_nopermission->param('number', $nopermission->{ borrowernumber });
78
$session_nopermission->param('id', $nopermission->{ userid });
79
$session_nopermission->param('ip', '127.0.0.1');
80
$session_nopermission->param('lasttime', time());
81
$session_nopermission->flush;
82
83
my $borrower = $builder->build({ source => 'Borrower' });
84
my $borrowernumber = $borrower->{borrowernumber};
85
86
my $module = new Test::MockModule('C4::Context');
87
$module->mock('userenv', sub { { branch => $branchcode } });
88
89
my $tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$borrowernumber");
90
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
91
$t->request_ok($tx)
92
  ->status_is(200)
93
  ->json_is([]);
94
95
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$borrowernumber");
96
$t->request_ok($tx)
97
  ->status_is(401);
98
99
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$borrowernumber");
100
$tx->req->cookies({name => 'CGISESSID', value => $session_nopermission->id});
101
$t->request_ok($tx)
102
  ->status_is(403);
103
104
my $notexisting_borrowernumber = $borrowernumber + 1;
105
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$notexisting_borrowernumber");
106
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
107
$t->request_ok($tx)
108
  ->status_is(404)
109
  ->json_has('/error');
110
111
my $biblionumber = create_biblio('RESTful Web APIs');
112
my $itemnumber1 = create_item($biblionumber, 'TEST000001');
113
my $itemnumber2 = create_item($biblionumber, 'TEST000002');
114
115
my $date_due = DateTime->now->add(weeks => 2);
116
117
my $issueId = Koha::OldIssues->count({}) + int rand(150000);
118
my $issue1;
119
$issue1 = Koha::OldIssue->new({ issue_id => $issueId, borrowernumber => $borrowernumber, itemnumber => $itemnumber1, date_due => $date_due});
120
$issue1->store();
121
122
my $date_due1 = Koha::DateUtils::dt_from_string( $issue1->date_due );
123
124
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$borrowernumber");
125
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
126
$t->request_ok($tx)
127
  ->status_is(200)
128
  ->json_is('/0/issue_id' => $issueId)
129
  ->json_hasnt('/1')
130
  ->json_hasnt('/error');
131
132
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history/" . $issue1->issue_id);
133
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
134
$t->request_ok($tx)
135
  ->status_is(200)
136
  ->json_is('/borrowernumber' => $borrowernumber)
137
  ->json_is('/itemnumber' => $itemnumber1)
138
  ->json_is('/date_due' => $date_due1->ymd . ' ' . $date_due1->hms)
139
  ->json_hasnt('/error');
140
141
$issue1->delete();
142
143
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history/" . $issue1->issue_id);
144
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
145
$t->request_ok($tx)
146
  ->status_is(404)
147
  ->json_has('/error');
148
149
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$borrowernumber");
150
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
151
$t->request_ok($tx)
152
  ->status_is(200)
153
  ->json_hasnt('/0')
154
  ->json_hasnt('/error');
155
156
Koha::Patrons->find($borrowernumber)->delete();
157
158
$tx = $t->ua->build_tx(GET => "/api/v1/checkouts/history?borrowernumber=$borrowernumber");
159
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
160
$t->request_ok($tx)
161
  ->status_is(404)
162
  ->json_has('/error');
163
164
sub create_biblio {
165
    my ($title) = @_;
166
167
    my $record = new MARC::Record;
168
    $record->append_fields(
169
        new MARC::Field('200', ' ', ' ', a => $title),
170
    );
171
172
    my ($biblionumber) = C4::Biblio::AddBiblio($record, '');
173
174
    return $biblionumber;
175
}
176
177
sub create_item {
178
    my ($biblionumber, $barcode) = @_;
179
180
    my $item = {
181
        barcode => $barcode,
182
    };
183
184
    my $itemnumber = C4::Items::AddItem($item, $biblionumber);
185
186
    return $itemnumber;
187
}

Return to bug 17005