Bugzilla – Attachment 168825 Details for
Bug 29560
Add option to create MARC links when adding items to bundles
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29560: Unit tests: API
Bug-29560-Unit-tests-API.patch (text/plain), 6.07 KB, created by
Martin Renvoize (ashimema)
on 2024-07-11 13:35:02 UTC
(
hide
)
Description:
Bug 29560: Unit tests: API
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-07-11 13:35:02 UTC
Size:
6.07 KB
patch
obsolete
>From bd6101e9734a1e0b6a869faeeec92c232aff0114 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 11 Jul 2024 14:11:43 +0100 >Subject: [PATCH] Bug 29560: Unit tests: API > >--- > t/db_dependent/api/v1/items/bundled_items.t | 139 ++++++++++++++++++-- > 1 file changed, 129 insertions(+), 10 deletions(-) > >diff --git a/t/db_dependent/api/v1/items/bundled_items.t b/t/db_dependent/api/v1/items/bundled_items.t >index d2b085ede2d..4689dd820e7 100755 >--- a/t/db_dependent/api/v1/items/bundled_items.t >+++ b/t/db_dependent/api/v1/items/bundled_items.t >@@ -2,7 +2,7 @@ > > use Modern::Perl; > >-use Test::More tests => 1; >+use Test::More tests => 2; > use Test::MockModule; > use Test::Mojo; > >@@ -18,30 +18,149 @@ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); > > my $t = Test::Mojo->new('Koha::REST::V1'); > >-subtest 'order by me.barcode should return 200' => sub { >- plan tests => 2; >+subtest 'bundled_items()' => sub { >+ plan tests => 7; > > $schema->storage->txn_begin; > >- my $bundle = $builder->build_sample_item; >- my $item = $builder->build_sample_item; >- $bundle->add_to_bundle($item); >+ my $item = $builder->build_sample_item; >+ my $itemnumber = $item->itemnumber; >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 4 } >+ } >+ ); >+ >+ # Make sure we have at least 10 items >+ for ( 1 .. 10 ) { >+ my $bundled_item = $builder->build_sample_item; >+ $item->add_to_bundle($bundled_item); >+ } > >- my $patron = $builder->build_object( >+ my $nonprivilegedpatron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ my $password = 'thePassword123'; >+ >+ $nonprivilegedpatron->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $nonprivilegedpatron->userid; >+ >+ $t->get_ok("//$userid:$password@/api/v1/items/$itemnumber/bundled_items")->status_is(403) >+ ->json_is( '/error' => 'Authorization failure. Missing required permission(s).' ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ $userid = $patron->userid; >+ >+ $t->get_ok("//$userid:$password@/api/v1/items/$itemnumber/bundled_items")->status_is( 200, 'SWAGGER3.2.2' ); >+ >+ my $response_count = scalar @{ $t->tx->res->json }; >+ >+ is( $response_count, 10, 'The API returns 10 bundled items' ); >+ >+ $schema->storage->txn_rollback; >+ >+ subtest 'order by me.barcode should return 200' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $bundle = $builder->build_sample_item; >+ my $item = $builder->build_sample_item; >+ $bundle->add_to_bundle($item); >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 4 } >+ } >+ ); >+ >+ my $password = 'thePassword123'; >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ >+ my $userid = $patron->userid; >+ my $itemnumber = $bundle->itemnumber; >+ >+ $t->get_ok("//$userid:$password@/api/v1/items/$itemnumber/bundled_items?_order_by=+me.barcode")->status_is(200); >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+}; >+ >+subtest 'add_to_bundle' => sub { >+ plan tests => 14; >+ >+ $schema->storage->txn_begin; >+ >+ my $item = $builder->build_sample_item; >+ my $itemnumber = $item->itemnumber; >+ my $patron = $builder->build_object( > { > class => 'Koha::Patrons', > value => { flags => 4 } > } > ); > >+ my $nonprivilegedpatron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ > my $password = 'thePassword123'; > >+ $nonprivilegedpatron->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $nonprivilegedpatron->userid; >+ >+ my $item_to_bundle = $builder->build_sample_item; >+ my $link = { >+ item_id => undef, >+ external_id => $item_to_bundle->barcode, >+ force_checkin => 0, >+ ignore_holds => 0, >+ marc_link => 0 >+ }; >+ >+ $t->post_ok( "//$userid:$password@/api/v1/items/$itemnumber/bundled_items" => json => $link )->status_is(403) >+ ->json_is( '/error' => 'Authorization failure. Missing required permission(s).' ); >+ > $patron->set_password( { password => $password, skip_validation => 1 } ); >+ $userid = $patron->userid; >+ >+ $t->post_ok( "//$userid:$password@/api/v1/items/$itemnumber/bundled_items" => json => $link ) >+ ->status_is( 201, 'Link created successfully' ) >+ ->json_is( '/item_id' => $item_to_bundle->itemnumber, 'Bundled item returned' ); >+ >+ $t->post_ok( "//$userid:$password@/api/v1/items/$itemnumber/bundled_items" => json => $link ) >+ ->status_is( 409, 'Cannot re-link already linked item' ) >+ ->json_is( '/error_code' => 'already_bundled', 'Correct error code' ); > >- my $userid = $patron->userid; >- my $itemnumber = $bundle->itemnumber; >+ # marc_link >+ $item_to_bundle = $builder->build_sample_item; >+ $link->{external_id} = $item_to_bundle->barcode; >+ $link->{marc_link} = 1; > >- $t->get_ok("//$userid:$password@/api/v1/items/$itemnumber/bundled_items?_order_by=+me.barcode")->status_is(200); >+ my $bundled_marc = $item_to_bundle->biblio->metadata->record; >+ is( $bundled_marc->field('773'), undef, 'No 773 field in item to bundle' ); >+ >+ $t->post_ok( "//$userid:$password@/api/v1/items/$itemnumber/bundled_items" => json => $link ) >+ ->status_is( 201, 'Link created successfully' ) >+ ->json_is( '/item_id' => $item_to_bundle->itemnumber, 'Bundled item returned' ); >+ >+ $item_to_bundle->discard_changes; >+ $bundled_marc = $item_to_bundle->biblio->metadata->record; >+ is( >+ ref( $bundled_marc->field('773') ), 'MARC::Field', >+ '773 field is set after bundling with "marc_link = 1"' >+ ); > > $schema->storage->txn_rollback; > }; >-- >2.45.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 29560
:
135090
|
135091
|
137509
|
137510
|
156299
|
156300
|
159081
|
159082
|
168720
|
168721
|
168722
|
168723
|
168816
|
168817
|
168818
|
168819
|
168820
|
168821
|
168822
|
168823
|
168824
|
168825
|
168885
|
168886
|
168887
|
168888
|
168889
|
168968