From 03d047dcfad540ac968f23a30918db63850c0968 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Fri, 16 Aug 2024 16:00:17 +0000 Subject: [PATCH] Bug 37639: Add unit tests --- t/db_dependent/api/v1/items.t | 62 ++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/items.t b/t/db_dependent/api/v1/items.t index 63ca5f73db..9ba55d39d6 100755 --- a/t/db_dependent/api/v1/items.t +++ b/t/db_dependent/api/v1/items.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; use Test::MockModule; use Test::Mojo; use Test::Warn; @@ -31,6 +31,7 @@ use Mojo::JSON qw(encode_json); use C4::Auth; use Koha::Items; +use Koha::Item; use Koha::Database; my $schema = Koha::Database->new->schema; @@ -40,6 +41,65 @@ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); my $t = Test::Mojo->new('Koha::REST::V1'); +subtest 'to_api_mapping() tests' => sub { + + plan tests => 46; + + $schema->storage->txn_begin; + + my $mapping = Koha::Item->to_api_mapping; + is($mapping->{itemnumber}, 'item_id', 'items.itemnumber is mapped as item_id in to_api_mapping'); + is($mapping->{biblionumber}, 'biblio_id', 'items.biblionumber is mapped as biblio_id in to_api_mapping'); + is($mapping->{biblioitemnumber}, undef, 'items.biblionumber is mapped as undef in to_api_mapping'); + is($mapping->{barcode}, 'external_id', 'items.barcode is mapped as external_id in to_api_mapping'); + is($mapping->{dateaccessioned}, 'acquisition_date', 'items.dateaccessioned is mapped as acquisition_date in to_api_mapping'); + is($mapping->{booksellerid}, 'acquisition_source', 'items.booksellerid is mapped as acquisition_source in to_api_mapping'); + is($mapping->{homebranch}, 'home_library_id', 'items.homebranch is mapped as home_libray_id in to_api_mapping'); + is($mapping->{price}, 'purchase_price', 'items.price is mapped as purchase_price in to_api_mapping'); + is($mapping->{replacementprice}, 'replacement_price', 'items.replacementprice is mapped as replacement_price in to_api_mapping'); + is($mapping->{replacementpricedate}, 'replacement_price_date', 'items.replacementpricedate is mapped as replacement_price_date in to_api_mapping'); + is($mapping->{datelastborrowed}, 'last_checkout_date', 'items.datelastborrowered is mapped as last_checkout_date in to_api_mapping'); + is($mapping->{datelastseen}, 'last_seen_date', 'items.datelastseen is mapped as last_seen_date in to_api_mapping'); + is($mapping->{stack}, 'stack', 'items.stack is mapped as stack in to_api_mapping'); + is($mapping->{notforloan}, 'not_for_loan_status', 'items.notforloan is mapped as not_for_loan_status in to_api_mapping'); + is($mapping->{damaged}, 'damaged_status', 'items.damaged is mapped as damaged_status in to_api_mapping'); + is($mapping->{damaged_on}, 'damaged_date', 'items.damaged_on is mapped as damaged_date in to_api_mapping'); + is($mapping->{itemlost}, 'lost_status', 'items.itemlost is mapped as lost_status in to_api_mapping'); + is($mapping->{itemlost_on}, 'lost_date', 'items.itemlost_on is mapped as lost_date in to_api_mapping'); + is($mapping->{withdrawn}, 'withdrawn', 'items.withdrawn is mapped as withdrawn in to_api_mapping'); + is($mapping->{withdrawn_on}, 'withdrawn_date', 'items.withdrawn_date is mapped as withdrawn in to_api_mapping'); + is($mapping->{itemcallnumber}, 'callnumber', 'items.itemcallnumber is mapped as callnumber in to_api_mapping'); + is($mapping->{coded_location_qualifier}, 'coded_location_qualifier', 'items.coded_location_qualifier is mapped as coded_location_qualifier in to_api_mapping'); + is($mapping->{issues}, 'checkouts_count', 'items.issues is mapped as checkouts_count in to_api_mapping'); + is($mapping->{renewals}, 'renewals_count', 'items.renewals is mapped as renewals_count in to_api_mapping'); + is($mapping->{reserves}, 'holds_count', 'items.reserves is mapped as holds_count in to_api_mapping'); + is($mapping->{restricted}, 'restricted_status', 'items.restricted is mapped as restricted_status in to_api_mapping'); + is($mapping->{itemnotes}, 'public_notes', 'items.itemnotes is mapped as public_notes in to_api_mapping'); + is($mapping->{itemnotes_nonpublic}, 'internal_notes', 'items.itemnotes_nonpublic is mapped as internal_notes in to_api_mapping'); + is($mapping->{holdingbranch}, 'holding_library_id', 'items.holdingbranch is mapped as holding_library_id in to_api_mapping'); + is($mapping->{timestamp}, 'timestamp', 'items.timestamp is mapped as timestamp in to_api_mapping'); + is($mapping->{location}, 'location', 'items.location is mapped as location in to_api_mapping'); + is($mapping->{permanent_location}, 'permanent_location', 'items.permanent_location is mapped as permanent_location in to_api_mapping'); + is($mapping->{onloan}, 'checked_out_date', 'items.onloan is mapped as checked_out_date in to_api_mapping'); + is($mapping->{cn_source}, 'call_number_source', 'items.cnsource is mapped as call_number_source in to_api_mapping'); + is($mapping->{cn_sort}, 'call_number_sort', 'items.cnsort is mapped as call_number_sort in to_api_mapping'); + is($mapping->{ccode}, 'collection_code', 'items.ccode is mapped as collection_code in to_api_mapping'); + is($mapping->{materials}, 'materials_notes', 'items.materials is mapped as materials_notes in to_api_mapping'); + is($mapping->{uri}, 'uri', 'items.uri is mapped as uri in to_api_mapping'); + is($mapping->{itype}, 'item_type_id', 'items.itype is mapped as item_type_id in to_api_mapping'); + is($mapping->{more_subfields_xml}, 'extended_subfields', 'items.more_subfields_xml is mapped as extended_subfields in to_api_mapping'); + is($mapping->{enumchron}, 'serial_issue_number', 'items.enumchron is mapped as serial_issue_number in to_api_mapping'); + is($mapping->{copynumber}, 'copy_number', 'items.copynumber is mapped as copy_number in to_api_mapping'); + is($mapping->{stocknumber}, 'inventory_number', 'items.stocknumber is mapped as inventory_number in to_api_mapping'); + is($mapping->{new_status}, 'new_status', 'items.new_status is mapped as new_status in to_api_mapping'); + is($mapping->{deleted_on}, undef, 'items.deleted_on is mapped as undef in to_api_mapping'); + + is( scalar keys %{$mapping}, 45, 'Correct number of columns in mapping' ); + + + $schema->storage->txn_rollback; +}; + subtest 'list() tests' => sub { plan tests => 15; -- 2.39.2