|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 1; |
22 |
use Test::More tests => 2; |
| 23 |
use Test::Mojo; |
23 |
use Test::Mojo; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
Lines 37-42
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
Link Here
|
| 37 |
|
37 |
|
| 38 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
38 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 39 |
|
39 |
|
|
|
40 |
subtest 'list() tests' => sub { |
| 41 |
|
| 42 |
plan tests => 12; |
| 43 |
|
| 44 |
$schema->storage->txn_begin; |
| 45 |
|
| 46 |
my $item = $builder->build_object( { class => 'Koha::Items' } ); |
| 47 |
my $patron = $builder->build_object( |
| 48 |
{ |
| 49 |
class => 'Koha::Patrons', |
| 50 |
value => { flags => 4 } |
| 51 |
} |
| 52 |
); |
| 53 |
|
| 54 |
my $nonprivilegedpatron = $builder->build_object( |
| 55 |
{ |
| 56 |
class => 'Koha::Patrons', |
| 57 |
value => { flags => 0 } |
| 58 |
} |
| 59 |
); |
| 60 |
|
| 61 |
my $password = 'thePassword123'; |
| 62 |
|
| 63 |
$nonprivilegedpatron->set_password( |
| 64 |
{ password => $password, skip_validation => 1 } ); |
| 65 |
my $userid = $nonprivilegedpatron->userid; |
| 66 |
|
| 67 |
$t->get_ok( "//$userid:$password@/api/v1/items" ) |
| 68 |
->status_is(403) |
| 69 |
->json_is( |
| 70 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
| 71 |
|
| 72 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 73 |
$userid = $patron->userid; |
| 74 |
|
| 75 |
$t->get_ok( "//$userid:$password@/api/v1/items" ) |
| 76 |
->status_is( 200, 'SWAGGER3.2.2' ); |
| 77 |
|
| 78 |
my $items_count = Koha::Items->search->count; |
| 79 |
my $response_count = scalar @{ $t->tx->res->json }; |
| 80 |
|
| 81 |
is( $items_count, $response_count, 'The API returns all the items' ); |
| 82 |
|
| 83 |
$t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode ) |
| 84 |
->status_is(200) |
| 85 |
->json_is( '' => [ Koha::REST::V1::Items::_to_api( $item->TO_JSON ) ], 'SWAGGER3.3.2'); |
| 86 |
|
| 87 |
my $barcode = $item->barcode; |
| 88 |
$item->delete; |
| 89 |
|
| 90 |
$t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode ) |
| 91 |
->status_is(200) |
| 92 |
->json_is( '' => [] ); |
| 93 |
|
| 94 |
$schema->storage->txn_rollback; |
| 95 |
}; |
| 96 |
|
| 97 |
|
| 40 |
subtest 'get() tests' => sub { |
98 |
subtest 'get() tests' => sub { |
| 41 |
|
99 |
|
| 42 |
plan tests => 9; |
100 |
plan tests => 9; |
| 43 |
- |
|
|