Bugzilla – Attachment 147656 Details for
Bug 31798
Add POST endpoint for Items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Bug-31798-follow-up-Tidy-up-and-add-duplicate-barc.patch (text/plain), 2.87 KB, created by
Martin Renvoize (ashimema)
on 2023-03-02 16:28:46 UTC
(
hide
)
Description:
Bug 31798: (follow-up) Tidy up and add duplicate barcode test
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-03-02 16:28:46 UTC
Size:
2.87 KB
patch
obsolete
>From 7d0bfb6389c7da53b532bb5bb67719b3d9d30544 Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Tue, 3 Jan 2023 12:12:39 -0300 >Subject: [PATCH] Bug 31798: (follow-up) Tidy up and add duplicate barcode test > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/REST/V1/Biblios.pm | 20 ++++++++------------ > api/v1/swagger/paths/biblios.yaml | 4 ++++ > t/db_dependent/api/v1/biblios.t | 9 ++++++++- > 3 files changed, 20 insertions(+), 13 deletions(-) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 2cc70b7151..3e278fae52 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -310,24 +310,20 @@ sub add_item { > $item->barcode($barcode); > } > >- if ( defined $item->barcode >- && Koha::Items->search( { barcode => $item->barcode } )->count ) >- { >- return $c->render( >- status => 400, >- openapi => { error => "Barcode not unique" } >- ); >- } >- >- my $storedItem = $item->store; >- $storedItem->discard_changes; >+ $item->store->discard_changes; > > $c->render( > status => 201, >- openapi => $storedItem->to_api >+ openapi => $item->to_api > ); > } > catch { >+ if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { >+ return $c->render( >+ status => 409, >+ openapi => { error => 'Duplicate barcode.' } >+ ); >+ } > $c->unhandled_exception($_); > } > } >diff --git a/api/v1/swagger/paths/biblios.yaml b/api/v1/swagger/paths/biblios.yaml >index 5b2fa3b45d..4bfb9e8c87 100644 >--- a/api/v1/swagger/paths/biblios.yaml >+++ b/api/v1/swagger/paths/biblios.yaml >@@ -254,6 +254,10 @@ > description: Not found > schema: > $ref: "../swagger.yaml#/definitions/error" >+ "409": >+ description: Conflict >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" > "500": > description: | > Internal server error. Possible `error_code` attribute values: >diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t >index 7dbbf859b9..f8a5592aaa 100755 >--- a/t/db_dependent/api/v1/biblios.t >+++ b/t/db_dependent/api/v1/biblios.t >@@ -715,7 +715,7 @@ subtest 'set_rating() tests' => sub { > }; > > subtest 'add_item() tests' => sub { >- plan tests => 5; >+ plan tests => 7; > > $schema->storage->txn_begin; > >@@ -760,5 +760,12 @@ subtest 'add_item() tests' => sub { > ->status_is(201, 'Item created') > ->json_is('/biblio_id', $biblio_id); > >+ my $item = $builder->build_sample_item(); >+ >+ $t->post_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items" => json => { >+ external_id => $item->barcode, >+ }) >+ ->status_is(409, 'Duplicate barcode'); >+ > $schema->storage->txn_rollback; > }; >-- >2.39.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31798
:
144893
|
144894
|
144952
|
144953
|
144956
|
147463
|
147464
|
147655
|
147656
|
147657
|
150598
|
150599
|
150600
|
150771
|
150772
|
150773
|
150774
|
150775