From 8e0d6b65a709e8c455fc72f6c1f5af472b3dc75e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 11 Jul 2022 13:46:05 +0100 Subject: [PATCH] Bug 31128: Unit tests This patch adds unit tests for the new effective_not_for_loan_status which I add to the items api responses in this patchset. Test plan 1) Run the unit test without applying the next commit, it should fail 2) RUn the test again after applying the next commit, it should pass --- t/db_dependent/api/v1/items.t | 37 +++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/api/v1/items.t b/t/db_dependent/api/v1/items.t index 41f574ccf7..5dd047937d 100755 --- a/t/db_dependent/api/v1/items.t +++ b/t/db_dependent/api/v1/items.t @@ -101,7 +101,7 @@ subtest 'list() tests' => sub { subtest 'get() tests' => sub { - plan tests => 17; + plan tests => 30; $schema->storage->txn_begin; @@ -143,21 +143,46 @@ subtest 'get() tests' => sub { my $biblio = $builder->build_sample_biblio; my $itype = - $builder->build_object( { class => 'Koha::ItemTypes' } )->itemtype; + $builder->build_object( { class => 'Koha::ItemTypes' } ); $item = $builder->build_sample_item( - { biblionumber => $biblio->biblionumber, itype => $itype } ); + { biblionumber => $biblio->biblionumber, itype => $itype->itemtype } ); + + isnt( $biblio->itemtype, $itype->itemtype, "Test biblio level itemtype and item level itemtype do not match"); $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber ) ->status_is( 200, 'SWAGGER3.2.2' ) - ->json_is( '/item_type_id' => $itype, 'item-level_itypes:0' ) + ->json_is( '/item_type_id' => $itype->itemtype, 'item-level_itypes:0' ) ->json_is( '/effective_item_type_id' => $biblio->itemtype, 'item-level_itypes:0' ); t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber ) ->status_is( 200, 'SWAGGER3.2.2' ) - ->json_is( '/item_type_id' => $itype, 'item-level_itype:1' ) - ->json_is( '/effective_item_type_id' => $itype, 'item-level_itypes:1' ); + ->json_is( '/item_type_id' => $itype->itemtype, 'item-level_itype:1' ) + ->json_is( '/effective_item_type_id' => $itype->itemtype, 'item-level_itypes:1' ); + + + my $biblio_itype = Koha::ItemTypes->find($biblio->itemtype); + $biblio_itype->notforloan(3)->store(); + $itype->notforloan(2)->store(); + $item->notforloan(1)->store(); + + $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber ) + ->status_is( 200, 'SWAGGER3.2.2' ) + ->json_is( '/not_for_loan_status' => 1, 'not_for_loan_status is 1' ) + ->json_is( '/effective_not_for_loan_status' => 1, 'effective_not_for_loan_status picks up item level' ); + + $item->notforloan(0)->store(); + $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber ) + ->status_is( 200, 'SWAGGER3.2.2' ) + ->json_is( '/not_for_loan_status' => 0, 'not_for_loan_status is 0' ) + ->json_is( '/effective_not_for_loan_status' => 2, 'effective_not_for_loan_status now picks up itemtype level - item-level_itypes:1' ); + + t::lib::Mocks::mock_preference( 'item-level_itypes', 0 ); + $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber ) + ->status_is( 200, 'SWAGGER3.2.2' ) + ->json_is( '/not_for_loan_status' => 0, 'not_for_loan_status is 0' ) + ->json_is( '/effective_not_for_loan_status' => 3, 'effective_not_for_loan_status now picks up itemtype level - item-level_itypes:0' ); $schema->storage->txn_rollback; }; -- 2.20.1