Lines 20-26
use Modern::Perl;
Link Here
|
20 |
use utf8; |
20 |
use utf8; |
21 |
use Encode; |
21 |
use Encode; |
22 |
|
22 |
|
23 |
use Test::More tests => 9; |
23 |
use Test::More tests => 10; |
24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
25 |
use Test::Mojo; |
25 |
use Test::Mojo; |
26 |
use Test::Warn; |
26 |
use Test::Warn; |
Lines 762-764
subtest 'add_item() tests' => sub {
Link Here
|
762 |
|
762 |
|
763 |
$schema->storage->txn_rollback; |
763 |
$schema->storage->txn_rollback; |
764 |
}; |
764 |
}; |
765 |
- |
765 |
|
|
|
766 |
subtest 'update_item() tests' => sub { |
767 |
plan tests => 7; |
768 |
|
769 |
$schema->storage->txn_begin; |
770 |
|
771 |
my $patron = $builder->build_object( |
772 |
{ |
773 |
class => 'Koha::Patrons', |
774 |
value => { flags => 0 } |
775 |
} |
776 |
); |
777 |
my $password = 'thePassword123'; |
778 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
779 |
my $userid = $patron->userid; |
780 |
|
781 |
my $item = $builder->build_sample_item({ replacementprice => 5 }); |
782 |
my $biblio_id = $item->biblionumber; |
783 |
my $item_id = $item->itemnumber; |
784 |
|
785 |
my $biblio = Koha::Biblios->find($item->biblionumber); |
786 |
|
787 |
my $matching_items = Koha::Items->search({ barcode => $item->barcode }); |
788 |
|
789 |
while (my $mbcitem = $matching_items->next) { |
790 |
$mbcitem->delete if $mbcitem->biblionumber != $item->biblionumber; |
791 |
} |
792 |
|
793 |
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => { external_id => 'something' }) |
794 |
->status_is(403, 'Not enough permissions to update an item'); |
795 |
|
796 |
# Add permissions |
797 |
$builder->build( |
798 |
{ |
799 |
source => 'UserPermission', |
800 |
value => { |
801 |
borrowernumber => $patron->borrowernumber, |
802 |
module_bit => 9, |
803 |
code => 'edit_catalogue' |
804 |
} |
805 |
} |
806 |
); |
807 |
|
808 |
my $other_item = $builder->build_sample_item(); |
809 |
|
810 |
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => { |
811 |
external_id => $other_item->barcode, |
812 |
}) |
813 |
->status_is(400, 'Barcode not unique'); |
814 |
|
815 |
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/items/$item_id" => json => { |
816 |
replacement_price => 30, |
817 |
}) |
818 |
->status_is(200, 'Item updated') |
819 |
->json_is('/replacement_price', 30); |
820 |
|
821 |
$schema->storage->txn_rollback; |
822 |
}; |