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

(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-2 / +55 lines)
Lines 34-39 get '/patrons' => sub { Link Here
34
    $c->render( status => 200, json => $patrons );
34
    $c->render( status => 200, json => $patrons );
35
};
35
};
36
36
37
get '/patrons_to_model' => sub {
38
    my $c = shift;
39
    $c->validation->output($c->req->params->to_hash);
40
    my $patrons_set = Koha::Patrons->new;
41
    my $patrons = $c->objects->search( $patrons_set, \&_to_model );
42
    $c->render( status => 200, json => $patrons );
43
};
44
45
sub _to_model {
46
    my $params = shift;
47
48
    if ( exists $params->{nombre} ) {
49
        $params->{firstname} = delete $params->{nombre};
50
    }
51
52
    return $params;
53
}
37
54
38
# The tests
55
# The tests
39
use Test::More tests => 1;
56
use Test::More tests => 1;
Lines 49-55 my $builder = t::lib::TestBuilder->new; Link Here
49
66
50
subtest 'objects.search helper' => sub {
67
subtest 'objects.search helper' => sub {
51
68
52
    plan tests => 34;
69
    plan tests => 62;
53
70
54
    my $t = Test::Mojo->new;
71
    my $t = Test::Mojo->new;
55
72
Lines 121-125 subtest 'objects.search helper' => sub { Link Here
121
        ->json_is('/1/firstname' => 'Manuela')
138
        ->json_is('/1/firstname' => 'Manuela')
122
        ->json_is('/2/firstname' => 'Emanuel');
139
        ->json_is('/2/firstname' => 'Emanuel');
123
140
141
    ## _to_model tests
142
    # _match=starts_with
143
    $t->get_ok('/patrons_to_model?nombre=manuel&_per_page=3&_page=1&_match=starts_with')
144
        ->status_is(200)
145
        ->json_has('/0')
146
        ->json_has('/1')
147
        ->json_hasnt('/2')
148
        ->json_is('/0/firstname' => 'Manuel')
149
        ->json_is('/1/firstname' => 'Manuela');
150
151
    # _match=ends_with
152
    $t->get_ok('/patrons_to_model?nombre=manuel&_per_page=3&_page=1&_match=ends_with')
153
        ->status_is(200)
154
        ->json_has('/0')
155
        ->json_has('/1')
156
        ->json_hasnt('/2')
157
        ->json_is('/0/firstname' => 'Manuel')
158
        ->json_is('/1/firstname' => 'Emanuel');
159
160
    # _match=exact
161
    $t->get_ok('/patrons_to_model?nombre=manuel&_per_page=3&_page=1&_match=exact')
162
        ->status_is(200)
163
        ->json_has('/0')
164
        ->json_hasnt('/1')
165
        ->json_is('/0/firstname' => 'Manuel');
166
167
    # _match=contains
168
    $t->get_ok('/patrons_to_model?nombre=manuel&_per_page=3&_page=1&_match=contains')
169
        ->status_is(200)
170
        ->json_has('/0')
171
        ->json_has('/1')
172
        ->json_has('/2')
173
        ->json_hasnt('/3')
174
        ->json_is('/0/firstname' => 'Manuel')
175
        ->json_is('/1/firstname' => 'Manuela')
176
        ->json_is('/2/firstname' => 'Emanuel');
177
124
    $schema->storage->txn_rollback;
178
    $schema->storage->txn_rollback;
125
};
179
};
126
- 

Return to bug 19686