|
Lines 2-8
Link Here
|
| 2 |
|
2 |
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
|
4 |
|
| 5 |
use Test::More tests => 1; |
5 |
use Test::More tests => 2; |
| 6 |
use Test::MockModule; |
6 |
use Test::MockModule; |
| 7 |
use Test::Mojo; |
7 |
use Test::Mojo; |
| 8 |
|
8 |
|
|
Lines 18-47
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
Link Here
|
| 18 |
|
18 |
|
| 19 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
19 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 20 |
|
20 |
|
| 21 |
subtest 'order by me.barcode should return 200' => sub { |
21 |
subtest 'bundled_items()' => sub { |
| 22 |
plan tests => 2; |
22 |
plan tests => 7; |
| 23 |
|
23 |
|
| 24 |
$schema->storage->txn_begin; |
24 |
$schema->storage->txn_begin; |
| 25 |
|
25 |
|
| 26 |
my $bundle = $builder->build_sample_item; |
26 |
my $item = $builder->build_sample_item; |
| 27 |
my $item = $builder->build_sample_item; |
27 |
my $itemnumber = $item->itemnumber; |
| 28 |
$bundle->add_to_bundle($item); |
28 |
my $patron = $builder->build_object( |
|
|
29 |
{ |
| 30 |
class => 'Koha::Patrons', |
| 31 |
value => { flags => 4 } |
| 32 |
} |
| 33 |
); |
| 34 |
|
| 35 |
# Make sure we have at least 10 items |
| 36 |
for ( 1 .. 10 ) { |
| 37 |
my $bundled_item = $builder->build_sample_item; |
| 38 |
$item->add_to_bundle($bundled_item); |
| 39 |
} |
| 29 |
|
40 |
|
| 30 |
my $patron = $builder->build_object( |
41 |
my $nonprivilegedpatron = $builder->build_object( |
|
|
42 |
{ |
| 43 |
class => 'Koha::Patrons', |
| 44 |
value => { flags => 0 } |
| 45 |
} |
| 46 |
); |
| 47 |
|
| 48 |
my $password = 'thePassword123'; |
| 49 |
|
| 50 |
$nonprivilegedpatron->set_password( { password => $password, skip_validation => 1 } ); |
| 51 |
my $userid = $nonprivilegedpatron->userid; |
| 52 |
|
| 53 |
$t->get_ok("//$userid:$password@/api/v1/items/$itemnumber/bundled_items")->status_is(403) |
| 54 |
->json_is( '/error' => 'Authorization failure. Missing required permission(s).' ); |
| 55 |
|
| 56 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 57 |
$userid = $patron->userid; |
| 58 |
|
| 59 |
$t->get_ok("//$userid:$password@/api/v1/items/$itemnumber/bundled_items")->status_is( 200, 'SWAGGER3.2.2' ); |
| 60 |
|
| 61 |
my $response_count = scalar @{ $t->tx->res->json }; |
| 62 |
|
| 63 |
is( $response_count, 10, 'The API returns 10 bundled items' ); |
| 64 |
|
| 65 |
$schema->storage->txn_rollback; |
| 66 |
|
| 67 |
subtest 'order by me.barcode should return 200' => sub { |
| 68 |
plan tests => 2; |
| 69 |
|
| 70 |
$schema->storage->txn_begin; |
| 71 |
|
| 72 |
my $bundle = $builder->build_sample_item; |
| 73 |
my $item = $builder->build_sample_item; |
| 74 |
$bundle->add_to_bundle($item); |
| 75 |
|
| 76 |
my $patron = $builder->build_object( |
| 77 |
{ |
| 78 |
class => 'Koha::Patrons', |
| 79 |
value => { flags => 4 } |
| 80 |
} |
| 81 |
); |
| 82 |
|
| 83 |
my $password = 'thePassword123'; |
| 84 |
|
| 85 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 86 |
|
| 87 |
my $userid = $patron->userid; |
| 88 |
my $itemnumber = $bundle->itemnumber; |
| 89 |
|
| 90 |
$t->get_ok("//$userid:$password@/api/v1/items/$itemnumber/bundled_items?_order_by=+me.barcode")->status_is(200); |
| 91 |
|
| 92 |
$schema->storage->txn_rollback; |
| 93 |
}; |
| 94 |
|
| 95 |
}; |
| 96 |
|
| 97 |
subtest 'add_to_bundle' => sub { |
| 98 |
plan tests => 14; |
| 99 |
|
| 100 |
$schema->storage->txn_begin; |
| 101 |
|
| 102 |
my $item = $builder->build_sample_item; |
| 103 |
my $itemnumber = $item->itemnumber; |
| 104 |
my $patron = $builder->build_object( |
| 31 |
{ |
105 |
{ |
| 32 |
class => 'Koha::Patrons', |
106 |
class => 'Koha::Patrons', |
| 33 |
value => { flags => 4 } |
107 |
value => { flags => 4 } |
| 34 |
} |
108 |
} |
| 35 |
); |
109 |
); |
| 36 |
|
110 |
|
|
|
111 |
my $nonprivilegedpatron = $builder->build_object( |
| 112 |
{ |
| 113 |
class => 'Koha::Patrons', |
| 114 |
value => { flags => 0 } |
| 115 |
} |
| 116 |
); |
| 117 |
|
| 37 |
my $password = 'thePassword123'; |
118 |
my $password = 'thePassword123'; |
| 38 |
|
119 |
|
|
|
120 |
$nonprivilegedpatron->set_password( { password => $password, skip_validation => 1 } ); |
| 121 |
my $userid = $nonprivilegedpatron->userid; |
| 122 |
|
| 123 |
my $item_to_bundle = $builder->build_sample_item; |
| 124 |
my $link = { |
| 125 |
item_id => undef, |
| 126 |
external_id => $item_to_bundle->barcode, |
| 127 |
force_checkin => 0, |
| 128 |
ignore_holds => 0, |
| 129 |
marc_link => 0 |
| 130 |
}; |
| 131 |
|
| 132 |
$t->post_ok( "//$userid:$password@/api/v1/items/$itemnumber/bundled_items" => json => $link )->status_is(403) |
| 133 |
->json_is( '/error' => 'Authorization failure. Missing required permission(s).' ); |
| 134 |
|
| 39 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
135 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
|
|
136 |
$userid = $patron->userid; |
| 137 |
|
| 138 |
$t->post_ok( "//$userid:$password@/api/v1/items/$itemnumber/bundled_items" => json => $link ) |
| 139 |
->status_is( 201, 'Link created successfully' ) |
| 140 |
->json_is( '/item_id' => $item_to_bundle->itemnumber, 'Bundled item returned' ); |
| 141 |
|
| 142 |
$t->post_ok( "//$userid:$password@/api/v1/items/$itemnumber/bundled_items" => json => $link ) |
| 143 |
->status_is( 409, 'Cannot re-link already linked item' ) |
| 144 |
->json_is( '/error_code' => 'already_bundled', 'Correct error code' ); |
| 40 |
|
145 |
|
| 41 |
my $userid = $patron->userid; |
146 |
# marc_link |
| 42 |
my $itemnumber = $bundle->itemnumber; |
147 |
$item_to_bundle = $builder->build_sample_item; |
|
|
148 |
$link->{external_id} = $item_to_bundle->barcode; |
| 149 |
$link->{marc_link} = 1; |
| 43 |
|
150 |
|
| 44 |
$t->get_ok("//$userid:$password@/api/v1/items/$itemnumber/bundled_items?_order_by=+me.barcode")->status_is(200); |
151 |
my $bundled_marc = $item_to_bundle->biblio->metadata->record; |
|
|
152 |
is( $bundled_marc->field('773'), undef, 'No 773 field in item to bundle' ); |
| 153 |
|
| 154 |
$t->post_ok( "//$userid:$password@/api/v1/items/$itemnumber/bundled_items" => json => $link ) |
| 155 |
->status_is( 201, 'Link created successfully' ) |
| 156 |
->json_is( '/item_id' => $item_to_bundle->itemnumber, 'Bundled item returned' ); |
| 157 |
|
| 158 |
$item_to_bundle->discard_changes; |
| 159 |
$bundled_marc = $item_to_bundle->biblio->metadata->record; |
| 160 |
is( |
| 161 |
ref( $bundled_marc->field('773') ), 'MARC::Field', |
| 162 |
'773 field is set after bundling with "marc_link = 1"' |
| 163 |
); |
| 45 |
|
164 |
|
| 46 |
$schema->storage->txn_rollback; |
165 |
$schema->storage->txn_rollback; |
| 47 |
}; |
166 |
}; |
| 48 |
- |
|
|