Lines 20-25
use Modern::Perl;
Link Here
|
20 |
use Koha::Acquisition::Orders; |
20 |
use Koha::Acquisition::Orders; |
21 |
use Koha::Cities; |
21 |
use Koha::Cities; |
22 |
use Koha::Holds; |
22 |
use Koha::Holds; |
|
|
23 |
use Koha::Biblios; |
23 |
|
24 |
|
24 |
# Dummy app for testing the plugin |
25 |
# Dummy app for testing the plugin |
25 |
use Mojolicious::Lite; |
26 |
use Mojolicious::Lite; |
Lines 55-62
get '/patrons/:patron_id/holds' => sub {
Link Here
|
55 |
$c->render( status => 200, json => {count => scalar(@$holds)} ); |
56 |
$c->render( status => 200, json => {count => scalar(@$holds)} ); |
56 |
}; |
57 |
}; |
57 |
|
58 |
|
|
|
59 |
get '/biblios' => sub { |
60 |
my $c = shift; |
61 |
my $output = $c->req->params->to_hash; |
62 |
$output->{query} = $c->req->json if defined $c->req->json; |
63 |
my $headers = $c->req->headers->to_hash; |
64 |
$output->{'x-koha-query'} = $headers->{'x-koha-query'} if defined $headers->{'x-koha-query'}; |
65 |
$c->validation->output($output); |
66 |
my $biblios_set = Koha::Biblios->new; |
67 |
$c->stash("koha.embed", { |
68 |
"suggestions" => { |
69 |
children => { |
70 |
"suggester" => {} |
71 |
} |
72 |
} |
73 |
}); |
74 |
my $biblios = $c->objects->search($biblios_set); |
75 |
|
76 |
$c->render( status => 200, json => {count => scalar(@$biblios)} ); |
77 |
}; |
78 |
|
58 |
# The tests |
79 |
# The tests |
59 |
use Test::More tests => 4; |
80 |
use Test::More tests => 8; |
60 |
use Test::Mojo; |
81 |
use Test::Mojo; |
61 |
|
82 |
|
62 |
use t::lib::TestBuilder; |
83 |
use t::lib::TestBuilder; |
Lines 220-222
subtest 'objects.search helper, with path parameters and _match' => sub {
Link Here
|
220 |
|
241 |
|
221 |
$schema->storage->txn_rollback; |
242 |
$schema->storage->txn_rollback; |
222 |
}; |
243 |
}; |
223 |
- |
244 |
|
|
|
245 |
subtest 'object.search helper with query parameter' => sub { |
246 |
plan tests => 4; |
247 |
|
248 |
$schema->storage->txn_begin; |
249 |
|
250 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" } ); |
251 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" } ); |
252 |
my $biblio1 = $builder->build_sample_biblio; |
253 |
my $biblio2 = $builder->build_sample_biblio; |
254 |
my $biblio3 = $builder->build_sample_biblio; |
255 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
256 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
257 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
258 |
|
259 |
$t->get_ok('/biblios' => json => {"suggestions.suggester.patron_id" => $patron1->borrowernumber }) |
260 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
261 |
|
262 |
$t->get_ok('/biblios' => json => {"suggestions.suggester.patron_id" => $patron2->borrowernumber }) |
263 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
264 |
|
265 |
$schema->storage->txn_rollback; |
266 |
}; |
267 |
|
268 |
subtest 'object.search helper with q parameter' => sub { |
269 |
plan tests => 4; |
270 |
|
271 |
$schema->storage->txn_begin; |
272 |
|
273 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" } ); |
274 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" } ); |
275 |
my $biblio1 = $builder->build_sample_biblio; |
276 |
my $biblio2 = $builder->build_sample_biblio; |
277 |
my $biblio3 = $builder->build_sample_biblio; |
278 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
279 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
280 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
281 |
|
282 |
$t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}') |
283 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
284 |
|
285 |
$t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}') |
286 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
287 |
|
288 |
$schema->storage->txn_rollback; |
289 |
}; |
290 |
|
291 |
subtest 'object.search helper with x-koha-query header' => sub { |
292 |
plan tests => 4; |
293 |
|
294 |
$schema->storage->txn_begin; |
295 |
|
296 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" } ); |
297 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" } ); |
298 |
my $biblio1 = $builder->build_sample_biblio; |
299 |
my $biblio2 = $builder->build_sample_biblio; |
300 |
my $biblio3 = $builder->build_sample_biblio; |
301 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
302 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
303 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
304 |
|
305 |
$t->get_ok('/biblios' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'}) |
306 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
307 |
|
308 |
$t->get_ok('/biblios' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'}) |
309 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
310 |
|
311 |
$schema->storage->txn_rollback; |
312 |
}; |
313 |
|
314 |
subtest 'object.search helper with all query methods' => sub { |
315 |
plan tests => 6; |
316 |
|
317 |
$schema->storage->txn_begin; |
318 |
|
319 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {cardnumber => 'cardpatron1', firstname=>'patron1'} } ); |
320 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {cardnumber => 'cardpatron2', firstname=>'patron2'} } ); |
321 |
my $biblio1 = $builder->build_sample_biblio; |
322 |
my $biblio2 = $builder->build_sample_biblio; |
323 |
my $biblio3 = $builder->build_sample_biblio; |
324 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
325 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
326 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
327 |
|
328 |
$t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron1->cardnumber}) |
329 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
330 |
|
331 |
$t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron2->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron2->cardnumber}) |
332 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
333 |
|
334 |
$t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron2->cardnumber}) |
335 |
->json_is('/count' => 0, 'there shouldn\'t be biblios where suggester has patron1 fistname and patron2 id'); |
336 |
|
337 |
$schema->storage->txn_rollback; |
338 |
}; |