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

(-)a/t/db_dependent/api/v1/query.t (-3 / +68 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::NoWarnings;
20
use Test::NoWarnings;
21
use Test::More tests => 4;
21
use Test::More tests => 5;
22
use Test::Mojo;
22
use Test::Mojo;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
Lines 27-32 use t::lib::Mocks; Link Here
27
use Koha::Cities;
27
use Koha::Cities;
28
use Koha::Database;
28
use Koha::Database;
29
29
30
use JSON qw(encode_json);
31
30
my $schema  = Koha::Database->new->schema;
32
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
33
my $builder = t::lib::TestBuilder->new;
32
34
Lines 97-102 subtest 'q handling tests' => sub { Link Here
97
    $schema->storage->txn_rollback;
99
    $schema->storage->txn_rollback;
98
};
100
};
99
101
102
subtest 'q in body handling tests' => sub {
103
104
    plan tests => 15;
105
106
    $schema->storage->txn_begin;
107
108
    my $librarian = $builder->build_object(
109
        {
110
            class => 'Koha::Patrons',
111
            value => { flags => 2**2 }    # catalogue flag = 2
112
        }
113
    );
114
    my $password = 'thePassword123';
115
    $librarian->set_password( { password => $password, skip_validation => 1 } );
116
    my $userid = $librarian->userid;
117
118
    # delete all cities
119
    Koha::Cities->new->delete;
120
121
    # No cities, so empty array should be returned
122
    $t->get_ok("//$userid:$password@/api/v1/cities")->status_is(200)->json_is( [] );
123
124
    my $names = [ 'AA', 'BA', 'BA', 'CA', 'DA', 'EB', 'FB', 'GB', 'HB', 'IB', ];
125
126
    # Add 10 cities
127
    foreach my $i ( 0 .. 9 ) {
128
        $builder->build_object( { class => 'Koha::Cities', value => { city_name => $names->[$i] } } );
129
    }
130
131
    t::lib::Mocks::mock_preference( 'RESTdefaultPageSize', 20 );
132
133
    my $q_ends_with_a     = { "name" => { "-like" => '%A' } };
134
    my $q_ends_with_a_str = encode_json($q_ends_with_a);
135
136
    my $cities =
137
        $t->get_ok( "//$userid:$password@/api/v1/cities" => json => $q_ends_with_a )->status_is(200)->tx->res->json;
138
139
    is( scalar @{$cities}, 5, '5 cities retrieved' );
140
141
    my $q_starts_with_a     = { "name" => { "-like" => 'A%' } };
142
    my $q_starts_with_a_str = encode_json($q_starts_with_a);
143
144
    $cities =
145
        $t->get_ok( "//$userid:$password@/api/v1/cities?q=$q_starts_with_a_str" => json => $q_ends_with_a )
146
        ->status_is(200)->tx->res->json;
147
148
    is( scalar @{$cities}, 1, 'Mixing query parameter and body, 1 city retrieved' );
149
150
    $cities =
151
        $t->get_ok( "//$userid:$password@/api/v1/cities?q=$q_ends_with_a_str" => json => $q_starts_with_a )
152
        ->status_is(200)->tx->res->json;
153
154
    is( scalar @{$cities}, 1, 'Mixing query parameter and body (flipped), 1 city retrieved' );
155
156
    $cities =
157
        $t->get_ok( "//$userid:$password@/api/v1/cities" => json => { "-and" => [ $q_ends_with_a, $q_starts_with_a ] } )
158
        ->status_is(200)->tx->res->json;
159
160
    is( scalar @{$cities}, 1, 'Body query is passed through, 1 city retrieved' );
161
162
    $schema->storage->txn_rollback;
163
};
164
100
subtest 'x-koha-embed tests' => sub {
165
subtest 'x-koha-embed tests' => sub {
101
166
102
    plan tests => 8;
167
    plan tests => 8;
Lines 123-129 subtest 'x-koha-embed tests' => sub { Link Here
123
    $res = $t->get_ok( "//$userid:$password@/api/v1/patrons?q={\"me.patron_id\":$patron_id}" =>
188
    $res = $t->get_ok( "//$userid:$password@/api/v1/patrons?q={\"me.patron_id\":$patron_id}" =>
124
            { 'x-koha-embed' => 'extended_attributes,custom_bad_embed,another_bad_embed' } )->status_is(400);
189
            { 'x-koha-embed' => 'extended_attributes,custom_bad_embed,another_bad_embed' } )->status_is(400);
125
190
126
    $res = $t->get_ok( "//$userid:$password@/api/v1/cities" => { 'x-koha-embed' => 'any_embed' } )->status_is(400)
191
    $res =
192
        $t->get_ok( "//$userid:$password@/api/v1/cities" => { 'x-koha-embed' => 'any_embed' } )->status_is(400)
127
        ->tx->res->json;
193
        ->tx->res->json;
128
194
129
    is( $res, 'Embedding objects is not allowed on this endpoint.', 'Correct error message is returned' );
195
    is( $res, 'Embedding objects is not allowed on this endpoint.', 'Correct error message is returned' );
130
- 

Return to bug 40424