Lines 109-122
my $t = Test::Mojo->new;
Link Here
|
109 |
|
109 |
|
110 |
subtest 'objects.search helper' => sub { |
110 |
subtest 'objects.search helper' => sub { |
111 |
|
111 |
|
112 |
plan tests => 90; |
112 |
plan tests => 38; |
113 |
|
113 |
|
114 |
$schema->storage->txn_begin; |
114 |
$schema->storage->txn_begin; |
115 |
|
115 |
|
116 |
# Remove existing cities to have more control on the search restuls |
116 |
# Remove existing cities to have more control on the search results |
117 |
Koha::Cities->delete; |
117 |
Koha::Cities->delete; |
118 |
|
118 |
|
119 |
# Create two sample patrons that match the query |
119 |
# Create three sample cities that match the query. This makes sure we |
|
|
120 |
# always have a "next" link regardless of Mojolicious::Plugin::OpenAPI version. |
120 |
$builder->build_object({ |
121 |
$builder->build_object({ |
121 |
class => 'Koha::Cities', |
122 |
class => 'Koha::Cities', |
122 |
value => { |
123 |
value => { |
Lines 129-138
subtest 'objects.search helper' => sub {
Link Here
|
129 |
city_name => 'Manuela' |
130 |
city_name => 'Manuela' |
130 |
} |
131 |
} |
131 |
}); |
132 |
}); |
|
|
133 |
$builder->build_object({ |
134 |
class => 'Koha::Cities', |
135 |
value => { |
136 |
city_name => 'Manuelab' |
137 |
} |
138 |
}); |
132 |
|
139 |
|
133 |
$t->get_ok('/cities?city_name=manuel&_per_page=1&_page=1') |
140 |
$t->get_ok('/cities?city_name=manuel&_per_page=1&_page=1') |
134 |
->status_is(200) |
141 |
->status_is(200) |
135 |
->header_like( 'Link' => qr/<http:\/\/.*\?.*&_page=2.*>; rel="next",/ ) |
142 |
->header_like( 'Link' => qr/<http:\/\/.*[\?&]_page=2.*>; rel="next",/ ) |
136 |
->json_has('/0') |
143 |
->json_has('/0') |
137 |
->json_hasnt('/1') |
144 |
->json_hasnt('/1') |
138 |
->json_is('/0/city_name' => 'Manuel'); |
145 |
->json_is('/0/city_name' => 'Manuel'); |
Lines 145-197
subtest 'objects.search helper' => sub {
Link Here
|
145 |
}); |
152 |
}); |
146 |
|
153 |
|
147 |
# _match=starts_with |
154 |
# _match=starts_with |
148 |
$t->get_ok('/cities?city_name=manuel&_per_page=3&_page=1&_match=starts_with') |
155 |
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=starts_with') |
149 |
->status_is(200) |
|
|
150 |
->json_has('/0') |
151 |
->json_has('/1') |
152 |
->json_hasnt('/2') |
153 |
->json_is('/0/city_name' => 'Manuel') |
154 |
->json_is('/1/city_name' => 'Manuela'); |
155 |
|
156 |
# _match=ends_with |
157 |
$t->get_ok('/cities?city_name=manuel&_per_page=3&_page=1&_match=ends_with') |
158 |
->status_is(200) |
159 |
->json_has('/0') |
160 |
->json_has('/1') |
161 |
->json_hasnt('/2') |
162 |
->json_is('/0/city_name' => 'Manuel') |
163 |
->json_is('/1/city_name' => 'Emanuel'); |
164 |
|
165 |
# _match=exact |
166 |
$t->get_ok('/cities?city_name=manuel&_per_page=3&_page=1&_match=exact') |
167 |
->status_is(200) |
168 |
->json_has('/0') |
169 |
->json_hasnt('/1') |
170 |
->json_is('/0/city_name' => 'Manuel'); |
171 |
|
172 |
# _match=contains |
173 |
$t->get_ok('/cities?city_name=manuel&_per_page=3&_page=1&_match=contains') |
174 |
->status_is(200) |
156 |
->status_is(200) |
175 |
->json_has('/0') |
157 |
->json_has('/0') |
176 |
->json_has('/1') |
158 |
->json_has('/1') |
177 |
->json_has('/2') |
159 |
->json_has('/2') |
178 |
->json_hasnt('/3') |
160 |
->json_hasnt('/3') |
179 |
->json_is('/0/city_name' => 'Manuel') |
161 |
->json_is('/0/name' => 'Manuel') |
180 |
->json_is('/1/city_name' => 'Manuela') |
162 |
->json_is('/1/name' => 'Manuela') |
181 |
->json_is('/2/city_name' => 'Emanuel'); |
163 |
->json_is('/2/name' => 'Manuelab'); |
182 |
|
|
|
183 |
## _to_model tests |
184 |
# _match=starts_with |
185 |
$t->get_ok('/cities_to_model?nombre=manuel&_per_page=3&_page=1&_match=starts_with') |
186 |
->status_is(200) |
187 |
->json_has('/0') |
188 |
->json_has('/1') |
189 |
->json_hasnt('/2') |
190 |
->json_is('/0/city_name' => 'Manuel') |
191 |
->json_is('/1/city_name' => 'Manuela'); |
192 |
|
164 |
|
193 |
# _match=ends_with |
165 |
# _match=ends_with |
194 |
$t->get_ok('/cities_to_model?nombre=manuel&_per_page=3&_page=1&_match=ends_with') |
166 |
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=ends_with') |
195 |
->status_is(200) |
167 |
->status_is(200) |
196 |
->json_has('/0') |
168 |
->json_has('/0') |
197 |
->json_has('/1') |
169 |
->json_has('/1') |
Lines 200-258
subtest 'objects.search helper' => sub {
Link Here
|
200 |
->json_is('/1/city_name' => 'Emanuel'); |
172 |
->json_is('/1/city_name' => 'Emanuel'); |
201 |
|
173 |
|
202 |
# _match=exact |
174 |
# _match=exact |
203 |
$t->get_ok('/cities_to_model?nombre=manuel&_per_page=3&_page=1&_match=exact') |
175 |
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=exact') |
204 |
->status_is(200) |
176 |
->status_is(200) |
205 |
->json_has('/0') |
177 |
->json_has('/0') |
206 |
->json_hasnt('/1') |
178 |
->json_hasnt('/1') |
207 |
->json_is('/0/city_name' => 'Manuel'); |
179 |
->json_is('/0/city_name' => 'Manuel'); |
208 |
|
180 |
|
209 |
# _match=contains |
181 |
# _match=contains |
210 |
$t->get_ok('/cities_to_model?nombre=manuel&_per_page=3&_page=1&_match=contains') |
182 |
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=contains') |
211 |
->status_is(200) |
|
|
212 |
->json_has('/0') |
213 |
->json_has('/1') |
214 |
->json_has('/2') |
215 |
->json_hasnt('/3') |
216 |
->json_is('/0/city_name' => 'Manuel') |
217 |
->json_is('/1/city_name' => 'Manuela') |
218 |
->json_is('/2/city_name' => 'Emanuel'); |
219 |
|
220 |
## _to_model && _to_api tests |
221 |
# _match=starts_with |
222 |
$t->get_ok('/cities_to_model_to_api?nombre=manuel&_per_page=3&_page=1&_match=starts_with') |
223 |
->status_is(200) |
224 |
->json_has('/0') |
225 |
->json_has('/1') |
226 |
->json_hasnt('/2') |
227 |
->json_is('/0/nombre' => 'Manuel') |
228 |
->json_is('/1/nombre' => 'Manuela'); |
229 |
|
230 |
# _match=ends_with |
231 |
$t->get_ok('/cities_to_model_to_api?nombre=manuel&_per_page=3&_page=1&_match=ends_with') |
232 |
->status_is(200) |
233 |
->json_has('/0') |
234 |
->json_has('/1') |
235 |
->json_hasnt('/2') |
236 |
->json_is('/0/nombre' => 'Manuel') |
237 |
->json_is('/1/nombre' => 'Emanuel'); |
238 |
|
239 |
# _match=exact |
240 |
$t->get_ok('/cities_to_model_to_api?nombre=manuel&_per_page=3&_page=1&_match=exact') |
241 |
->status_is(200) |
242 |
->json_has('/0') |
243 |
->json_hasnt('/1') |
244 |
->json_is('/0/nombre' => 'Manuel'); |
245 |
|
246 |
# _match=contains |
247 |
$t->get_ok('/cities_to_model_to_api?nombre=manuel&_per_page=3&_page=1&_match=contains') |
248 |
->status_is(200) |
183 |
->status_is(200) |
249 |
->json_has('/0') |
184 |
->json_has('/0') |
250 |
->json_has('/1') |
185 |
->json_has('/1') |
251 |
->json_has('/2') |
186 |
->json_has('/2') |
252 |
->json_hasnt('/3') |
187 |
->json_has('/3') |
253 |
->json_is('/0/nombre' => 'Manuel') |
188 |
->json_hasnt('/4') |
254 |
->json_is('/1/nombre' => 'Manuela') |
189 |
->json_is('/0/name' => 'Manuel') |
255 |
->json_is('/2/nombre' => 'Emanuel'); |
190 |
->json_is('/1/name' => 'Manuela') |
|
|
191 |
->json_is('/2/name' => 'Manuelab') |
192 |
->json_is('/3/name' => 'Emanuel'); |
256 |
|
193 |
|
257 |
$schema->storage->txn_rollback; |
194 |
$schema->storage->txn_rollback; |
258 |
}; |
195 |
}; |