Lines 24-29
use Test::Warn;
Link Here
|
24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
25 |
use t::lib::Mocks; |
25 |
use t::lib::Mocks; |
26 |
|
26 |
|
|
|
27 |
use JSON qw( encode_json ); |
28 |
|
27 |
use Koha::Acquisition::Orders; |
29 |
use Koha::Acquisition::Orders; |
28 |
use Koha::Database; |
30 |
use Koha::Database; |
29 |
|
31 |
|
Lines 35-41
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
Link Here
|
35 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
37 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
36 |
|
38 |
|
37 |
subtest 'list() tests' => sub { |
39 |
subtest 'list() tests' => sub { |
38 |
plan tests => 8; |
40 |
plan tests => 18; |
39 |
|
41 |
|
40 |
$schema->storage->txn_begin; |
42 |
$schema->storage->txn_begin; |
41 |
|
43 |
|
Lines 48-58
subtest 'list() tests' => sub {
Link Here
|
48 |
my $userid = $patron->userid; |
50 |
my $userid = $patron->userid; |
49 |
|
51 |
|
50 |
my $basket = $builder->build_object({ class => 'Koha::Acquisition::Baskets' }); |
52 |
my $basket = $builder->build_object({ class => 'Koha::Acquisition::Baskets' }); |
|
|
53 |
|
54 |
my $biblio = $builder->build_sample_biblio; |
55 |
my $biblioitem = $biblio->biblioitem; |
56 |
$biblioitem->set({ isbn => 'SOMETHING' })->store; |
57 |
|
51 |
# Create test context |
58 |
# Create test context |
52 |
my $order = $builder->build_object( |
59 |
my $order = $builder->build_object( |
53 |
{ |
60 |
{ |
54 |
class => 'Koha::Acquisition::Orders', |
61 |
class => 'Koha::Acquisition::Orders', |
55 |
value => { basketno => $basket->basketno, orderstatus => 'new' } |
62 |
value => { |
|
|
63 |
basketno => $basket->basketno, |
64 |
orderstatus => 'new', |
65 |
biblionumber => $biblio->biblionumber |
66 |
} |
56 |
} |
67 |
} |
57 |
); |
68 |
); |
58 |
my $another_order = $order->unblessed; # create a copy of $order but make |
69 |
my $another_order = $order->unblessed; # create a copy of $order but make |
Lines 98-103
subtest 'list() tests' => sub {
Link Here
|
98 |
} |
109 |
} |
99 |
}; |
110 |
}; |
100 |
|
111 |
|
|
|
112 |
my $query = { "biblio.isbn" => { "-like" => "\%SOMETHING\%" } }; |
113 |
|
114 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?q=" . encode_json($query) => {'x-koha-embed' => 'biblio'} ) |
115 |
->status_is( 200, "Embeddig biblio.isbn doesn't make it explode" ) |
116 |
->json_has( "/0/biblio", "biblio object correctly embedded" ) |
117 |
->json_is( "/0/biblio/isbn", 'SOMETHING', 'Filtering by a biblioitems column works!' ); |
118 |
|
119 |
my $result = $t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?biblio_id=" . $biblio->biblionumber ) |
120 |
->status_is( 200 ); |
121 |
|
122 |
is( scalar @{ $result->tx->res->json}, 2, 'Two orders fetched' ); |
123 |
|
124 |
# Mark $another_order as cancelled |
125 |
$another_order->set({ orderstatus => 'cancelled' })->store; |
126 |
|
127 |
$result = $t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?only_active=1&biblio_id=" . $biblio->biblionumber ) |
128 |
->status_is( 200, "only_active parameter accepted" ); |
129 |
|
130 |
is( scalar @{ $result->tx->res->json}, 1, 'Only one order is active' ); |
131 |
|
101 |
# Warn on unsupported query parameter |
132 |
# Warn on unsupported query parameter |
102 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?order_blah=blah" ) |
133 |
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders?order_blah=blah" ) |
103 |
->status_is(400) |
134 |
->status_is(400) |
104 |
- |
|
|