|
Lines 19-25
use Modern::Perl;
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Koha::Acquisition::Orders; |
20 |
use Koha::Acquisition::Orders; |
| 21 |
use Koha::Cities; |
21 |
use Koha::Cities; |
| 22 |
use Koha::Holds; |
|
|
| 23 |
use Koha::Biblios; |
22 |
use Koha::Biblios; |
| 24 |
|
23 |
|
| 25 |
# Dummy app for testing the plugin |
24 |
# Dummy app for testing the plugin |
|
Lines 46-61
get '/orders' => sub {
Link Here
|
| 46 |
$c->render( status => 200, json => $orders ); |
45 |
$c->render( status => 200, json => $orders ); |
| 47 |
}; |
46 |
}; |
| 48 |
|
47 |
|
| 49 |
get '/patrons/:patron_id/holds' => sub { |
|
|
| 50 |
my $c = shift; |
| 51 |
my $params = $c->req->params->to_hash; |
| 52 |
$params->{patron_id} = $c->stash("patron_id"); |
| 53 |
$c->validation->output($params); |
| 54 |
my $holds_set = Koha::Holds->new; |
| 55 |
my $holds = $c->objects->search( $holds_set ); |
| 56 |
$c->render( status => 200, json => {count => scalar(@$holds)} ); |
| 57 |
}; |
| 58 |
|
| 59 |
get '/biblios' => sub { |
48 |
get '/biblios' => sub { |
| 60 |
my $c = shift; |
49 |
my $c = shift; |
| 61 |
my $output = $c->req->params->to_hash; |
50 |
my $output = $c->req->params->to_hash; |
|
Lines 75-83
get '/biblios' => sub {
Link Here
|
| 75 |
$c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} ); |
64 |
$c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} ); |
| 76 |
}; |
65 |
}; |
| 77 |
|
66 |
|
| 78 |
|
|
|
| 79 |
# The tests |
67 |
# The tests |
| 80 |
use Test::More tests => 10; |
68 |
use Test::More tests => 9; |
| 81 |
use Test::Mojo; |
69 |
use Test::Mojo; |
| 82 |
|
70 |
|
| 83 |
use t::lib::Mocks; |
71 |
use t::lib::Mocks; |
|
Lines 274-313
subtest 'objects.search helper, embed' => sub {
Link Here
|
| 274 |
$schema->storage->txn_rollback; |
262 |
$schema->storage->txn_rollback; |
| 275 |
}; |
263 |
}; |
| 276 |
|
264 |
|
| 277 |
subtest 'objects.search helper, with path parameters and _match' => sub { |
|
|
| 278 |
plan tests => 8; |
| 279 |
|
| 280 |
$schema->storage->txn_begin; |
| 281 |
|
| 282 |
Koha::Holds->search()->delete; |
| 283 |
|
| 284 |
my $patron = Koha::Patrons->find(10); |
| 285 |
$patron->delete if $patron; |
| 286 |
$patron = $builder->build_object( { class => "Koha::Patrons" } ); |
| 287 |
$patron->borrowernumber(10)->store; |
| 288 |
$builder->build_object( |
| 289 |
{ |
| 290 |
class => "Koha::Holds", |
| 291 |
value => { borrowernumber => $patron->borrowernumber } |
| 292 |
} |
| 293 |
); |
| 294 |
|
| 295 |
my $t = Test::Mojo->new; |
| 296 |
$t->get_ok('/patrons/1/holds?_match=exact') |
| 297 |
->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=exact'); |
| 298 |
|
| 299 |
$t->get_ok('/patrons/1/holds?_match=contains') |
| 300 |
->json_is('/count' => 0, 'there should be no holds for borrower 1 with _match=contains'); |
| 301 |
|
| 302 |
$t->get_ok('/patrons/10/holds?_match=exact') |
| 303 |
->json_is('/count' => 1, 'there should be 1 hold for borrower 10 with _match=exact'); |
| 304 |
|
| 305 |
$t->get_ok('/patrons/10/holds?_match=contains') |
| 306 |
->json_is('/count' => 1, 'there should be 1 hold for borrower 10 with _match=contains'); |
| 307 |
|
| 308 |
$schema->storage->txn_rollback; |
| 309 |
}; |
| 310 |
|
| 311 |
subtest 'object.search helper with query parameter' => sub { |
265 |
subtest 'object.search helper with query parameter' => sub { |
| 312 |
plan tests => 4; |
266 |
plan tests => 4; |
| 313 |
|
267 |
|
| 314 |
- |
|
|