Lines 1012-1028
subtest 'add() tests' => sub {
Link Here
|
1012 |
$schema->storage->txn_rollback; |
1012 |
$schema->storage->txn_rollback; |
1013 |
}; |
1013 |
}; |
1014 |
|
1014 |
|
1015 |
|
|
|
1016 |
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { |
1015 |
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { |
1017 |
|
1016 |
|
1018 |
plan tests => 4; |
1017 |
plan tests => 16; |
1019 |
|
1018 |
|
1020 |
$schema->storage->txn_begin; |
1019 |
$schema->storage->txn_begin; |
1021 |
|
1020 |
|
1022 |
my $password = 'AbcdEFG123'; |
1021 |
my $password = 'AbcdEFG123'; |
1023 |
|
1022 |
|
1024 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
1023 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
1025 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
1024 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
|
|
1025 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
1026 |
|
1026 |
|
1027 |
my $patron = $builder->build_object( |
1027 |
my $patron = $builder->build_object( |
1028 |
{ class => 'Koha::Patrons', value => { flags => 0 } } ); |
1028 |
{ class => 'Koha::Patrons', value => { flags => 0 } } ); |
Lines 1043-1049
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
Link Here
|
1043 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
1043 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
1044 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
1044 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
1045 |
|
1045 |
|
|
|
1046 |
my $libraries_query = { branchcode => [ $library_1->branchcode, $library_2->branchcode ] }; |
1047 |
|
1048 |
my $mocked_biblio = Test::MockModule->new('Koha::Biblio'); |
1049 |
$mocked_biblio->mock( 'pickup_locations', sub { |
1050 |
return Koha::Libraries->search($libraries_query); |
1051 |
}); |
1052 |
|
1053 |
my $mocked_item = Test::MockModule->new('Koha::Item'); |
1054 |
$mocked_item->mock( 'pickup_locations', sub { |
1055 |
return Koha::Libraries->search($libraries_query); |
1056 |
}); |
1057 |
|
1046 |
my $biblio = $builder->build_sample_biblio; |
1058 |
my $biblio = $builder->build_sample_biblio; |
|
|
1059 |
my $item = $builder->build_sample_item( |
1060 |
{ |
1061 |
biblionumber => $biblio->biblionumber, |
1062 |
library => $library_1->branchcode |
1063 |
} |
1064 |
); |
1065 |
|
1066 |
# biblio-level hold |
1047 |
my $hold = Koha::Holds->find( |
1067 |
my $hold = Koha::Holds->find( |
1048 |
AddReserve( |
1068 |
AddReserve( |
1049 |
{ |
1069 |
{ |
Lines 1051-1063
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
Link Here
|
1051 |
borrowernumber => $patron->borrowernumber, |
1071 |
borrowernumber => $patron->borrowernumber, |
1052 |
biblionumber => $biblio->biblionumber, |
1072 |
biblionumber => $biblio->biblionumber, |
1053 |
priority => 1, |
1073 |
priority => 1, |
|
|
1074 |
itemnumber => undef, |
1075 |
} |
1076 |
) |
1077 |
); |
1078 |
|
1079 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1080 |
. $hold->id |
1081 |
. "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } ) |
1082 |
->status_is(200) |
1083 |
->json_is({ pickup_library_id => $library_2->branchcode }); |
1084 |
|
1085 |
is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); |
1086 |
|
1087 |
$libraries_query = { branchcode => $library_1->branchcode }; |
1088 |
|
1089 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1090 |
. $hold->id |
1091 |
. "/pickup_location" => json => { pickup_library_id => $library_3->branchcode } ) |
1092 |
->status_is(400) |
1093 |
->json_is({ error => '[The supplied pickup location is not valid]' }); |
1094 |
|
1095 |
is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library unchanged' ); |
1096 |
|
1097 |
# item-level hold |
1098 |
$hold = Koha::Holds->find( |
1099 |
AddReserve( |
1100 |
{ |
1101 |
branchcode => $library_1->branchcode, |
1102 |
borrowernumber => $patron->borrowernumber, |
1103 |
biblionumber => $biblio->biblionumber, |
1104 |
priority => 1, |
1105 |
itemnumber => $item->itemnumber, |
1054 |
} |
1106 |
} |
1055 |
) |
1107 |
) |
1056 |
); |
1108 |
); |
1057 |
|
1109 |
|
|
|
1110 |
$libraries_query = { branchcode => $library_1->branchcode }; |
1111 |
|
1112 |
# Attempt to use an invalid pickup locations ends in 400 |
1113 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1114 |
. $hold->id |
1115 |
. "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } ) |
1116 |
->status_is(400) |
1117 |
->json_is({ error => '[The supplied pickup location is not valid]' }); |
1118 |
|
1119 |
is( $hold->discard_changes->branchcode->branchcode, $library_1->branchcode, 'pickup library unchanged' ); |
1120 |
|
1121 |
$libraries_query = { |
1122 |
branchcode => { |
1123 |
'-in' => [ $library_1->branchcode, $library_2->branchcode ] |
1124 |
} |
1125 |
}; |
1126 |
|
1058 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1127 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1059 |
. $hold->id |
1128 |
. $hold->id |
1060 |
. "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode); |
1129 |
. "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } ) |
|
|
1130 |
->status_is(200) |
1131 |
->json_is({ pickup_library_id => $library_2->branchcode }); |
1061 |
|
1132 |
|
1062 |
is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); |
1133 |
is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); |
1063 |
|
1134 |
|
1064 |
- |
|
|