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

(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-2 / +42 lines)
Lines 50-55 get '/cities_to_model_to_api' => sub { Link Here
50
    $c->render( status => 200, json => $cities );
50
    $c->render( status => 200, json => $cities );
51
};
51
};
52
52
53
get '/cities_sorted' => sub {
54
    my $c = shift;
55
    $c->validation->output($c->req->params->to_hash);
56
    my $cities_set = Koha::Cities->new;
57
    my $cities = $c->objects->search( $cities_set, \&to_model, \&to_api );
58
    $c->render( status => 200, json => $cities );
59
};
60
53
sub to_model {
61
sub to_model {
54
    my $params = shift;
62
    my $params = shift;
55
63
Lines 71-77 sub to_api { Link Here
71
}
79
}
72
80
73
# The tests
81
# The tests
74
use Test::More tests => 1;
82
use Test::More tests => 2;
75
use Test::Mojo;
83
use Test::Mojo;
76
84
77
use t::lib::TestBuilder;
85
use t::lib::TestBuilder;
Lines 233-235 subtest 'objects.search helper' => sub { Link Here
233
241
234
    $schema->storage->txn_rollback;
242
    $schema->storage->txn_rollback;
235
};
243
};
236
- 
244
245
subtest 'objects.search helper, sorting on mapped column' => sub {
246
247
    plan tests => 14;
248
249
    my $t = Test::Mojo->new;
250
251
    $schema->storage->txn_begin;
252
253
    # Have complete control over the existing cities to ease testing
254
    Koha::Cities->delete;
255
256
    $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'A', city_country => 'Argentina' } });
257
    $builder->build_object({ class => 'Koha::Cities', value => { city_name => 'B', city_country => 'Argentina' } });
258
259
    $t->get_ok('/cities_sorted?_order_by=%2Bnombre&_order_by=+city_country')
260
      ->status_is(200)
261
      ->json_has('/0')
262
      ->json_has('/1')
263
      ->json_hasnt('/2')
264
      ->json_is('/0/nombre' => 'A')
265
      ->json_is('/1/nombre' => 'B');
266
267
    $t->get_ok('/cities_sorted?_order_by=-nombre')
268
      ->status_is(200)
269
      ->json_has('/0')
270
      ->json_has('/1')
271
      ->json_hasnt('/2')
272
      ->json_is('/0/nombre' => 'B')
273
      ->json_is('/1/nombre' => 'A');
274
275
    $schema->storage->txn_rollback;
276
}

Return to bug 24191