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

(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-2 / +105 lines)
Lines 40-45 get '/cities' => sub { Link Here
40
    $c->render( status => 200, json => $cities );
40
    $c->render( status => 200, json => $cities );
41
};
41
};
42
42
43
get '/cities/:city_id' => sub {
44
    my $c = shift;
45
    my $id = $c->stash("city_id");
46
    my $city = $c->objects->find(Koha::Cities->new, $id);
47
    $c->render( status => 200, json => $city );
48
};
49
43
get '/orders' => sub {
50
get '/orders' => sub {
44
    my $c = shift;
51
    my $c = shift;
45
    $c->stash('koha.embed', ( { fund => {} } ) );
52
    $c->stash('koha.embed', ( { fund => {} } ) );
Lines 48-53 get '/orders' => sub { Link Here
48
    $c->render( status => 200, json => $orders );
55
    $c->render( status => 200, json => $orders );
49
};
56
};
50
57
58
get '/orders/:order_id' => sub {
59
    my $c = shift;
60
    $c->stash('koha.embed', ( { fund => {} } ) );
61
    my $id = $c->stash("order_id");
62
    my $order = $c->objects->find(Koha::Acquisition::Orders->new, $id);
63
    $c->render( status => 200, json => $order );
64
};
65
51
get '/patrons/:patron_id/holds' => sub {
66
get '/patrons/:patron_id/holds' => sub {
52
    my $c = shift;
67
    my $c = shift;
53
    my $params = $c->req->params->to_hash;
68
    my $params = $c->req->params->to_hash;
Lines 79-85 get '/biblios' => sub { Link Here
79
94
80
95
81
# The tests
96
# The tests
82
use Test::More tests => 11;
97
use Test::More tests => 14;
83
use Test::Mojo;
98
use Test::Mojo;
84
99
85
use t::lib::Mocks;
100
use t::lib::Mocks;
Lines 209-214 subtest 'objects.search helper' => sub { Link Here
209
    $schema->storage->txn_rollback;
224
    $schema->storage->txn_rollback;
210
};
225
};
211
226
227
subtest 'objects.find helper' => sub {
228
  plan tests => 6;
229
230
  $schema->storage->txn_begin;
231
232
  Koha::Cities->delete;
233
234
  my $city1 = $builder->build_object({ class => 'Koha::Cities' });
235
  my $city2 = $builder->build_object({ class => 'Koha::Cities' });
236
237
  $t->get_ok('/cities/'.$city1->cityid)
238
    ->status_is(200)
239
    ->json_is('/name' => $city1->city_name);
240
241
  $t->get_ok('/cities/'.$city2->cityid)
242
    ->status_is(200)
243
    ->json_is('/name' => $city2->city_name);
244
245
  $schema->storage->txn_rollback;
246
247
};
248
212
subtest 'objects.search helper, sorting on mapped column' => sub {
249
subtest 'objects.search helper, sorting on mapped column' => sub {
213
250
214
    plan tests => 14;
251
    plan tests => 14;
Lines 274-279 subtest 'objects.search helper, embed' => sub { Link Here
274
    $schema->storage->txn_rollback;
311
    $schema->storage->txn_rollback;
275
};
312
};
276
313
314
subtest 'objects.find helper, embed' => sub {
315
316
    plan tests => 2;
317
318
    $schema->storage->txn_begin;
319
320
    my $order = $builder->build_object({ class => 'Koha::Acquisition::Orders' });
321
322
    $t->get_ok('/orders/' . $order->ordernumber)
323
      ->json_is('',$order->to_api({ embed => ( { fund => {} } ) }));
324
325
    $schema->storage->txn_rollback;
326
};
327
277
subtest 'objects.search helper, with path parameters and _match' => sub {
328
subtest 'objects.search helper, with path parameters and _match' => sub {
278
    plan tests => 8;
329
    plan tests => 8;
279
330
Lines 471-475 subtest 'objects.search helper with expanded authorised values' => sub { Link Here
471
        ->json_has('/1/_authorised_values')
522
        ->json_has('/1/_authorised_values')
472
        ->json_is('/1/_authorised_values/country/lib' => $us->lib);
523
        ->json_is('/1/_authorised_values/country/lib' => $us->lib);
473
524
525
    $schema->storage->txn_rollback;
526
};
527
528
subtest 'objects.find helper with expanded authorised values' => sub {
529
    plan tests => 10;
530
531
    $schema->storage->txn_begin;
532
533
    Koha::AuthorisedValues->search({category => 'Countries'})->delete;
534
    Koha::AuthorisedValueCategories->search({category_name =>'Countries'})->delete;
535
536
    my $cat = $builder->build_object({ class => 'Koha::AuthorisedValueCategories', value => {category_name =>'Countries'} });
537
    my $fr = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'FR', lib=>'France', category=>$cat->category_name} });
538
    my $us = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'US', lib=>'United States of America', category=>$cat->category_name} });
539
    my $ar = $builder->build_object({ class => 'Koha::AuthorisedValues', value => {authorised_value => 'AR', lib=>'Argentina', category=>$cat->category_name} });
540
541
    my $city_class = Test::MockModule->new('Koha::City');
542
    $city_class->mock( '_fetch_authorised_values',
543
        sub {
544
            my ($self) = @_;
545
            use Koha::AuthorisedValues;
546
            my $av = Koha::AuthorisedValues->find({authorised_value => $self->city_country, category => 'Countries'});
547
            return {country => $av->unblessed};
548
        }
549
    );
550
551
    my $manuel = $builder->build_object({
552
        class => 'Koha::Cities',
553
        value => {
554
            city_name => 'Manuel',
555
            city_country => 'AR'
556
        }
557
    });
558
    my $manuela = $builder->build_object({
559
        class => 'Koha::Cities',
560
        value => {
561
            city_name => 'Manuela',
562
            city_country => 'US'
563
        }
564
    });
565
566
    $t->get_ok('/cities/'.$manuel->cityid => { 'x-koha-av' => 1 })
567
        ->status_is(200)
568
        ->json_is('/name' => 'Manuel')
569
        ->json_has('/_authorised_values')
570
        ->json_is('/_authorised_values/country/lib' => $ar->lib);
571
572
    $t->get_ok('/cities/'.$manuela->cityid => { 'x-koha-av' => 1 })
573
        ->status_is(200)
574
        ->json_is('/name' => 'Manuela')
575
        ->json_has('/_authorised_values')
576
        ->json_is('/_authorised_values/country/lib' => $us->lib);
577
474
    $schema->storage->txn_rollback;
578
    $schema->storage->txn_rollback;
475
};
579
};
476
- 

Return to bug 26636