Bug 31128: Unit tests
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 11 Jul 2022 12:46:05 +0000 (13:46 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 22 Jul 2022 14:32:21 +0000 (11:32 -0300)
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

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
t/db_dependent/api/v1/items.t

index 41f574c..5dd0479 100755 (executable)
@@ -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;
 };