|
Lines 1027-1043
subtest 'add() tests' => sub {
Link Here
|
| 1027 |
$schema->storage->txn_rollback; |
1027 |
$schema->storage->txn_rollback; |
| 1028 |
}; |
1028 |
}; |
| 1029 |
|
1029 |
|
| 1030 |
|
|
|
| 1031 |
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { |
1030 |
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { |
| 1032 |
|
1031 |
|
| 1033 |
plan tests => 4; |
1032 |
plan tests => 16; |
| 1034 |
|
1033 |
|
| 1035 |
$schema->storage->txn_begin; |
1034 |
$schema->storage->txn_begin; |
| 1036 |
|
1035 |
|
| 1037 |
my $password = 'AbcdEFG123'; |
1036 |
my $password = 'AbcdEFG123'; |
| 1038 |
|
1037 |
|
| 1039 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
1038 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 1040 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
1039 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
|
|
1040 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 1041 |
|
1041 |
|
| 1042 |
my $patron = $builder->build_object( |
1042 |
my $patron = $builder->build_object( |
| 1043 |
{ class => 'Koha::Patrons', value => { flags => 0 } } ); |
1043 |
{ class => 'Koha::Patrons', value => { flags => 0 } } ); |
|
Lines 1058-1064
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
Link Here
|
| 1058 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
1058 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
| 1059 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
1059 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 1060 |
|
1060 |
|
|
|
1061 |
my $libraries_query = { branchcode => [ $library_1->branchcode, $library_2->branchcode ] }; |
| 1062 |
|
| 1063 |
my $mocked_biblio = Test::MockModule->new('Koha::Biblio'); |
| 1064 |
$mocked_biblio->mock( 'pickup_locations', sub { |
| 1065 |
return Koha::Libraries->search($libraries_query); |
| 1066 |
}); |
| 1067 |
|
| 1068 |
my $mocked_item = Test::MockModule->new('Koha::Item'); |
| 1069 |
$mocked_item->mock( 'pickup_locations', sub { |
| 1070 |
return Koha::Libraries->search($libraries_query); |
| 1071 |
}); |
| 1072 |
|
| 1061 |
my $biblio = $builder->build_sample_biblio; |
1073 |
my $biblio = $builder->build_sample_biblio; |
|
|
1074 |
my $item = $builder->build_sample_item( |
| 1075 |
{ |
| 1076 |
biblionumber => $biblio->biblionumber, |
| 1077 |
library => $library_1->branchcode |
| 1078 |
} |
| 1079 |
); |
| 1080 |
|
| 1081 |
# biblio-level hold |
| 1062 |
my $hold = Koha::Holds->find( |
1082 |
my $hold = Koha::Holds->find( |
| 1063 |
AddReserve( |
1083 |
AddReserve( |
| 1064 |
{ |
1084 |
{ |
|
Lines 1066-1078
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
Link Here
|
| 1066 |
borrowernumber => $patron->borrowernumber, |
1086 |
borrowernumber => $patron->borrowernumber, |
| 1067 |
biblionumber => $biblio->biblionumber, |
1087 |
biblionumber => $biblio->biblionumber, |
| 1068 |
priority => 1, |
1088 |
priority => 1, |
|
|
1089 |
itemnumber => undef, |
| 1090 |
} |
| 1091 |
) |
| 1092 |
); |
| 1093 |
|
| 1094 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
| 1095 |
. $hold->id |
| 1096 |
. "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } ) |
| 1097 |
->status_is(200) |
| 1098 |
->json_is({ pickup_library_id => $library_2->branchcode }); |
| 1099 |
|
| 1100 |
is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); |
| 1101 |
|
| 1102 |
$libraries_query = { branchcode => $library_1->branchcode }; |
| 1103 |
|
| 1104 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
| 1105 |
. $hold->id |
| 1106 |
. "/pickup_location" => json => { pickup_library_id => $library_3->branchcode } ) |
| 1107 |
->status_is(400) |
| 1108 |
->json_is({ error => '[The supplied pickup location is not valid]' }); |
| 1109 |
|
| 1110 |
is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library unchanged' ); |
| 1111 |
|
| 1112 |
# item-level hold |
| 1113 |
$hold = Koha::Holds->find( |
| 1114 |
AddReserve( |
| 1115 |
{ |
| 1116 |
branchcode => $library_1->branchcode, |
| 1117 |
borrowernumber => $patron->borrowernumber, |
| 1118 |
biblionumber => $biblio->biblionumber, |
| 1119 |
priority => 1, |
| 1120 |
itemnumber => $item->itemnumber, |
| 1069 |
} |
1121 |
} |
| 1070 |
) |
1122 |
) |
| 1071 |
); |
1123 |
); |
| 1072 |
|
1124 |
|
|
|
1125 |
$libraries_query = { branchcode => $library_1->branchcode }; |
| 1126 |
|
| 1127 |
# Attempt to use an invalid pickup locations ends in 400 |
| 1128 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
| 1129 |
. $hold->id |
| 1130 |
. "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } ) |
| 1131 |
->status_is(400) |
| 1132 |
->json_is({ error => '[The supplied pickup location is not valid]' }); |
| 1133 |
|
| 1134 |
is( $hold->discard_changes->branchcode->branchcode, $library_1->branchcode, 'pickup library unchanged' ); |
| 1135 |
|
| 1136 |
$libraries_query = { |
| 1137 |
branchcode => { |
| 1138 |
'-in' => [ $library_1->branchcode, $library_2->branchcode ] |
| 1139 |
} |
| 1140 |
}; |
| 1141 |
|
| 1073 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1142 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
| 1074 |
. $hold->id |
1143 |
. $hold->id |
| 1075 |
. "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode); |
1144 |
. "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } ) |
|
|
1145 |
->status_is(200) |
| 1146 |
->json_is({ pickup_library_id => $library_2->branchcode }); |
| 1076 |
|
1147 |
|
| 1077 |
is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); |
1148 |
is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); |
| 1078 |
|
1149 |
|
| 1079 |
- |
|
|