|
Lines 73-79
get '/dbic_merge_sorting' => sub {
Link Here
|
| 73 |
$attributes = $c->dbic_merge_sorting( |
73 |
$attributes = $c->dbic_merge_sorting( |
| 74 |
{ |
74 |
{ |
| 75 |
attributes => $attributes, |
75 |
attributes => $attributes, |
| 76 |
params => { _match => 'exact', _order_by => 'uno|-dos|+tres' } |
76 |
params => { _match => 'exact', _order_by => [ 'uno', '-dos', '+tres', ' cuatro' ] } |
| 77 |
} |
77 |
} |
| 78 |
); |
78 |
); |
| 79 |
$c->render( json => $attributes, status => 200 ); |
79 |
$c->render( json => $attributes, status => 200 ); |
|
Lines 117-125
subtest 'dbic_merge_sorting() tests' => sub {
Link Here
|
| 117 |
|
117 |
|
| 118 |
my $t = Test::Mojo->new; |
118 |
my $t = Test::Mojo->new; |
| 119 |
|
119 |
|
| 120 |
$t->get_ok('/dbic_merge_sorting') |
120 |
$t->get_ok('/dbic_merge_sorting')->status_is(200) |
| 121 |
->status_is(200) |
|
|
| 122 |
->json_is( '/a' => 'a', 'Existing values are kept (a)' ) |
121 |
->json_is( '/a' => 'a', 'Existing values are kept (a)' ) |
| 123 |
->json_is( '/b' => 'b', 'Existing values are kept (b)' ) |
122 |
->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is( |
| 124 |
->json_is( '/order_by' => [ 'uno', { -desc => 'dos' }, { -asc => 'tres' } ] ); |
123 |
'/order_by' => [ |
|
|
124 |
'uno', |
| 125 |
{ -desc => 'dos' }, |
| 126 |
{ -asc => 'tres' }, |
| 127 |
{ -asc => 'cuatro' } |
| 128 |
] |
| 129 |
); |
| 130 |
}; |
| 131 |
|
| 132 |
subtest '_build_query_params_from_api' => sub { |
| 133 |
|
| 134 |
plan tests => 16; |
| 135 |
|
| 136 |
my $t = Test::Mojo->new; |
| 137 |
|
| 138 |
# _match => contains |
| 139 |
$t->get_ok('/build_query?_match=contains&title=Ender&author=Orson') |
| 140 |
->status_is(200) |
| 141 |
->json_is( '/query' => |
| 142 |
{ author => { like => '%Orson%' }, title => { like => '%Ender%' } } ); |
| 143 |
|
| 144 |
# _match => starts_with |
| 145 |
$t->get_ok('/build_query?_match=starts_with&title=Ender&author=Orson') |
| 146 |
->status_is(200) |
| 147 |
->json_is( '/query' => |
| 148 |
{ author => { like => 'Orson%' }, title => { like => 'Ender%' } } ); |
| 149 |
|
| 150 |
# _match => ends_with |
| 151 |
$t->get_ok('/build_query?_match=ends_with&title=Ender&author=Orson') |
| 152 |
->status_is(200) |
| 153 |
->json_is( '/query' => |
| 154 |
{ author => { like => '%Orson' }, title => { like => '%Ender' } } ); |
| 155 |
|
| 156 |
# _match => exact |
| 157 |
$t->get_ok('/build_query?_match=exact&title=Ender&author=Orson') |
| 158 |
->status_is(200) |
| 159 |
->json_is( '/query' => { author => 'Orson', title => 'Ender' } ); |
| 160 |
|
| 161 |
# _match => blah |
| 162 |
$t->get_ok('/build_query?_match=blah&title=Ender&author=Orson') |
| 163 |
->status_is(400) |
| 164 |
->json_is( '/exception_msg' => 'Invalid value for _match param (blah)' ) |
| 165 |
->json_is( '/exception_type' => 'Koha::Exceptions::WrongParameter' ); |
| 166 |
|
| 125 |
}; |
167 |
}; |
| 126 |
- |
|
|