Lines 37-43
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
Link Here
|
37 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
37 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
38 |
|
38 |
|
39 |
subtest 'list() tests' => sub { |
39 |
subtest 'list() tests' => sub { |
40 |
plan tests => 18; |
40 |
|
|
|
41 |
plan tests => 19; |
41 |
|
42 |
|
42 |
$schema->storage->txn_begin; |
43 |
$schema->storage->txn_begin; |
43 |
|
44 |
|
Lines 134-139
subtest 'list() tests' => sub {
Link Here
|
134 |
->status_is(400) |
135 |
->status_is(400) |
135 |
->json_is( [{ path => '/query/order_blah', message => 'Malformed query string'}] ); |
136 |
->json_is( [{ path => '/query/order_blah', message => 'Malformed query string'}] ); |
136 |
|
137 |
|
|
|
138 |
subtest 'sorting tests' => sub { |
139 |
|
140 |
plan tests => 10; |
141 |
|
142 |
$schema->storage->txn_begin; |
143 |
|
144 |
my $biblio_1 = $builder->build_sample_biblio(); |
145 |
my $biblio_2 = $builder->build_sample_biblio(); |
146 |
|
147 |
my $basket = $builder->build_object({ class => 'Koha::Acquisition::Baskets', value => { is_standing => 1 } }); |
148 |
my $order_1 = $builder->build_object( |
149 |
{ |
150 |
class => 'Koha::Acquisition::Orders', |
151 |
value => { |
152 |
basketno => $basket->basketno, |
153 |
orderstatus => 'new', |
154 |
biblionumber => $biblio_1->biblionumber |
155 |
} |
156 |
} |
157 |
); |
158 |
my $order_2 = $builder->build_object( |
159 |
{ |
160 |
class => 'Koha::Acquisition::Orders', |
161 |
value => { |
162 |
basketno => $basket->basketno, |
163 |
orderstatus => 'new', |
164 |
biblionumber => $biblio_2->biblionumber |
165 |
} |
166 |
} |
167 |
); |
168 |
|
169 |
# order by order_id |
170 |
my $result = |
171 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?_order_by=+me.order_id&basket_id=" . $basket->id ) |
172 |
->status_is( 200, "query successful" ) |
173 |
->tx->res->json; |
174 |
|
175 |
is( scalar @$result, 2, 'Two elements returned' ); |
176 |
|
177 |
is( $result->[0]->{order_id}, $order_1->id, 'The first element is order_1' ); |
178 |
is( $result->[1]->{order_id}, $order_2->id, 'The second element is order_2' ); |
179 |
|
180 |
# now reverse order |
181 |
$result = |
182 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?_order_by=-me.order_id&basket_id=" . $basket->id ) |
183 |
->status_is( 200, "query successful" ) |
184 |
->tx->res->json; |
185 |
|
186 |
is( scalar @$result, 2, 'Two elements returned' ); |
187 |
|
188 |
is( $result->[0]->{order_id}, $order_2->id, 'The first element is order_2' ); |
189 |
is( $result->[1]->{order_id}, $order_1->id, 'The second element is order_1' ); |
190 |
|
191 |
$schema->storage->txn_rollback; |
192 |
}; |
193 |
|
137 |
$schema->storage->txn_rollback; |
194 |
$schema->storage->txn_rollback; |
138 |
}; |
195 |
}; |
139 |
|
196 |
|
140 |
- |
|
|