From d1a362648fa580fcbe0b910e435842d0570205fd Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 10 Dec 2021 10:15:42 -0300 Subject: [PATCH] Bug 29464: Regression tests --- t/db_dependent/api/v1/acquisitions_orders.t | 59 ++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/acquisitions_orders.t b/t/db_dependent/api/v1/acquisitions_orders.t index 9c806a53cc..398f918b97 100755 --- a/t/db_dependent/api/v1/acquisitions_orders.t +++ b/t/db_dependent/api/v1/acquisitions_orders.t @@ -37,7 +37,8 @@ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); my $t = Test::Mojo->new('Koha::REST::V1'); subtest 'list() tests' => sub { - plan tests => 18; + + plan tests => 19; $schema->storage->txn_begin; @@ -134,6 +135,62 @@ subtest 'list() tests' => sub { ->status_is(400) ->json_is( [{ path => '/query/order_blah', message => 'Malformed query string'}] ); + subtest 'sorting tests' => sub { + + plan tests => 10; + + $schema->storage->txn_begin; + + my $biblio_1 = $builder->build_sample_biblio(); + my $biblio_2 = $builder->build_sample_biblio(); + + my $basket = $builder->build_object({ class => 'Koha::Acquisition::Baskets', value => { is_standing => 1 } }); + my $order_1 = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + basketno => $basket->basketno, + orderstatus => 'new', + biblionumber => $biblio_1->biblionumber + } + } + ); + my $order_2 = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + basketno => $basket->basketno, + orderstatus => 'new', + biblionumber => $biblio_2->biblionumber + } + } + ); + + # order by order_id + my $result = + $t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?_order_by=+me.order_id&basket_id=" . $basket->id ) + ->status_is( 200, "query successful" ) + ->tx->res->json; + + is( scalar @$result, 2, 'Two elements returned' ); + + is( $result->[0]->{order_id}, $order_1->id, 'The first element is order_1' ); + is( $result->[1]->{order_id}, $order_2->id, 'The second element is order_2' ); + + # now reverse order + $result = + $t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?_order_by=-me.order_id&basket_id=" . $basket->id ) + ->status_is( 200, "query successful" ) + ->tx->res->json; + + is( scalar @$result, 2, 'Two elements returned' ); + + is( $result->[0]->{order_id}, $order_2->id, 'The first element is order_2' ); + is( $result->[1]->{order_id}, $order_1->id, 'The second element is order_1' ); + + $schema->storage->txn_rollback; + }; + $schema->storage->txn_rollback; }; -- 2.34.1