|
Lines 18-24
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
| 21 |
use Test::More tests => 3; |
21 |
use Test::More tests => 4; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
| 23 |
use Test::Mojo; |
23 |
use Test::Mojo; |
| 24 |
|
24 |
|
|
Lines 171-173
subtest 'add() tests' => sub {
Link Here
|
| 171 |
|
171 |
|
| 172 |
$schema->storage->txn_rollback; |
172 |
$schema->storage->txn_rollback; |
| 173 |
}; |
173 |
}; |
| 174 |
- |
174 |
|
|
|
175 |
subtest 'delete() tests' => sub { |
| 176 |
plan tests => 8; |
| 177 |
|
| 178 |
$schema->storage->txn_begin; |
| 179 |
|
| 180 |
my $authorized_patron = $builder->build_object( |
| 181 |
{ |
| 182 |
class => 'Koha::Patrons', |
| 183 |
value => { flags => 1 } |
| 184 |
} |
| 185 |
); |
| 186 |
my $password = 'thePassword123'; |
| 187 |
$authorized_patron->set_password( { password => $password, skip_validation => 1 } ); |
| 188 |
my $auth_userid = $authorized_patron->userid; |
| 189 |
|
| 190 |
my $unauthorized_patron = $builder->build_object( |
| 191 |
{ |
| 192 |
class => 'Koha::Patrons', |
| 193 |
value => { flags => 4 } |
| 194 |
} |
| 195 |
); |
| 196 |
$unauthorized_patron->set_password( { password => $password, skip_validation => 1 } ); |
| 197 |
my $unauth_userid = $unauthorized_patron->userid; |
| 198 |
|
| 199 |
my $hold_1 = $builder->build_object( |
| 200 |
{ |
| 201 |
class => 'Koha::Holds', |
| 202 |
value => { borrowernumber => $authorized_patron->id, hold_group_id => undef, found => undef } |
| 203 |
} |
| 204 |
); |
| 205 |
my $hold_2 = $builder->build_object( |
| 206 |
{ |
| 207 |
class => 'Koha::Holds', |
| 208 |
value => { borrowernumber => $authorized_patron->id, hold_group_id => undef, found => undef } |
| 209 |
} |
| 210 |
); |
| 211 |
|
| 212 |
my $hold_3 = $builder->build_object( |
| 213 |
{ |
| 214 |
class => 'Koha::Holds', |
| 215 |
value => { borrowernumber => $unauthorized_patron->borrowernumber, hold_group_id => undef, found => undef } |
| 216 |
} |
| 217 |
); |
| 218 |
my $hold_4 = $builder->build_object( |
| 219 |
{ |
| 220 |
class => 'Koha::Holds', |
| 221 |
value => { borrowernumber => $unauthorized_patron->borrowernumber, hold_group_id => undef, found => undef } |
| 222 |
} |
| 223 |
); |
| 224 |
|
| 225 |
my $unauth_hold_group = $unauthorized_patron->create_hold_group( [ $hold_3->reserve_id, $hold_4->reserve_id ] ); |
| 226 |
my $hold_group = $authorized_patron->create_hold_group( [ $hold_1->reserve_id, $hold_2->reserve_id ] ); |
| 227 |
|
| 228 |
# Unauthorized attempt to delete |
| 229 |
$t->delete_ok( "//$unauth_userid:$password@/api/v1/patrons/" |
| 230 |
. $unauthorized_patron->borrowernumber |
| 231 |
. "/hold_groups/" |
| 232 |
. $unauth_hold_group->hold_group_id )->status_is(403); |
| 233 |
|
| 234 |
# Attempt to delete a hold group of another patron |
| 235 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/patrons/" |
| 236 |
. $authorized_patron->borrowernumber |
| 237 |
. "/hold_groups/" |
| 238 |
. $unauth_hold_group->hold_group_id )->status_is(404); |
| 239 |
|
| 240 |
# Successful deletion |
| 241 |
$t->delete_ok( "//$auth_userid:$password@/api/v1/patrons/" |
| 242 |
. $authorized_patron->borrowernumber |
| 243 |
. "/hold_groups/" |
| 244 |
. $hold_group->hold_group_id )->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' ); |
| 245 |
|
| 246 |
my $nonexistent_hold = Koha::HoldGroups->find( $hold_group->hold_group_id ); |
| 247 |
is( $nonexistent_hold, undef, 'The hold group does not exist after deletion' ); |
| 248 |
|
| 249 |
$schema->storage->txn_rollback; |
| 250 |
}; |