View | Details | Raw Unified | Return to bug 24487
Collapse All | Expand All

(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-6 / +32 lines)
Lines 17-22 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Koha::Cities;
19
use Koha::Cities;
20
use Koha::Holds;
20
21
21
# Dummy app for testing the plugin
22
# Dummy app for testing the plugin
22
use Mojolicious::Lite;
23
use Mojolicious::Lite;
Lines 58-63 get '/cities_sorted' => sub { Link Here
58
    $c->render( status => 200, json => $cities );
59
    $c->render( status => 200, json => $cities );
59
};
60
};
60
61
62
get '/patrons/:patron_id/holds' => sub {
63
    my $c = shift;
64
    my $params = $c->req->params->to_hash;
65
    $params->{patron_id} = $c->stash("patron_id");
66
    $c->validation->output($params);
67
    my $holds_set = Koha::Holds->new;
68
    my $holds     = $c->objects->search( $holds_set );
69
    $c->render( status => 200, json => {count => scalar(@$holds)} );
70
};
71
61
sub to_model {
72
sub to_model {
62
    my $params = shift;
73
    my $params = shift;
63
74
Lines 79-93 sub to_api { Link Here
79
}
90
}
80
91
81
# The tests
92
# The tests
82
use Test::More tests => 2;
93
use Test::More tests => 3;
83
use Test::Mojo;
94
use Test::Mojo;
84
95
85
use t::lib::TestBuilder;
96
use t::lib::TestBuilder;
86
use Koha::Database;
97
use Koha::Database;
87
98
88
my $schema = Koha::Database->new()->schema();
99
my $schema = Koha::Database->new->schema;
89
90
91
my $builder = t::lib::TestBuilder->new;
100
my $builder = t::lib::TestBuilder->new;
92
101
93
subtest 'objects.search helper' => sub {
102
subtest 'objects.search helper' => sub {
Lines 273-276 subtest 'objects.search helper, sorting on mapped column' => sub { Link Here
273
      ->json_is('/1/nombre' => 'A');
282
      ->json_is('/1/nombre' => 'A');
274
283
275
    $schema->storage->txn_rollback;
284
    $schema->storage->txn_rollback;
276
}
285
};
286
287
subtest 'objects.search helper, with path parameters and _match' => sub {
288
    plan tests => 4;
289
290
    $schema->storage->txn_begin;
291
292
    Koha::Holds->search()->delete;
293
294
    $builder->build_object({class=>"Koha::Holds", value => {borrowernumber => 10 }});
295
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
    $schema->storage->txn_rollback;
303
};
277
- 

Return to bug 24487