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

(-)a/t/Koha/REST/Plugin/Query.t (-2 / +53 lines)
Lines 206-211 get '/build_query' => sub { Link Here
206
    };
206
    };
207
};
207
};
208
208
209
get '/dbic_validate_operators' => sub {
210
    my ( $c, $args ) = @_;
211
212
    my $query = $c->req->json->{q};
213
214
    return try {
215
        $c->dbic_validate_operators( { filtered_params => $query } );
216
        $c->render( json => { filtered_params => $query }, status => 200 );
217
    } catch {
218
        return $c->render( json => { filtered_params => $query }, status => 400 );
219
    };
220
};
221
209
get '/stash_embed' => sub {
222
get '/stash_embed' => sub {
210
    my $c = shift;
223
    my $c = shift;
211
224
Lines 337-343 sub to_model { Link Here
337
350
338
# The tests
351
# The tests
339
352
340
use Test::More tests => 8;
353
use Test::More tests => 9;
341
use Test::Mojo;
354
use Test::Mojo;
342
355
343
subtest 'extract_reserved_params() tests' => sub {
356
subtest 'extract_reserved_params() tests' => sub {
Lines 634-636 subtest 'dbic_extended_attributes_join() tests' => sub { Link Here
634
        ]
647
        ]
635
    );
648
    );
636
};
649
};
637
- 
650
651
subtest 'dbic_validate_operators' => sub {
652
    plan tests => 16;
653
654
    my $t = Test::Mojo->new;
655
656
    # Valid queries
657
    my $q = {};
658
    $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(200);
659
660
    $q = [];
661
    $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(200);
662
663
    $q = {
664
        firstname => 'Bilbo',
665
        lastname  => 'Baggins'
666
    };
667
    $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(200);
668
669
    $q = {
670
        firstname => undef,
671
        lastname  => 'Baggins'
672
    };
673
    $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(200);
674
675
    $q = { lastname => [ 'Gaggins', 'Gamgee' ] };
676
    $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(200);
677
678
    $q = { lastname => { '!=' => [ 'Gaggins', 'Gamgee' ] } };
679
    $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(200);
680
681
    $q = { status => { '!=', 'completed', -not_like => 'pending%' } };
682
    $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(200);
683
684
    # Invalid queries
685
    $q = [ { "-and" => [ [ { "biblio_id" => { "like(sleep(1/100000))or" => "%a%" } } ] ] } ];
686
    $t->get_ok( '/dbic_validate_operators' => json => { q => $q } )->status_is(400);
687
688
};

Return to bug 37018