Lines 23-28
use Test::Mojo;
Link Here
|
23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
|
25 |
|
|
|
26 |
use Mojo::JSON qw(encode_json); |
27 |
|
26 |
use Koha::ItemTypes; |
28 |
use Koha::ItemTypes; |
27 |
use Koha::Database; |
29 |
use Koha::Database; |
28 |
|
30 |
|
Lines 34-40
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
Link Here
|
34 |
|
36 |
|
35 |
subtest 'list() tests' => sub { |
37 |
subtest 'list() tests' => sub { |
36 |
|
38 |
|
37 |
plan tests => 12; |
39 |
plan tests => 13; |
38 |
|
40 |
|
39 |
$schema->storage->txn_begin; |
41 |
$schema->storage->txn_begin; |
40 |
|
42 |
|
Lines 42-48
subtest 'list() tests' => sub {
Link Here
|
42 |
{ |
44 |
{ |
43 |
class => 'Koha::ItemTypes', |
45 |
class => 'Koha::ItemTypes', |
44 |
value => { |
46 |
value => { |
45 |
itemtype => 'TEST_IT', |
|
|
46 |
parent_type => undef, |
47 |
parent_type => undef, |
47 |
description => 'Test item type', |
48 |
description => 'Test item type', |
48 |
rentalcharge => 100.0, |
49 |
rentalcharge => 100.0, |
Lines 70-76
subtest 'list() tests' => sub {
Link Here
|
70 |
class => 'Koha::Localizations', |
71 |
class => 'Koha::Localizations', |
71 |
value => { |
72 |
value => { |
72 |
entity => 'itemtypes', |
73 |
entity => 'itemtypes', |
73 |
code => 'TEST_IT', |
74 |
code => $item_type->id, |
74 |
lang => 'en', |
75 |
lang => 'en', |
75 |
translation => 'English word "test"', |
76 |
translation => 'English word "test"', |
76 |
} |
77 |
} |
Lines 81-87
subtest 'list() tests' => sub {
Link Here
|
81 |
class => 'Koha::Localizations', |
82 |
class => 'Koha::Localizations', |
82 |
value => { |
83 |
value => { |
83 |
entity => 'itemtypes', |
84 |
entity => 'itemtypes', |
84 |
code => 'TEST_IT', |
85 |
code => $item_type->id, |
85 |
lang => 'sv_SE', |
86 |
lang => 'sv_SE', |
86 |
translation => 'Swedish word "test"', |
87 |
translation => 'Swedish word "test"', |
87 |
} |
88 |
} |
Lines 109-138
subtest 'list() tests' => sub {
Link Here
|
109 |
my $unauth_userid = $patron->userid; |
110 |
my $unauth_userid = $patron->userid; |
110 |
|
111 |
|
111 |
## Authorized user tests |
112 |
## Authorized user tests |
112 |
$t->get_ok("//$userid:$password@/api/v1/item_types")->status_is(200)->json_has('/0'); |
113 |
my $query = encode_json( { item_type_id => $item_type->id } ); |
113 |
|
114 |
$t->get_ok("//$userid:$password@/api/v1/item_types?q=$query")->status_is(200)->json_has('/0') |
114 |
for my $json ( @{ $t->tx->res->json } ) { |
115 |
->json_is( '/0/description', $item_type->description )->json_hasnt('/0/translated_descriptions'); |
115 |
if ( $json->{item_type_id} eq 'TEST_IT' ) { |
116 |
|
116 |
is( $json->{description}, 'Test item type' ); |
117 |
$t->get_ok( "//$userid:$password@/api/v1/item_types?q=$query" => { 'x-koha-embed' => 'translated_descriptions' } ) |
117 |
ok( !exists $json->{translated_descriptions} ); |
118 |
->status_is(200)->json_has('/0')->json_is( '/0/description', $item_type->description ) |
118 |
} |
119 |
->json_has('/0/translated_descriptions')->json_is( |
119 |
} |
120 |
'/0/translated_descriptions', |
120 |
|
121 |
[ |
121 |
$t->get_ok( "//$userid:$password@/api/v1/item_types" => { 'x-koha-embed' => 'translated_descriptions' } ) |
122 |
{ lang => 'en', translation => 'English word "test"' }, |
122 |
->status_is(200)->json_has('/0'); |
123 |
{ lang => 'sv_SE', translation => 'Swedish word "test"' }, |
123 |
|
124 |
] |
124 |
for my $json ( @{ $t->tx->res->json } ) { |
125 |
); |
125 |
if ( $json->{item_type_id} eq 'TEST_IT' ) { |
|
|
126 |
is( $json->{description}, 'Test item type' ); |
127 |
is_deeply( |
128 |
$json->{translated_descriptions}, |
129 |
[ |
130 |
{ lang => 'en', translation => 'English word "test"' }, |
131 |
{ lang => 'sv_SE', translation => 'Swedish word "test"' }, |
132 |
] |
133 |
); |
134 |
} |
135 |
} |
136 |
|
126 |
|
137 |
# Unauthorized access |
127 |
# Unauthorized access |
138 |
$t->get_ok("//$unauth_userid:$password@/api/v1/item_types")->status_is(403); |
128 |
$t->get_ok("//$unauth_userid:$password@/api/v1/item_types")->status_is(403); |
139 |
- |
|
|