Lines 155-170
my $suspended_until = DateTime->now->add(days => 10)->truncate( to => 'day' );
Link Here
|
155 |
my $expiration_date = DateTime->now->add(days => 10)->truncate( to => 'day' ); |
155 |
my $expiration_date = DateTime->now->add(days => 10)->truncate( to => 'day' ); |
156 |
|
156 |
|
157 |
my $post_data = { |
157 |
my $post_data = { |
158 |
patron_id => int($patron_1->borrowernumber), |
158 |
patron_id => $patron_1->borrowernumber, |
159 |
biblio_id => int($biblio_1->biblionumber), |
159 |
biblio_id => $biblio_1->biblionumber, |
160 |
item_id => int($item_1->itemnumber), |
160 |
item_id => $item_1->itemnumber, |
161 |
pickup_library_id => $branchcode, |
161 |
pickup_library_id => $branchcode, |
162 |
expiration_date => output_pref({ dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 }), |
162 |
expiration_date => output_pref( { dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 } ), |
163 |
priority => 2, |
|
|
164 |
}; |
163 |
}; |
165 |
my $put_data = { |
164 |
my $patch_data = { |
166 |
priority => 2, |
165 |
priority => 2, |
167 |
suspended_until => output_pref({ dt => $suspended_until, dateformat => 'rfc3339' }), |
166 |
suspended_until => output_pref( { dt => $suspended_until, dateformat => 'rfc3339' } ), |
168 |
}; |
167 |
}; |
169 |
|
168 |
|
170 |
subtest "Test endpoints without authentication" => sub { |
169 |
subtest "Test endpoints without authentication" => sub { |
Lines 173-179
subtest "Test endpoints without authentication" => sub {
Link Here
|
173 |
->status_is(401); |
172 |
->status_is(401); |
174 |
$t->post_ok('/api/v1/holds') |
173 |
$t->post_ok('/api/v1/holds') |
175 |
->status_is(401); |
174 |
->status_is(401); |
176 |
$t->put_ok('/api/v1/holds/0') |
175 |
$t->patch_ok('/api/v1/holds/0') |
177 |
->status_is(401); |
176 |
->status_is(401); |
178 |
$t->delete_ok('/api/v1/holds/0') |
177 |
$t->delete_ok('/api/v1/holds/0') |
179 |
->status_is(401); |
178 |
->status_is(401); |
Lines 192-198
subtest "Test endpoints without permission" => sub {
Link Here
|
192 |
$t->post_ok( "//$nopermission_userid:$password@/api/v1/holds" => json => $post_data ) |
191 |
$t->post_ok( "//$nopermission_userid:$password@/api/v1/holds" => json => $post_data ) |
193 |
->status_is(403); |
192 |
->status_is(403); |
194 |
|
193 |
|
195 |
$t->put_ok( "//$nopermission_userid:$password@/api/v1/holds/0" => json => $put_data ) |
194 |
$t->patch_ok( "//$nopermission_userid:$password@/api/v1/holds/0" => json => $patch_data ) |
196 |
->status_is(403); |
195 |
->status_is(403); |
197 |
|
196 |
|
198 |
$t->delete_ok( "//$nopermission_userid:$password@/api/v1/holds/0" ) |
197 |
$t->delete_ok( "//$nopermission_userid:$password@/api/v1/holds/0" ) |
Lines 218-224
subtest "Test endpoints with permission" => sub {
Link Here
|
218 |
->status_is(204, 'SWAGGER3.2.4') |
217 |
->status_is(204, 'SWAGGER3.2.4') |
219 |
->content_is('', 'SWAGGER3.3.4'); |
218 |
->content_is('', 'SWAGGER3.3.4'); |
220 |
|
219 |
|
221 |
$t->put_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" => json => $put_data ) |
220 |
$t->patch_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" => json => $patch_data ) |
222 |
->status_is(404) |
221 |
->status_is(404) |
223 |
->json_has('/error'); |
222 |
->json_has('/error'); |
224 |
|
223 |
|
Lines 262-273
subtest "Test endpoints with permission" => sub {
Link Here
|
262 |
->status_is(403) |
261 |
->status_is(403) |
263 |
->json_like('/error', qr/itemAlreadyOnHold/); |
262 |
->json_like('/error', qr/itemAlreadyOnHold/); |
264 |
|
263 |
|
265 |
$post_data->{biblionumber} = int($biblio_2->biblionumber); |
264 |
$post_data->{biblio_id} = $biblio_2->biblionumber; |
266 |
$post_data->{itemnumber} = int($item_2->itemnumber); |
265 |
$post_data->{item_id} = $item_2->itemnumber; |
267 |
|
266 |
|
268 |
$t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) |
267 |
$t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) |
269 |
->status_is(403) |
268 |
->status_is(403) |
270 |
->json_like('/error', qr/itemAlreadyOnHold/); |
269 |
->json_like('/error', qr/Hold cannot be placed. Reason: tooManyReserves/); |
271 |
|
270 |
|
272 |
my $to_delete_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
271 |
my $to_delete_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
273 |
my $deleted_patron_id = $to_delete_patron->borrowernumber; |
272 |
my $deleted_patron_id = $to_delete_patron->borrowernumber; |
Lines 326-338
subtest 'test AllowHoldDateInFuture' => sub {
Link Here
|
326 |
my $future_hold_date = DateTime->now->add(days => 10)->truncate( to => 'day' ); |
325 |
my $future_hold_date = DateTime->now->add(days => 10)->truncate( to => 'day' ); |
327 |
|
326 |
|
328 |
my $post_data = { |
327 |
my $post_data = { |
329 |
patron_id => int($patron_1->borrowernumber), |
328 |
patron_id => $patron_1->borrowernumber, |
330 |
biblio_id => int($biblio_1->biblionumber), |
329 |
biblio_id => $biblio_1->biblionumber, |
331 |
item_id => int($item_1->itemnumber), |
330 |
item_id => $item_1->itemnumber, |
332 |
pickup_library_id => $branchcode, |
331 |
pickup_library_id => $branchcode, |
333 |
expiration_date => output_pref({ dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 }), |
332 |
expiration_date => output_pref( { dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 } ), |
334 |
hold_date => output_pref({ dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 }), |
333 |
hold_date => output_pref( { dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 } ), |
335 |
priority => 2, |
|
|
336 |
}; |
334 |
}; |
337 |
|
335 |
|
338 |
t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 ); |
336 |
t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 ); |
Lines 953-962
subtest 'edit() tests' => sub {
Link Here
|
953 |
} |
951 |
} |
954 |
); |
952 |
); |
955 |
|
953 |
|
956 |
my $biblio_hold_data = $biblio_hold->to_api; |
954 |
my $biblio_hold_api_data = $biblio_hold->to_api; |
957 |
$biblio_hold_data->{pickup_library_id} = $library_1->branchcode; |
955 |
my $biblio_hold_data = { |
|
|
956 |
pickup_library_id => $library_1->branchcode, |
957 |
priority => $biblio_hold_api_data->{priority} |
958 |
}; |
958 |
|
959 |
|
959 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
960 |
$t->patch_ok( "//$userid:$password@/api/v1/holds/" |
960 |
. $biblio_hold->id |
961 |
. $biblio_hold->id |
961 |
=> json => $biblio_hold_data ) |
962 |
=> json => $biblio_hold_data ) |
962 |
->status_is(400) |
963 |
->status_is(400) |
Lines 965-978
subtest 'edit() tests' => sub {
Link Here
|
965 |
$biblio_hold->discard_changes; |
966 |
$biblio_hold->discard_changes; |
966 |
is( $biblio_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); |
967 |
is( $biblio_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); |
967 |
|
968 |
|
968 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" . $biblio_hold->id |
969 |
$t->patch_ok( "//$userid:$password@/api/v1/holds/" . $biblio_hold->id |
969 |
=> { 'x-koha-override' => 'any' } |
970 |
=> { 'x-koha-override' => 'any' } |
970 |
=> json => $biblio_hold_data ) |
971 |
=> json => $biblio_hold_data ) |
971 |
->status_is(200) |
972 |
->status_is(200) |
972 |
->json_has( '/pickup_library_id' => $library_1->id ); |
973 |
->json_has( '/pickup_library_id' => $library_1->id ); |
973 |
|
974 |
|
974 |
$biblio_hold_data->{pickup_library_id} = $library_2->branchcode; |
975 |
$biblio_hold_data->{pickup_library_id} = $library_2->branchcode; |
975 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
976 |
$t->patch_ok( "//$userid:$password@/api/v1/holds/" |
976 |
. $biblio_hold->id |
977 |
. $biblio_hold->id |
977 |
=> json => $biblio_hold_data ) |
978 |
=> json => $biblio_hold_data ) |
978 |
->status_is(200); |
979 |
->status_is(200); |
Lines 993-1002
subtest 'edit() tests' => sub {
Link Here
|
993 |
} |
994 |
} |
994 |
); |
995 |
); |
995 |
|
996 |
|
996 |
my $item_hold_data = $item_hold->to_api; |
997 |
my $item_hold_api_data = $item_hold->to_api; |
997 |
$item_hold_data->{pickup_library_id} = $library_1->branchcode; |
998 |
my $item_hold_data = { |
|
|
999 |
pickup_library_id => $library_1->branchcode, |
1000 |
priority => $item_hold_api_data->{priority} |
1001 |
}; |
998 |
|
1002 |
|
999 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1003 |
$t->patch_ok( "//$userid:$password@/api/v1/holds/" |
1000 |
. $item_hold->id |
1004 |
. $item_hold->id |
1001 |
=> json => $item_hold_data ) |
1005 |
=> json => $item_hold_data ) |
1002 |
->status_is(400) |
1006 |
->status_is(400) |
Lines 1005-1018
subtest 'edit() tests' => sub {
Link Here
|
1005 |
$item_hold->discard_changes; |
1009 |
$item_hold->discard_changes; |
1006 |
is( $item_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); |
1010 |
is( $item_hold->branchcode, $library_3->branchcode, 'branchcode remains untouched' ); |
1007 |
|
1011 |
|
1008 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" . $item_hold->id |
1012 |
$t->patch_ok( "//$userid:$password@/api/v1/holds/" . $item_hold->id |
1009 |
=> { 'x-koha-override' => 'any' } |
1013 |
=> { 'x-koha-override' => 'any' } |
1010 |
=> json => $item_hold_data ) |
1014 |
=> json => $item_hold_data ) |
1011 |
->status_is(200) |
1015 |
->status_is(200) |
1012 |
->json_has( '/pickup_library_id' => $library_1->id ); |
1016 |
->json_has( '/pickup_library_id' => $library_1->id ); |
1013 |
|
1017 |
|
1014 |
$item_hold_data->{pickup_library_id} = $library_2->branchcode; |
1018 |
$item_hold_data->{pickup_library_id} = $library_2->branchcode; |
1015 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1019 |
$t->patch_ok( "//$userid:$password@/api/v1/holds/" |
1016 |
. $item_hold->id |
1020 |
. $item_hold->id |
1017 |
=> json => $item_hold_data ) |
1021 |
=> json => $item_hold_data ) |
1018 |
->status_is(200); |
1022 |
->status_is(200); |
Lines 1098-1107
subtest 'add() tests' => sub {
Link Here
|
1098 |
} |
1102 |
} |
1099 |
); |
1103 |
); |
1100 |
|
1104 |
|
1101 |
my $biblio_hold_data = $biblio_hold->to_api; |
1105 |
my $biblio_hold_api_data = $biblio_hold->to_api; |
1102 |
$biblio_hold->delete; |
1106 |
$biblio_hold->delete; |
1103 |
$biblio_hold_data->{pickup_library_id} = $library_1->branchcode; |
1107 |
my $biblio_hold_data = { |
1104 |
delete $biblio_hold_data->{hold_id}; |
1108 |
biblio_id => $biblio_hold_api_data->{biblio_id}, |
|
|
1109 |
patron_id => $biblio_hold_api_data->{patron_id}, |
1110 |
pickup_library_id => $library_1->branchcode, |
1111 |
}; |
1105 |
|
1112 |
|
1106 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $biblio_hold_data ) |
1113 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $biblio_hold_data ) |
1107 |
->status_is(400) |
1114 |
->status_is(400) |
Lines 1124-1133
subtest 'add() tests' => sub {
Link Here
|
1124 |
} |
1131 |
} |
1125 |
); |
1132 |
); |
1126 |
|
1133 |
|
1127 |
my $item_hold_data = $item_hold->to_api; |
1134 |
my $item_hold_api_data = $item_hold->to_api; |
1128 |
$item_hold->delete; |
1135 |
$item_hold->delete; |
1129 |
$item_hold_data->{pickup_library_id} = $library_1->branchcode; |
1136 |
my $item_hold_data = { |
1130 |
delete $item_hold->{hold_id}; |
1137 |
biblio_id => $item_hold_api_data->{biblio_id}, |
|
|
1138 |
item_id => $item_hold_api_data->{item_id}, |
1139 |
patron_id => $item_hold_api_data->{patron_id}, |
1140 |
pickup_library_id => $library_1->branchcode, |
1141 |
}; |
1131 |
|
1142 |
|
1132 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $item_hold_data ) |
1143 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $item_hold_data ) |
1133 |
->status_is(400) |
1144 |
->status_is(400) |
1134 |
- |
|
|