|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # |
3 | | -# Copyright (C) 2018-2020 CERN. |
| 3 | +# Copyright (C) 2018-2025 CERN. |
4 | 4 | # |
5 | 5 | # invenio-app-ils is free software; you can redistribute it and/or modify it |
6 | 6 | # under the terms of the MIT License; see LICENSE file for more details. |
@@ -249,15 +249,29 @@ def test_self_checkout_search(app, client, json_headers, users, testdata): |
249 | 249 | assert res.status_code == 400 |
250 | 250 |
|
251 | 251 | # test that an error is returned when the item cannot circulate |
252 | | - missing_item_barcode = "123456789-1" |
| 252 | + in_binding_item_barcode = "123456789-74" |
253 | 253 | url = url_for("invenio_app_ils_circulation.loan_self_checkout") |
254 | | - res = client.get(f"{url}?barcode={missing_item_barcode}", headers=json_headers) |
| 254 | + res = client.get(f"{url}?barcode={in_binding_item_barcode}", headers=json_headers) |
255 | 255 | assert res.status_code == 400 |
256 | 256 | # assert that the payload will contain the key error with a msg |
257 | 257 | response = res.get_json() |
258 | 258 | assert LoanSelfCheckoutItemInvalidStatus.description in response["message"] |
259 | 259 | assert LoanSelfCheckoutItemInvalidStatus.supportCode in response["supportCode"] |
260 | 260 |
|
| 261 | + # test that no error is returned when the item is marked as missing |
| 262 | + missing_item_barcode = "123456789-1" |
| 263 | + missing_item_pid = "itemid-1" |
| 264 | + url = url_for("invenio_app_ils_circulation.loan_self_checkout") |
| 265 | + res = client.get(f"{url}?barcode={missing_item_barcode}", headers=json_headers) |
| 266 | + assert res.status_code == 200 |
| 267 | + |
| 268 | + # assert item is no longer marked as missing |
| 269 | + response = res.get_json() |
| 270 | + item_pid = response["metadata"]["pid"] |
| 271 | + assert item_pid == missing_item_pid |
| 272 | + item = Item.get_record_by_pid(item_pid) |
| 273 | + assert item["status"] == "CAN_CIRCULATE" |
| 274 | + |
261 | 275 | # create a loan on the same patron, and another one on another patron |
262 | 276 | user_login(client, "librarian", users) |
263 | 277 | url = url_for("invenio_app_ils_circulation.loan_checkout") |
@@ -326,6 +340,7 @@ def _create_request(patron, document_pid): |
326 | 340 | current_search.flush_and_refresh(index="*") |
327 | 341 |
|
328 | 342 | def _self_checkout(patron, item_pid, document_pid): |
| 343 | + url = url_for("invenio_app_ils_circulation.loan_self_checkout") |
329 | 344 | params = deepcopy(NEW_LOAN) |
330 | 345 | params["document_pid"] = document_pid |
331 | 346 | params["item_pid"] = dict(type="pitmid", value=item_pid) |
@@ -394,3 +409,14 @@ def _self_checkout(patron, item_pid, document_pid): |
394 | 409 | assert res.status_code == 202 |
395 | 410 | response = res.get_json() |
396 | 411 | assert response["metadata"]["delivery"]["method"] == "SELF-CHECKOUT" |
| 412 | + |
| 413 | + # test self-checkout with item marked as missing raises no error and marks the item as CAN_CIRCULATE |
| 414 | + missing_item_pid = "itemid-1" |
| 415 | + app.config["ILS_SELF_CHECKOUT_ENABLED"] = True |
| 416 | + patron2 = user_login(client, "patron2", users) |
| 417 | + res = _self_checkout(patron2, missing_item_pid, "docid-1") |
| 418 | + assert res.status_code == 202 |
| 419 | + response = res.get_json() |
| 420 | + assert response["metadata"]["delivery"]["method"] == "SELF-CHECKOUT" |
| 421 | + item = Item.get_record_by_pid(missing_item_pid) |
| 422 | + assert item["status"] == "CAN_CIRCULATE" |
0 commit comments