Lines 31-42
get '/patrons' => sub {
Link Here
|
31 |
my $c = shift; |
31 |
my $c = shift; |
32 |
$c->validation->output($c->req->params->to_hash); |
32 |
$c->validation->output($c->req->params->to_hash); |
33 |
my $patrons = $c->objects->search(Koha::Patrons->new); |
33 |
my $patrons = $c->objects->search(Koha::Patrons->new); |
34 |
$c->render( status => 200, json => $patrons->TO_JSON ); |
34 |
$c->render( status => 200, json => $patrons ); |
35 |
}; |
35 |
}; |
36 |
|
36 |
|
37 |
|
37 |
|
38 |
# The tests |
38 |
# The tests |
39 |
|
|
|
40 |
use Test::More tests => 1; |
39 |
use Test::More tests => 1; |
41 |
use Test::Mojo; |
40 |
use Test::Mojo; |
42 |
|
41 |
|
Lines 44-77
use t::lib::TestBuilder;
Link Here
|
44 |
use Koha::Database; |
43 |
use Koha::Database; |
45 |
|
44 |
|
46 |
my $schema = Koha::Database->new()->schema(); |
45 |
my $schema = Koha::Database->new()->schema(); |
47 |
$schema->storage->txn_begin(); |
46 |
|
48 |
|
47 |
|
49 |
my $builder = t::lib::TestBuilder->new; |
48 |
my $builder = t::lib::TestBuilder->new; |
50 |
$builder->build({ |
|
|
51 |
source => 'Borrower', |
52 |
value => { |
53 |
firstname => 'Manuel', |
54 |
}, |
55 |
}); |
56 |
$builder->build({ |
57 |
source => 'Borrower', |
58 |
value => { |
59 |
firstname => 'Manuel', |
60 |
}, |
61 |
}); |
62 |
|
49 |
|
63 |
subtest 'objects.search helper' => sub { |
50 |
subtest 'objects.search helper' => sub { |
64 |
|
51 |
|
65 |
plan tests => 6; |
52 |
plan tests => 34; |
66 |
|
53 |
|
67 |
my $t = Test::Mojo->new; |
54 |
my $t = Test::Mojo->new; |
68 |
|
55 |
|
69 |
$t->get_ok('/patrons?firstname=Manuel&_per_page=1&_page=1') |
56 |
$schema->storage->txn_begin; |
|
|
57 |
|
58 |
# Delete existing patrons |
59 |
Koha::Patrons->search->delete; |
60 |
# Create two sample patrons that match the query |
61 |
$builder->build_object({ |
62 |
class => 'Koha::Patrons', |
63 |
value => { |
64 |
firstname => 'Manuel' |
65 |
} |
66 |
}); |
67 |
$builder->build_object({ |
68 |
class => 'Koha::Patrons', |
69 |
value => { |
70 |
firstname => 'Manuela' |
71 |
} |
72 |
}); |
73 |
|
74 |
$t->get_ok('/patrons?firstname=manuel&_per_page=1&_page=1') |
70 |
->status_is(200) |
75 |
->status_is(200) |
71 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*&_page=2.*>; rel="next",/ ) |
76 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*&_page=2.*>; rel="next",/ ) |
72 |
->json_has('/0') |
77 |
->json_has('/0') |
73 |
->json_hasnt('/1') |
78 |
->json_hasnt('/1') |
74 |
->json_is('/0/firstname' => 'Manuel'); |
79 |
->json_is('/0/firstname' => 'Manuel'); |
75 |
}; |
|
|
76 |
|
80 |
|
77 |
$schema->storage->txn_rollback(); |
81 |
$builder->build_object({ |
|
|
82 |
class => 'Koha::Patrons', |
83 |
value => { |
84 |
firstname => 'Emanuel' |
85 |
} |
86 |
}); |
87 |
|
88 |
# _match=starts_with |
89 |
$t->get_ok('/patrons?firstname=manuel&_per_page=3&_page=1&_match=starts_with') |
90 |
->status_is(200) |
91 |
->json_has('/0') |
92 |
->json_has('/1') |
93 |
->json_hasnt('/2') |
94 |
->json_is('/0/firstname' => 'Manuel') |
95 |
->json_is('/1/firstname' => 'Manuela'); |
96 |
|
97 |
# _match=ends_with |
98 |
$t->get_ok('/patrons?firstname=manuel&_per_page=3&_page=1&_match=ends_with') |
99 |
->status_is(200) |
100 |
->json_has('/0') |
101 |
->json_has('/1') |
102 |
->json_hasnt('/2') |
103 |
->json_is('/0/firstname' => 'Manuel') |
104 |
->json_is('/1/firstname' => 'Emanuel'); |
105 |
|
106 |
# _match=exact |
107 |
$t->get_ok('/patrons?firstname=manuel&_per_page=3&_page=1&_match=exact') |
108 |
->status_is(200) |
109 |
->json_has('/0') |
110 |
->json_hasnt('/1') |
111 |
->json_is('/0/firstname' => 'Manuel'); |
112 |
|
113 |
# _match=contains |
114 |
$t->get_ok('/patrons?firstname=manuel&_per_page=3&_page=1&_match=contains') |
115 |
->status_is(200) |
116 |
->json_has('/0') |
117 |
->json_has('/1') |
118 |
->json_has('/2') |
119 |
->json_hasnt('/3') |
120 |
->json_is('/0/firstname' => 'Manuel') |
121 |
->json_is('/1/firstname' => 'Manuela') |
122 |
->json_is('/2/firstname' => 'Emanuel'); |
123 |
|
124 |
$schema->storage->txn_rollback; |
125 |
}; |
78 |
- |
|
|