3 use Test::More tests => 8;
5 diag("Test transferring holds with parts.");
7 use constant WORKSTATION_NAME => 'BR1-test-26-lp1411422-transferring-items-volumes-with-parts.t';
8 use constant WORKSTATION_LIB => 4;
10 use strict; use warnings;
12 use OpenILS::Utils::TestUtils;
13 use OpenILS::Utils::CStoreEditor qw/:funcs/;
14 use OpenILS::Utils::Fieldmapper;
16 our $script = OpenILS::Utils::TestUtils->new();
19 our $e = new_editor(xact => 1);
23 # setup workstation and login
27 # Find a copy with at least one part
30 my $copy = $e->search_asset_copy([
37 bmp => { type => 'left' },
42 flesh_fields => { acp => ['parts']},
47 diag("Using copy ". $copy->id);
48 my $parts = $copy->parts;
49 my $oldcallnumber = $copy->call_number;
53 foreach my $spart (@$parts) {
56 diag("Copy part label -> ". $part->label);
58 diag("Copy call number ". $oldcallnumber);
60 $oldcallnumber = $e->search_asset_call_number({id => $oldcallnumber, deleted => 'f'})->[0];
62 diag("Copy attached to bib ". $oldcallnumber->record);
64 # Find a bib without parts
66 my $sdestbib = $e->search_biblio_record_entry([
72 'select' => { "bmp" => [ 'record' ] }
81 foreach(@{$sdestbib}) {
89 diag("Using this non parted bib ". $destbib->id);
91 # Create a new volume for the copy to transfer to
93 my $newcall = Fieldmapper::asset::call_number->new;
95 $newcall->owning_lib($oldcallnumber->owning_lib);
96 $newcall->record($destbib->id);
97 $newcall->creator($oldcallnumber->creator);
98 $newcall->editor($oldcallnumber->editor);
99 $newcall->label('Test copy transfer with parts');
102 my $stat = $e->create_asset_call_number($newcall);
103 ok($stat, 'Created temporary volume on bib '.$destbib->id);
105 diag( "New call number id: " . $newcall->id );
107 # freshen up the variable
108 # get all the rest of the values from the DB
109 $newcall = $e->search_asset_call_number({id => $newcall->id})->[0];
111 # save changes so that the storage request has access
116 my @copy_id_array = ($copy->id);
117 my $storage = $script->session('open-ils.cat');
118 my $req = $storage->request(
119 'open-ils.cat.transfer_copies_to_volume', $script->authtoken, $newcall->id, \@copy_id_array )->gather(1);
121 # Did the code create a new part on the destination bib?
125 my $destparts = $e->search_biblio_monograph_part({record => $newcall->record, label => $part->label, deleted => 'f'})->[0];
126 ok($destparts, 'Copy transfer with parts success on bib '.$destbib->id);
128 is($destparts->label, $part->label, 'Part labels match and everything!');
130 # Now test transferring volumes,
131 # might as well transfer it back to the old bib
134 my @vols = ($newcall->id);
135 my $docid = $oldcallnumber->record;
136 my $args = {lib => $oldcallnumber->owning_lib, docid => $docid, volumes => \@vols };
137 $storage = $script->session('open-ils.cat');
138 $req = $storage->request(
139 'open-ils.cat.asset.volume.batch.transfer',
143 # Make sure that the old bib received the part
144 my $destparts2 = $e->search_biblio_monograph_part({record => $oldcallnumber->record, label => $part->label, deleted => 'f'})->[0];
145 ok($destparts2, 'Volume transfer with parts success on bib '.$oldcallnumber->record);
146 is($destparts->label, $part->label, 'Part labels match and everything!');
151 $storage = $script->session('open-ils.cat');
152 $req = $storage->request(
153 'open-ils.cat.transfer_copies_to_volume', $script->authtoken, $oldcallnumber->id, \@copy_id_array )->gather(1);
155 $stat = $e->delete_asset_call_number($newcall);
162 my $workstation = $e->search_actor_workstation([ {name => WORKSTATION_NAME, owning_lib => WORKSTATION_LIB } ])->[0];
166 $script->authenticate({
168 password => 'demo123',
170 ok( $script->authtoken, 'Have an authtoken');
171 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
172 ok( ! ref $ws, 'Registered a new workstation');
176 $script->authenticate({
178 password => 'demo123',
180 workstation => WORKSTATION_NAME});
181 ok( $script->authtoken, 'Have an authtoken associated with the workstation');