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

(-)a/t/db_dependent/api/v1/authorised_values.t (-2 / +35 lines)
Lines 26-31 use t::lib::Mocks; Link Here
26
use Koha::AuthorisedValues;
26
use Koha::AuthorisedValues;
27
use Koha::Database;
27
use Koha::Database;
28
28
29
use JSON qw( encode_json );
30
29
my $schema  = Koha::Database->new->schema;
31
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
32
my $builder = t::lib::TestBuilder->new;
31
33
Lines 34-40 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); Link Here
34
36
35
subtest 'list_av_from_category() tests' => sub {
37
subtest 'list_av_from_category() tests' => sub {
36
38
37
    plan tests => 11;
39
    plan tests => 22;
38
40
39
    $schema->storage->txn_begin;
41
    $schema->storage->txn_begin;
40
42
Lines 83-87 subtest 'list_av_from_category() tests' => sub { Link Here
83
    $t->get_ok("//$unauth_userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")
85
    $t->get_ok("//$unauth_userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")
84
      ->status_is(403);
86
      ->status_is(403);
85
87
88
    # Test the query webservice endpoint for multiple av_cats
89
    my $av_cat_2 =
90
        $builder->build_object( { class => 'Koha::AuthorisedValueCategories', value => { category_name => 'cat_a' } } );
91
    my $av_cat_3 =
92
        $builder->build_object( { class => 'Koha::AuthorisedValueCategories', value => { category_name => 'cat_b' } } );
93
    my $query = { "me.category_name" => [ $av_cat_2->category_name, $av_cat_3->category_name ] };
94
    $t->get_ok( "//$userid:$password@/api/v1/authorised_value_categories?q=" . encode_json($query) )->status_is(200)
95
        ->json_is( [ $av_cat_2->to_api, $av_cat_3->to_api ] );
96
97
    # Test the above but with x-koha-embed: authorised_values
98
    my $embedded_query = { "me.category_name" => [ $av_cat_2->category_name, $av_cat_3->category_name ] };
99
    $t->get_ok( "//$userid:$password@/api/v1/authorised_value_categories?q="
100
            . encode_json($embedded_query) => { 'x-koha-embed' => 'authorised_values' } )->status_is(200)
101
        ->json_has( '/0/authorised_values', 'authorised_values object correctly embedded' )
102
        ->json_has( '/1/authorised_values', 'authorised_values object correctly embedded' )
103
        ->json_hasnt( '/2/', 'authorised_values object correctly embedded' );
104
105
    # Test the query webservice endpoint for multiple av_cats with authorised_values embedded
106
    my $av_2 = $builder->build_object(
107
        { class => 'Koha::AuthorisedValues', value => { category => $av_cat_2->category_name, lib => undef } } );
108
    my $av_3 = $builder->build_object(
109
        {
110
            class => 'Koha::AuthorisedValues',
111
            value => { category => $av_cat_2->category_name, lib => 'description_value' }
112
        }
113
    );
114
115
    my $embedded_av_query = { "me.category_name" => [ $av_cat_2->category_name ] };
116
    $t->get_ok( "//$userid:$password@/api/v1/authorised_value_categories?q="
117
            . encode_json($embedded_av_query) => { 'x-koha-embed' => 'authorised_values' } )->status_is(200)
118
        ->json_is( [ { %{ $av_cat_2->to_api }, authorised_values => [ $av_2->to_api, $av_3->to_api ] } ] );
119
86
    $schema->storage->txn_rollback;
120
    $schema->storage->txn_rollback;
87
};
121
};
88
- 

Return to bug 34920