Lines 65-74
get '/patrons/:patron_id/holds' => sub {
Link Here
|
65 |
$params->{patron_id} = $c->stash("patron_id"); |
65 |
$params->{patron_id} = $c->stash("patron_id"); |
66 |
$c->validation->output($params); |
66 |
$c->validation->output($params); |
67 |
my $holds_set = Koha::Holds->new; |
67 |
my $holds_set = Koha::Holds->new; |
68 |
my $holds = $c->objects->search( $holds_set ); |
68 |
my $holds = $c->objects->search( $holds_set, \&to_model_holds ); |
69 |
$c->render( status => 200, json => {count => scalar(@$holds)} ); |
69 |
$c->render( status => 200, json => {count => scalar(@$holds)} ); |
70 |
}; |
70 |
}; |
71 |
|
71 |
|
|
|
72 |
sub to_model_holds { |
73 |
my ($params) = @_; |
74 |
$params->{borrowernumber} = delete $params->{patron_id}; |
75 |
return $params; |
76 |
} |
77 |
|
72 |
sub to_model { |
78 |
sub to_model { |
73 |
my $params = shift; |
79 |
my $params = shift; |
74 |
|
80 |
|
Lines 99-110
use Koha::Database;
Link Here
|
99 |
my $schema = Koha::Database->new->schema; |
105 |
my $schema = Koha::Database->new->schema; |
100 |
my $builder = t::lib::TestBuilder->new; |
106 |
my $builder = t::lib::TestBuilder->new; |
101 |
|
107 |
|
|
|
108 |
my $t = Test::Mojo->new; |
109 |
|
102 |
subtest 'objects.search helper' => sub { |
110 |
subtest 'objects.search helper' => sub { |
103 |
|
111 |
|
104 |
plan tests => 90; |
112 |
plan tests => 90; |
105 |
|
113 |
|
106 |
my $t = Test::Mojo->new; |
|
|
107 |
|
108 |
$schema->storage->txn_begin; |
114 |
$schema->storage->txn_begin; |
109 |
|
115 |
|
110 |
# Remove existing cities to have more control on the search restuls |
116 |
# Remove existing cities to have more control on the search restuls |
Lines 285-297
subtest 'objects.search helper, sorting on mapped column' => sub {
Link Here
|
285 |
}; |
291 |
}; |
286 |
|
292 |
|
287 |
subtest 'objects.search helper, with path parameters and _match' => sub { |
293 |
subtest 'objects.search helper, with path parameters and _match' => sub { |
288 |
plan tests => 4; |
294 |
plan tests => 8; |
289 |
|
295 |
|
290 |
$schema->storage->txn_begin; |
296 |
$schema->storage->txn_begin; |
291 |
|
297 |
|
292 |
Koha::Holds->search()->delete; |
298 |
Koha::Holds->search()->delete; |
293 |
|
299 |
|
294 |
$builder->build_object({class=>"Koha::Holds", value => {borrowernumber => 10 }}); |
300 |
my $patron = Koha::Patrons->find(10); |
|
|
301 |
$patron->delete if $patron; |
302 |
$patron = $builder->build_object( { class => "Koha::Patrons" } ); |
303 |
$patron->borrowernumber(10)->store; |
304 |
$builder->build_object( |
305 |
{ |
306 |
class => "Koha::Holds", |
307 |
value => { borrowernumber => $patron->borrowernumber } |
308 |
} |
309 |
); |
295 |
|
310 |
|
296 |
$t->get_ok('/patrons/1/holds?_match=exact') |
311 |
$t->get_ok('/patrons/1/holds?_match=exact') |
297 |
->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=exact'); |
312 |
->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=exact'); |
Lines 299-303
subtest 'objects.search helper, with path parameters and _match' => sub {
Link Here
|
299 |
$t->get_ok('/patrons/1/holds?_match=contains') |
314 |
$t->get_ok('/patrons/1/holds?_match=contains') |
300 |
->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=contains'); |
315 |
->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=contains'); |
301 |
|
316 |
|
|
|
317 |
$t->get_ok('/patrons/10/holds?_match=exact') |
318 |
->json_is('/count' => 1, 'there should be 1 hold for borrower 10 with _match=exact'); |
319 |
|
320 |
$t->get_ok('/patrons/10/holds?_match=contains') |
321 |
->json_is('/count' => 1, 'there should be 1 hold for borrower 10 with _match=contains'); |
322 |
|
302 |
$schema->storage->txn_rollback; |
323 |
$schema->storage->txn_rollback; |
303 |
}; |
324 |
}; |
304 |
- |
|
|