Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 1; |
20 |
use Test::More tests => 2; |
|
|
21 |
use Test::MockModule; |
21 |
use Test::Mojo; |
22 |
use Test::Mojo; |
22 |
|
23 |
|
23 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
Lines 68-70
subtest 'list() tests' => sub {
Link Here
|
68 |
|
69 |
|
69 |
$schema->storage->txn_rollback; |
70 |
$schema->storage->txn_rollback; |
70 |
}; |
71 |
}; |
71 |
- |
72 |
|
|
|
73 |
subtest 'delete_public() tests' => sub { |
74 |
|
75 |
plan tests => 13; |
76 |
|
77 |
$schema->storage->txn_begin; |
78 |
|
79 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); |
80 |
|
81 |
my $patron = $builder->build_object( |
82 |
{ |
83 |
class => 'Koha::Patrons', |
84 |
value => { flags => 0 }, |
85 |
} |
86 |
); |
87 |
my $password = 'thePassword123'; |
88 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
89 |
my $userid = $patron->userid; |
90 |
|
91 |
my $hold_to_delete = $builder->build_object( { class => 'Koha::Holds' } ); |
92 |
my $deleted_hold_id = $hold_to_delete->id; |
93 |
$hold_to_delete->delete; |
94 |
|
95 |
$t->delete_ok( "//$userid:$password@/api/v1/public/patrons/" . $patron->id . '/holds/' . $deleted_hold_id ) |
96 |
->status_is(404); |
97 |
|
98 |
my $another_user_hold = $builder->build_object( { class => 'Koha::Holds' } ); |
99 |
|
100 |
$t->delete_ok( "//$userid:$password@/api/v1/public/patrons/" . $patron->id . '/holds/' . $another_user_hold->id ) |
101 |
->status_is( 404, 'Invalid patron_id and hold_id combination yields 404' ); |
102 |
|
103 |
my $non_waiting_hold = $builder->build_object( |
104 |
{ |
105 |
class => 'Koha::Holds', |
106 |
value => { |
107 |
borrowernumber => $patron->id, |
108 |
found => undef, |
109 |
itemnumber => undef |
110 |
} |
111 |
} |
112 |
); |
113 |
|
114 |
$t->delete_ok( "//$userid:$password@/api/v1/public/patrons/" . $patron->id . '/holds/' . $non_waiting_hold->id ) |
115 |
->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' ); |
116 |
|
117 |
my $cancellation_requestable; |
118 |
|
119 |
my $hold_mock = Test::MockModule->new('Koha::Hold'); |
120 |
$hold_mock->mock( 'cancellation_requestable_from_opac', sub { return $cancellation_requestable; } ); |
121 |
|
122 |
my $item = $builder->build_sample_item; |
123 |
my $waiting_hold = $builder->build_object( |
124 |
{ |
125 |
class => 'Koha::Holds', |
126 |
value => { |
127 |
borrowernumber => $patron->id, |
128 |
found => 'W', |
129 |
itemnumber => $item->id, |
130 |
} |
131 |
} |
132 |
); |
133 |
|
134 |
$cancellation_requestable = 0; |
135 |
|
136 |
$t->delete_ok( "//$userid:$password@/api/v1/public/patrons/" . $patron->id . '/holds/' . $waiting_hold->id ) |
137 |
->status_is(403)->json_is( { error => 'Cancellation forbidden' } ); |
138 |
|
139 |
$cancellation_requestable = 1; |
140 |
|
141 |
$t->delete_ok( "//$userid:$password@/api/v1/public/patrons/" . $patron->id . '/holds/' . $waiting_hold->id ) |
142 |
->status_is(202); |
143 |
|
144 |
my $cancellation_requests = $waiting_hold->cancellation_requests; |
145 |
is( $cancellation_requests->count, 1, 'Cancellation request recorded' ); |
146 |
|
147 |
$schema->storage->txn_rollback; |
148 |
}; |