Bug 30708: Tidy perl files
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
2817639d54
commit
81c25dc0be
15 changed files with 345 additions and 452 deletions
|
@ -58,9 +58,9 @@ sub full_message {
|
|||
|
||||
my $msg = $self->message;
|
||||
|
||||
unless ( $msg ) {
|
||||
unless ($msg) {
|
||||
if ( $self->isa('Koha::Exceptions::Preservation::MissingSettings') ) {
|
||||
$msg = sprintf("The following parameter settings is required: %s", $self->parameter );
|
||||
$msg = sprintf( "The following parameter settings is required: %s", $self->parameter );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,22 +44,18 @@ Set or return the attributes for this processing
|
|||
sub attributes {
|
||||
my ( $self, $attributes ) = @_;
|
||||
|
||||
if ( $attributes ) {
|
||||
if ($attributes) {
|
||||
my $schema = $self->_result->result_source->schema;
|
||||
$schema->txn_do(
|
||||
sub {
|
||||
my @existing_ids = map { $_->{processing_attribute_id} || () } @$attributes;
|
||||
if (@existing_ids || !@$attributes) {
|
||||
if ( @existing_ids || !@$attributes ) {
|
||||
$self->attributes->search(
|
||||
{
|
||||
(
|
||||
# If no attributes passed we delete all the existing ones
|
||||
@$attributes
|
||||
? (
|
||||
processing_attribute_id => {
|
||||
-not_in => \@existing_ids
|
||||
}
|
||||
)
|
||||
? ( processing_attribute_id => { -not_in => \@existing_ids } )
|
||||
: ()
|
||||
)
|
||||
}
|
||||
|
@ -71,7 +67,7 @@ sub attributes {
|
|||
if ($existing_attribute) {
|
||||
$existing_attribute->set($attribute)->store;
|
||||
} else {
|
||||
$self->_result ->add_to_preservation_processing_attributes( $attribute );
|
||||
$self->_result->add_to_preservation_processing_attributes($attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,10 +88,9 @@ Note that we do not enforce that in ->delete, the callers are supposed to deal w
|
|||
sub can_be_deleted {
|
||||
my ($self) = @_;
|
||||
|
||||
my $trains_using_it = Koha::Preservation::Trains->search(
|
||||
{ default_processing_id => $self->processing_id } )->count;
|
||||
my $items_using_it = Koha::Preservation::Train::Items->search(
|
||||
{ processing_id => $self->processing_id } )->count;
|
||||
my $trains_using_it =
|
||||
Koha::Preservation::Trains->search( { default_processing_id => $self->processing_id } )->count;
|
||||
my $items_using_it = Koha::Preservation::Train::Items->search( { processing_id => $self->processing_id } )->count;
|
||||
|
||||
return ( $trains_using_it || $items_using_it ) ? 0 : 1;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ Return the default processing object for this train
|
|||
=cut
|
||||
|
||||
sub default_processing {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
my $rs = $self->_result->default_processing;
|
||||
return unless $rs;
|
||||
return Koha::Preservation::Processing->_new_from_dbic($rs);
|
||||
|
@ -81,9 +81,7 @@ sub add_item {
|
|||
|
||||
my $already_in_train = Koha::Preservation::Train::Items->search(
|
||||
{ item_id => $train_item->{item_id}, 'train.received_on' => undef },
|
||||
{
|
||||
join => 'train'
|
||||
}
|
||||
{ join => 'train' }
|
||||
);
|
||||
if ( $already_in_train->count ) {
|
||||
my $train_id = $already_in_train->next->train_id;
|
||||
|
@ -121,7 +119,7 @@ sub add_items {
|
|||
for my $train_item (@$train_items) {
|
||||
try {
|
||||
my $added_item = $self->add_item($train_item);
|
||||
$added_item->attributes($train_item->{attributes});
|
||||
$added_item->attributes( $train_item->{attributes} );
|
||||
push @added_items, $added_item;
|
||||
} catch {
|
||||
|
||||
|
@ -142,9 +140,9 @@ Return the items in this train.
|
|||
=cut
|
||||
|
||||
sub items {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
my $items_rs = $self->_result->preservation_trains_items;
|
||||
return Koha::Preservation::Train::Items->_new_from_dbic($items_rs)
|
||||
return Koha::Preservation::Train::Items->_new_from_dbic($items_rs);
|
||||
}
|
||||
|
||||
=head2 Internal methods
|
||||
|
|
|
@ -45,7 +45,7 @@ Return the processing object for this item
|
|||
=cut
|
||||
|
||||
sub processing {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
my $rs = $self->_result->processing; # FIXME Should we return train's default processing if there is no specific?
|
||||
return Koha::Preservation::Processing->_new_from_dbic($rs);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ Return the catalogue item object for this train item
|
|||
=cut
|
||||
|
||||
sub catalogue_item {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
my $item_rs = $self->_result->item;
|
||||
return Koha::Item->_new_from_dbic($item_rs);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ Getter and setter for the attributes
|
|||
sub attributes {
|
||||
my ( $self, $attributes ) = @_;
|
||||
|
||||
if ( $attributes ) {
|
||||
if ($attributes) {
|
||||
my $schema = $self->_result->result_source->schema;
|
||||
$schema->txn_do(
|
||||
sub {
|
||||
|
|
|
@ -45,9 +45,9 @@ Return the Koha::Preservation::Processing::Attribute object
|
|||
=cut
|
||||
|
||||
sub processing_attribute {
|
||||
my ( $self ) = @_;
|
||||
my ($self) = @_;
|
||||
my $processing_attribute_rs = $self->_result->processing_attribute;
|
||||
return Koha::Preservation::Processing::Attribute->_new_from_dbic($processing_attribute_rs)
|
||||
return Koha::Preservation::Processing::Attribute->_new_from_dbic($processing_attribute_rs);
|
||||
}
|
||||
|
||||
=head3 strings_map
|
||||
|
|
|
@ -39,7 +39,9 @@ Return the configuration options needed for the Preservation Vue app
|
|||
|
||||
sub config {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $patron = $c->stash('koha.user');
|
||||
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => {
|
||||
|
|
|
@ -23,6 +23,7 @@ use Koha::Preservation::Processings;
|
|||
|
||||
use Scalar::Util qw( blessed );
|
||||
use Try::Tiny;
|
||||
|
||||
=head1 API
|
||||
|
||||
=head2 Methods
|
||||
|
@ -36,10 +37,9 @@ sub list {
|
|||
|
||||
return try {
|
||||
my $processings_set = Koha::Preservation::Processings->new;
|
||||
my $processings = $c->objects->search( $processings_set );
|
||||
my $processings = $c->objects->search($processings_set);
|
||||
return $c->render( status => 200, openapi => $processings );
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
@ -68,8 +68,7 @@ sub get {
|
|||
status => 200,
|
||||
openapi => $processing
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
@ -94,15 +93,14 @@ sub add {
|
|||
my $processing = Koha::Preservation::Processing->new_from_api($body)->store;
|
||||
$processing->attributes($attributes);
|
||||
|
||||
$c->res->headers->location($c->req->url->to_string . '/' . $processing->processing_id);
|
||||
$c->res->headers->location( $c->req->url->to_string . '/' . $processing->processing_id );
|
||||
return $c->render(
|
||||
status => 201,
|
||||
openapi => $processing->to_api
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
|
||||
my $to_api_mapping = Koha::Preservation::Processing->new->to_api_mapping;
|
||||
|
||||
|
@ -112,28 +110,17 @@ sub add {
|
|||
status => 409,
|
||||
openapi => { error => $_->error, conflict => $_->duplicate_id }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->broken_fk }
|
||||
. " does not exist"
|
||||
}
|
||||
openapi => { error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->parameter }
|
||||
. " does not exist"
|
||||
}
|
||||
openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
return $c->render(
|
||||
status => 413,
|
||||
openapi => { error => $_->error }
|
||||
|
@ -155,7 +142,7 @@ sub update {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $processing_id = $c->param('processing_id');
|
||||
my $processing = Koha::Preservation::Processings->find( $processing_id );
|
||||
my $processing = Koha::Preservation::Processings->find($processing_id);
|
||||
|
||||
unless ($processing) {
|
||||
return $c->render(
|
||||
|
@ -175,40 +162,28 @@ sub update {
|
|||
$processing->set_from_api($body)->store;
|
||||
$processing->attributes($attributes);
|
||||
|
||||
|
||||
$c->res->headers->location($c->req->url->to_string . '/' . $processing->processing_id);
|
||||
$c->res->headers->location( $c->req->url->to_string . '/' . $processing->processing_id );
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => $processing->to_api
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
my $to_api_mapping = Koha::Preservation::Processing->new->to_api_mapping;
|
||||
|
||||
if ( blessed $_ ) {
|
||||
if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->broken_fk }
|
||||
. " does not exist"
|
||||
}
|
||||
openapi => { error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->parameter }
|
||||
. " does not exist"
|
||||
}
|
||||
openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
return $c->render(
|
||||
status => 413,
|
||||
openapi => { error => $_->error }
|
||||
|
@ -218,7 +193,7 @@ sub update {
|
|||
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
=head3 delete
|
||||
|
||||
|
@ -228,7 +203,7 @@ sub delete {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $processing_id = $c->param('processing_id');
|
||||
my $processing = Koha::Preservation::Processings->find( $processing_id );
|
||||
my $processing = Koha::Preservation::Processings->find($processing_id);
|
||||
unless ($processing) {
|
||||
return $c->render(
|
||||
status => 404,
|
||||
|
@ -236,7 +211,7 @@ sub delete {
|
|||
);
|
||||
}
|
||||
|
||||
unless ($processing->can_be_deleted) {
|
||||
unless ( $processing->can_be_deleted ) {
|
||||
return $c->render(
|
||||
status => 409,
|
||||
openapi => { error => "Processing is already used" },
|
||||
|
@ -248,8 +223,7 @@ sub delete {
|
|||
status => 204,
|
||||
openapi => q{}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -40,10 +40,9 @@ sub list {
|
|||
|
||||
return try {
|
||||
my $trains_set = Koha::Preservation::Trains->new;
|
||||
my $trains = $c->objects->search( $trains_set );
|
||||
my $trains = $c->objects->search($trains_set);
|
||||
return $c->render( status => 200, openapi => $trains );
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
@ -72,8 +71,7 @@ sub get {
|
|||
status => 200,
|
||||
openapi => $train
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
@ -95,15 +93,14 @@ sub add {
|
|||
|
||||
my $train = Koha::Preservation::Train->new_from_api($body)->store;
|
||||
|
||||
$c->res->headers->location($c->req->url->to_string . '/' . $train->train_id);
|
||||
$c->res->headers->location( $c->req->url->to_string . '/' . $train->train_id );
|
||||
return $c->render(
|
||||
status => 201,
|
||||
openapi => $train->to_api
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
|
||||
my $to_api_mapping = Koha::Preservation::Train->new->to_api_mapping;
|
||||
|
||||
|
@ -113,28 +110,17 @@ sub add {
|
|||
status => 409,
|
||||
openapi => { error => $_->error, conflict => $_->duplicate_id }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->broken_fk }
|
||||
. " does not exist"
|
||||
}
|
||||
openapi => { error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->parameter }
|
||||
. " does not exist"
|
||||
}
|
||||
openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
return $c->render(
|
||||
status => 413,
|
||||
openapi => { error => $_->error }
|
||||
|
@ -156,7 +142,7 @@ sub update {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $train_id = $c->param('train_id');
|
||||
my $train = Koha::Preservation::Trains->find( $train_id );
|
||||
my $train = Koha::Preservation::Trains->find($train_id);
|
||||
|
||||
unless ($train) {
|
||||
return $c->render(
|
||||
|
@ -173,39 +159,28 @@ sub update {
|
|||
|
||||
$train->set_from_api($body)->store;
|
||||
|
||||
$c->res->headers->location($c->req->url->to_string . '/' . $train->train_id);
|
||||
$c->res->headers->location( $c->req->url->to_string . '/' . $train->train_id );
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => $train->to_api
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
my $to_api_mapping = Koha::Preservation::Train->new->to_api_mapping;
|
||||
|
||||
if ( blessed $_ ) {
|
||||
if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->broken_fk }
|
||||
. " does not exist"
|
||||
}
|
||||
openapi => { error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::BadParameter') ) {
|
||||
return $c->render(
|
||||
status => 400,
|
||||
openapi => {
|
||||
error => "Given "
|
||||
. $to_api_mapping->{ $_->parameter }
|
||||
. " does not exist"
|
||||
}
|
||||
openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
} elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) {
|
||||
return $c->render(
|
||||
status => 413,
|
||||
openapi => { error => $_->error }
|
||||
|
@ -215,7 +190,7 @@ sub update {
|
|||
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
=head3 delete
|
||||
|
||||
|
@ -240,8 +215,7 @@ sub delete {
|
|||
status => 204,
|
||||
openapi => q{}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
@ -256,7 +230,7 @@ sub get_item {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $train_id = $c->param('train_id');
|
||||
my $train = Koha::Preservation::Trains->find( $train_id );
|
||||
my $train = Koha::Preservation::Trains->find($train_id);
|
||||
|
||||
unless ($train) {
|
||||
return $c->render(
|
||||
|
@ -267,7 +241,10 @@ sub get_item {
|
|||
|
||||
my $train_item_id = $c->param('train_item_id');
|
||||
|
||||
my $train_item = $c->objects->find(Koha::Preservation::Train::Items->search, { train_item_id => $train_item_id, train_id => $train_id });
|
||||
my $train_item = $c->objects->find(
|
||||
Koha::Preservation::Train::Items->search,
|
||||
{ train_item_id => $train_item_id, train_id => $train_id }
|
||||
);
|
||||
|
||||
unless ($train_item) {
|
||||
return $c->render(
|
||||
|
@ -282,8 +259,7 @@ sub get_item {
|
|||
return $c->render( status => 200, openapi => $train_item );
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
@ -298,7 +274,7 @@ sub add_items {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $train_id = $c->param('train_id');
|
||||
my $train = Koha::Preservation::Trains->find( $train_id );
|
||||
my $train = Koha::Preservation::Trains->find($train_id);
|
||||
|
||||
unless ($train) {
|
||||
return $c->render(
|
||||
|
@ -315,8 +291,7 @@ sub add_items {
|
|||
return $c->render( status => 201, openapi => $train_items );
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
if ( blessed $_ ) {
|
||||
if ( $_->isa('Koha::Exceptions::Preservation::MissingSettings') ) {
|
||||
return $c->render(
|
||||
|
@ -340,7 +315,7 @@ sub add_item {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $train_id = $c->param('train_id');
|
||||
my $train = Koha::Preservation::Trains->find( $train_id );
|
||||
my $train = Koha::Preservation::Trains->find($train_id);
|
||||
|
||||
unless ($train) {
|
||||
return $c->render(
|
||||
|
@ -359,8 +334,7 @@ sub add_item {
|
|||
return $c->render( status => 201, openapi => $train_item );
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
if ( blessed $_ ) {
|
||||
if ( $_->isa('Koha::Exceptions::Preservation::MissingSettings') ) {
|
||||
return $c->render(
|
||||
|
@ -409,7 +383,7 @@ sub copy_item {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $train_id = $c->param('train_id');
|
||||
my $train = Koha::Preservation::Trains->find( $train_id );
|
||||
my $train = Koha::Preservation::Trains->find($train_id);
|
||||
|
||||
unless ($train) {
|
||||
return $c->render(
|
||||
|
@ -420,7 +394,8 @@ sub copy_item {
|
|||
|
||||
my $train_item_id = $c->param('train_item_id');
|
||||
|
||||
my $train_item = Koha::Preservation::Train::Items->search({ train_item_id => $train_item_id, train_id => $train_id })->single;
|
||||
my $train_item =
|
||||
Koha::Preservation::Train::Items->search( { train_item_id => $train_item_id, train_id => $train_id } )->single;
|
||||
|
||||
unless ($train_item) {
|
||||
return $c->render(
|
||||
|
@ -434,7 +409,7 @@ sub copy_item {
|
|||
Koha::Database->new->schema->txn_do(
|
||||
sub {
|
||||
my $new_train_id = delete $body->{train_id};
|
||||
my $new_train = Koha::Preservation::Trains->find( $new_train_id );
|
||||
my $new_train = Koha::Preservation::Trains->find($new_train_id);
|
||||
unless ($train) {
|
||||
return $c->render(
|
||||
status => 404,
|
||||
|
@ -463,8 +438,7 @@ sub copy_item {
|
|||
return $c->render( status => 201, openapi => $train_item );
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
if ( blessed $_ ) {
|
||||
if ( $_->isa('Koha::Exceptions::Preservation::MissingSettings') ) {
|
||||
return $c->render(
|
||||
|
@ -513,7 +487,7 @@ sub update_item {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $train_id = $c->param('train_id');
|
||||
my $train = Koha::Preservation::Trains->find( $train_id );
|
||||
my $train = Koha::Preservation::Trains->find($train_id);
|
||||
|
||||
unless ($train) {
|
||||
return $c->render(
|
||||
|
@ -524,7 +498,8 @@ sub update_item {
|
|||
|
||||
my $train_item_id = $c->param('train_item_id');
|
||||
|
||||
my $train_item = Koha::Preservation::Train::Items->search({ train_item_id => $train_item_id, train_id => $train_id })->single;
|
||||
my $train_item =
|
||||
Koha::Preservation::Train::Items->search( { train_item_id => $train_item_id, train_id => $train_id } )->single;
|
||||
|
||||
unless ($train_item) {
|
||||
return $c->render(
|
||||
|
@ -544,13 +519,11 @@ sub update_item {
|
|||
return $c->render( status => 200, openapi => $train_item );
|
||||
}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
=head3 remove_item
|
||||
|
||||
Controller function that handles removing an item from a train
|
||||
|
@ -561,7 +534,7 @@ sub remove_item {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $train_id = $c->param('train_id');
|
||||
my $train = Koha::Preservation::Trains->find( $train_id );
|
||||
my $train = Koha::Preservation::Trains->find($train_id);
|
||||
|
||||
unless ($train) {
|
||||
return $c->render(
|
||||
|
@ -588,8 +561,7 @@ sub remove_item {
|
|||
status => 204,
|
||||
openapi => q{}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -41,16 +41,16 @@ sub list {
|
|||
|
||||
return try {
|
||||
my $not_for_loan = C4::Context->preference('PreservationNotForLoanWaitingListIn');
|
||||
Koha::Exceptions::Preservation::MissingSettings->throw( parameter => 'PreservationNotForLoanWaitingListIn' ) unless $not_for_loan;
|
||||
Koha::Exceptions::Preservation::MissingSettings->throw( parameter => 'PreservationNotForLoanWaitingListIn' )
|
||||
unless $not_for_loan;
|
||||
|
||||
my $items_set = Koha::Items->new->search({ notforloan => $not_for_loan });
|
||||
my $items = $c->objects->search( $items_set );
|
||||
my $items_set = Koha::Items->new->search( { notforloan => $not_for_loan } );
|
||||
my $items = $c->objects->search($items_set);
|
||||
return $c->render(
|
||||
status => 200,
|
||||
openapi => $items
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
if ( blessed $_ ) {
|
||||
if ( $_->isa('Koha::Exceptions::Preservation::MissingSettings') ) {
|
||||
return $c->render(
|
||||
|
@ -77,10 +77,11 @@ sub add_items {
|
|||
my $body = $c->req->json;
|
||||
my $new_not_for_loan = C4::Context->preference('PreservationNotForLoanWaitingListIn');
|
||||
|
||||
Koha::Exceptions::Preservation::MissingSettings->throw( parameter => 'PreservationNotForLoanWaitingListIn' ) unless $new_not_for_loan;
|
||||
Koha::Exceptions::Preservation::MissingSettings->throw( parameter => 'PreservationNotForLoanWaitingListIn' )
|
||||
unless $new_not_for_loan;
|
||||
|
||||
my @items;
|
||||
for my $item_id ( @$body ) {
|
||||
for my $item_id (@$body) {
|
||||
try {
|
||||
while ( my ( $k, $v ) = each %$item_id ) {
|
||||
|
||||
|
@ -97,7 +98,7 @@ sub add_items {
|
|||
join => 'train',
|
||||
}
|
||||
)->count;
|
||||
if ( $already_in_train ) {
|
||||
if ($already_in_train) {
|
||||
Koha::Exceptions::Preservation::ItemAlreadyInTrain->throw;
|
||||
}
|
||||
|
||||
|
@ -110,8 +111,7 @@ sub add_items {
|
|||
};
|
||||
}
|
||||
return $c->render( status => 201, openapi => \@items );
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ sub remove_item {
|
|||
}
|
||||
|
||||
my $not_for_loan_waiting_list_in = C4::Context->preference('PreservationNotForLoanWaitingListIn');
|
||||
if ($item->notforloan ne $not_for_loan_waiting_list_in) {
|
||||
if ( $item->notforloan ne $not_for_loan_waiting_list_in ) {
|
||||
unless ($item) {
|
||||
return $c->render(
|
||||
status => 404,
|
||||
|
@ -153,8 +153,7 @@ sub remove_item {
|
|||
status => 204,
|
||||
openapi => q{}
|
||||
);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
$c->unhandled_exception($_);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -85,7 +85,10 @@ subtest 'can_be_deleted' => sub {
|
|||
is( $another_processing->can_be_deleted, 1, 'processing is not used, it can be deleted' );
|
||||
|
||||
my $item = $builder->build_sample_item;
|
||||
$train->add_item( { item_id => $item->itemnumber, processing_id => $another_processing->processing_id }, { skip_waiting_list_check => 1 } );
|
||||
$train->add_item(
|
||||
{ item_id => $item->itemnumber, processing_id => $another_processing->processing_id },
|
||||
{ skip_waiting_list_check => 1 }
|
||||
);
|
||||
is( $processing->can_be_deleted, 0, 'processing is used, it cannot be deleted' );
|
||||
is( $another_processing->can_be_deleted, 0, 'processing is used, it cannot be deleted' );
|
||||
|
||||
|
|
|
@ -40,10 +40,14 @@ subtest 'default_processing' => sub {
|
|||
my $processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $another_processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
|
||||
my $train = $builder->build_object( { class => 'Koha::Preservation::Trains', value => { default_processing_id => $processing->processing_id } } );
|
||||
my $train = $builder->build_object(
|
||||
{ class => 'Koha::Preservation::Trains', value => { default_processing_id => $processing->processing_id } } );
|
||||
|
||||
my $default_processing = $train->default_processing;
|
||||
is( ref($default_processing), 'Koha::Preservation::Processing', '->default_processing returns a Koha::Preservation::Processing object' );
|
||||
is(
|
||||
ref($default_processing), 'Koha::Preservation::Processing',
|
||||
'->default_processing returns a Koha::Preservation::Processing object'
|
||||
);
|
||||
is( $default_processing->processing_id, $processing->processing_id, 'correct processing is returned' );
|
||||
$processing->delete;
|
||||
$default_processing = $train->get_from_storage->default_processing;
|
||||
|
@ -74,13 +78,20 @@ subtest 'add_items & items' => sub {
|
|||
my $item_2 = $builder->build_sample_item;
|
||||
my $item_3 = $builder->build_sample_item;
|
||||
|
||||
$builder->build_object( { class => 'Koha::AuthorisedValues', value => { category => 'NOT_LOAN', authorised_value => $not_for_loan_waiting_list_in } } );
|
||||
$builder->build_object(
|
||||
{
|
||||
class => 'Koha::AuthorisedValues',
|
||||
value => { category => 'NOT_LOAN', authorised_value => $not_for_loan_waiting_list_in }
|
||||
}
|
||||
);
|
||||
$item_1->notforloan($not_for_loan_waiting_list_in)->store;
|
||||
$item_2->notforloan(0)->store; # item_2 is not in the waiting list
|
||||
$item_3->notforloan($not_for_loan_waiting_list_in)->store;
|
||||
t::lib::Mocks::mock_preference( 'PreservationNotForLoanWaitingListIn', $not_for_loan_waiting_list_in );
|
||||
warning_is {
|
||||
$train->add_items( [ { item_id => $item_1->itemnumber }, { item_id => $item_2->itemnumber }, { barcode => $item_3->barcode } ] );
|
||||
$train->add_items(
|
||||
[ { item_id => $item_1->itemnumber }, { item_id => $item_2->itemnumber }, { barcode => $item_3->barcode } ]
|
||||
);
|
||||
}
|
||||
'Item not added to train: [Cannot add item to train, it is not in the waiting list]';
|
||||
my $items_train = $train->items;
|
||||
|
@ -101,7 +112,8 @@ subtest 'add_items & items' => sub {
|
|||
|
||||
warning_is {
|
||||
$train->add_item( { item_id => $item_2->itemnumber }, { skip_waiting_list_check => 1 } );
|
||||
} '';
|
||||
}
|
||||
'';
|
||||
is( $train->items->count, 3, 'the item has been added to the train' );
|
||||
is( $item_2->get_from_storage->notforloan, $not_for_loan_train_in );
|
||||
|
||||
|
@ -121,12 +133,14 @@ subtest 'add_items & items' => sub {
|
|||
|
||||
throws_ok {
|
||||
$another_train->add_item( { item_id => $item_1->itemnumber }, { skip_waiting_list_check => 1 } );
|
||||
} 'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain';
|
||||
}
|
||||
'Koha::Exceptions::Preservation::ItemAlreadyInAnotherTrain';
|
||||
|
||||
my $item_4 = $builder->build_sample_item;
|
||||
throws_ok {
|
||||
$train->add_item( { item_id => $item_4->itemnumber } );
|
||||
} 'Koha::Exceptions::Preservation::CannotAddItemToClosedTrain';
|
||||
}
|
||||
'Koha::Exceptions::Preservation::CannotAddItemToClosedTrain';
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
@ -62,8 +62,7 @@ subtest 'list() tests' => sub {
|
|||
|
||||
## Authorized user tests
|
||||
# No processings, so empty array should be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/processings")->status_is(200)
|
||||
->json_is( [] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/processings")->status_is(200)->json_is( [] );
|
||||
|
||||
my $processing = $builder->build_object(
|
||||
{
|
||||
|
@ -76,8 +75,7 @@ subtest 'list() tests' => sub {
|
|||
->json_is( [ $processing->to_api ] );
|
||||
|
||||
# Unauthorized access
|
||||
$t->get_ok("//$unauth_userid:$password@/api/v1/preservation/processings")
|
||||
->status_is(403);
|
||||
$t->get_ok("//$unauth_userid:$password@/api/v1/preservation/processings")->status_is(403);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
@ -88,8 +86,7 @@ subtest 'get() tests' => sub {
|
|||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $processing =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $attributes = [
|
||||
{
|
||||
name => 'color',
|
||||
|
@ -124,27 +121,25 @@ subtest 'get() tests' => sub {
|
|||
my $unauth_userid = $patron->userid;
|
||||
|
||||
# This processing exists, should get returned
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/processings/"
|
||||
. $processing->processing_id )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/processings/" . $processing->processing_id )->status_is(200)
|
||||
->json_is( $processing->to_api );
|
||||
|
||||
# Return one processing with attributes
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/processings/"
|
||||
. $processing->processing_id => {'x-koha-embed' => 'attributes'} )->status_is(200)
|
||||
->json_is( { %{ $processing->to_api }, attributes => $attributes->to_api });
|
||||
. $processing->processing_id => { 'x-koha-embed' => 'attributes' } )->status_is(200)
|
||||
->json_is( { %{ $processing->to_api }, attributes => $attributes->to_api } );
|
||||
|
||||
# Unauthorized access
|
||||
$t->get_ok( "//$unauth_userid:$password@/api/v1/preservation/processings/"
|
||||
. $processing->processing_id )->status_is(403);
|
||||
$t->get_ok( "//$unauth_userid:$password@/api/v1/preservation/processings/" . $processing->processing_id )
|
||||
->status_is(403);
|
||||
|
||||
# Attempt to get non-existent processing
|
||||
my $processing_to_delete =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $processing_to_delete = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $non_existent_id = $processing_to_delete->processing_id;
|
||||
$processing_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/processings/$non_existent_id")
|
||||
->status_is(404)->json_is( '/error' => 'Processing not found' );
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/processings/$non_existent_id")->status_is(404)
|
||||
->json_is( '/error' => 'Processing not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
@ -175,14 +170,13 @@ subtest 'add() tests' => sub {
|
|||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $unauth_userid = $patron->userid;
|
||||
|
||||
my $default_processing = $builder->build_object({class => 'Koha::Preservation::Processings'});
|
||||
my $default_processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $processing = {
|
||||
name => "processing name",
|
||||
};
|
||||
|
||||
# Unauthorized attempt to write
|
||||
$t->post_ok( "//$unauth_userid:$password@/api/v1/preservation/processings" => json =>
|
||||
$processing )->status_is(403);
|
||||
$t->post_ok( "//$unauth_userid:$password@/api/v1/preservation/processings" => json => $processing )->status_is(403);
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
my $processing_with_invalid_field = {
|
||||
|
@ -190,8 +184,8 @@ subtest 'add() tests' => sub {
|
|||
%$processing,
|
||||
};
|
||||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/processings" => json =>
|
||||
$processing_with_invalid_field )->status_is(400)->json_is(
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/processings" => json => $processing_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
@ -202,25 +196,21 @@ subtest 'add() tests' => sub {
|
|||
|
||||
# Authorized attempt to write
|
||||
my $processing_id =
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/processings" => json => $processing )
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/processings" => json => $processing )
|
||||
->status_is( 201, 'SWAGGER3.2.1' )->header_like(
|
||||
Location => qr|^/api/v1/preservation/processings/\d*|,
|
||||
'SWAGGER3.4.1'
|
||||
)->json_is( '/name' => $processing->{name} )
|
||||
->tx->res->json->{processing_id};
|
||||
)->json_is( '/name' => $processing->{name} )->tx->res->json->{processing_id};
|
||||
|
||||
# Authorized attempt to create with null id
|
||||
$processing->{processing_id} = undef;
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/processings" => json => $processing )
|
||||
->status_is(400)->json_has('/errors');
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/processings" => json => $processing )->status_is(400)
|
||||
->json_has('/errors');
|
||||
|
||||
# Authorized attempt to create with existing id
|
||||
$processing->{processing_id} = $processing_id;
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/processings" => json => $processing )
|
||||
->status_is(400)->json_is(
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/processings" => json => $processing )->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Read-only.",
|
||||
|
@ -258,34 +248,28 @@ subtest 'update() tests' => sub {
|
|||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $unauth_userid = $patron->userid;
|
||||
|
||||
my $processing_id =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Processings' } )->processing_id;
|
||||
my $processing_id = $builder->build_object( { class => 'Koha::Preservation::Processings' } )->processing_id;
|
||||
|
||||
# Unauthorized attempt to update
|
||||
$t->put_ok(
|
||||
"//$unauth_userid:$password@/api/v1/preservation/processings/$processing_id" =>
|
||||
json => { name => 'New unauthorized name change' } )->status_is(403);
|
||||
$t->put_ok( "//$unauth_userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
{ name => 'New unauthorized name change' } )->status_is(403);
|
||||
|
||||
# Attempt partial update on a PUT
|
||||
my $processing_with_missing_field = {
|
||||
};
|
||||
my $processing_with_missing_field = {};
|
||||
|
||||
$t->put_ok(
|
||||
"//$userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
$processing_with_missing_field )->status_is(400)
|
||||
->json_is( "/errors" =>
|
||||
[ { message => "Missing property.", path => "/body/name" } ] );
|
||||
->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
|
||||
|
||||
my $default_processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
|
||||
my $default_processing = $builder->build_object({class => 'Koha::Preservation::Processings'});
|
||||
# Full object update on PUT
|
||||
my $processing_with_updated_field = {
|
||||
name => "New name",
|
||||
};
|
||||
|
||||
$t->put_ok(
|
||||
"//$userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
$processing_with_updated_field )->status_is(200)
|
||||
->json_is( '/name' => 'New name' );
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
$processing_with_updated_field )->status_is(200)->json_is( '/name' => 'New name' );
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
my $processing_with_invalid_field = {
|
||||
|
@ -293,8 +277,7 @@ subtest 'update() tests' => sub {
|
|||
%$processing_with_updated_field,
|
||||
};
|
||||
|
||||
$t->put_ok(
|
||||
"//$userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
$processing_with_invalid_field )->status_is(400)->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
|
@ -305,19 +288,17 @@ subtest 'update() tests' => sub {
|
|||
);
|
||||
|
||||
# Attempt to update non-existent processing
|
||||
my $processing_to_delete =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $processing_to_delete = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $non_existent_id = $processing_to_delete->processing_id;
|
||||
$processing_to_delete->delete;
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/processings/$non_existent_id" =>
|
||||
json => $processing_with_updated_field )->status_is(404);
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/processings/$non_existent_id" => json =>
|
||||
$processing_with_updated_field )->status_is(404);
|
||||
|
||||
# Wrong method (POST)
|
||||
$processing_with_updated_field->{processing_id} = 2;
|
||||
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/processings/$processing_id" => json =>
|
||||
$processing_with_updated_field )->status_is(404);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
@ -349,21 +330,17 @@ subtest 'delete() tests' => sub {
|
|||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $unauth_userid = $patron->userid;
|
||||
|
||||
my $processing_id =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Processings' } )->processing_id;
|
||||
my $processing_id = $builder->build_object( { class => 'Koha::Preservation::Processings' } )->processing_id;
|
||||
|
||||
# Unauthorized attempt to delete
|
||||
$t->delete_ok(
|
||||
"//$unauth_userid:$password@/api/v1/preservation/processings/$processing_id")
|
||||
->status_is(403);
|
||||
$t->delete_ok("//$unauth_userid:$password@/api/v1/preservation/processings/$processing_id")->status_is(403);
|
||||
|
||||
# Delete existing processing
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/processings/$processing_id")
|
||||
->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' );
|
||||
|
||||
# Attempt to delete non-existent processing
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/processings/$processing_id")
|
||||
->status_is(404);
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/processings/$processing_id")->status_is(404);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
@ -63,8 +63,7 @@ subtest 'list() tests' => sub {
|
|||
|
||||
## Authorized user tests
|
||||
# No trains, so empty array should be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/trains")->status_is(200)
|
||||
->json_is( [] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/trains")->status_is(200)->json_is( [] );
|
||||
|
||||
my $train = $builder->build_object(
|
||||
{
|
||||
|
@ -73,12 +72,10 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# One train created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/trains")->status_is(200)
|
||||
->json_is( [ $train->to_api ] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/trains")->status_is(200)->json_is( [ $train->to_api ] );
|
||||
|
||||
# Unauthorized access
|
||||
$t->get_ok("//$unauth_userid:$password@/api/v1/preservation/trains")
|
||||
->status_is(403);
|
||||
$t->get_ok("//$unauth_userid:$password@/api/v1/preservation/trains")->status_is(403);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
@ -89,8 +86,7 @@ subtest 'get() tests' => sub {
|
|||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $train =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Trains' } );
|
||||
my $train = $builder->build_object( { class => 'Koha::Preservation::Trains' } );
|
||||
my $default_processing = $train->default_processing;
|
||||
my $librarian = $builder->build_object(
|
||||
{
|
||||
|
@ -113,32 +109,38 @@ subtest 'get() tests' => sub {
|
|||
my $unauth_userid = $patron->userid;
|
||||
|
||||
# This train exists, should get returned
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/trains/"
|
||||
. $train->train_id )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/trains/" . $train->train_id )->status_is(200)
|
||||
->json_is( $train->to_api );
|
||||
|
||||
# Return one train with some embeds
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/trains/"
|
||||
. $train->train_id => {'x-koha-embed' => 'items,default_processing'} )->status_is(200)
|
||||
->json_is( { %{ $train->to_api }, items => [], default_processing => $default_processing->unblessed });
|
||||
. $train->train_id => { 'x-koha-embed' => 'items,default_processing' } )->status_is(200)
|
||||
->json_is( { %{ $train->to_api }, items => [], default_processing => $default_processing->unblessed } );
|
||||
|
||||
# Return one train with all embeds
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/trains/"
|
||||
. $train->train_id => { 'x-koha-embed' => 'items,items.attributes,items.attributes.processing_attribute,default_processing,default_processing.attributes' } )
|
||||
->status_is(200)->json_is( { %{ $train->to_api }, items => [], default_processing => { %{ $default_processing->unblessed }, attributes => [] } } );
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/"
|
||||
. $train->train_id => {
|
||||
'x-koha-embed' =>
|
||||
'items,items.attributes,items.attributes.processing_attribute,default_processing,default_processing.attributes'
|
||||
}
|
||||
)->status_is(200)->json_is(
|
||||
{
|
||||
%{ $train->to_api }, items => [],
|
||||
default_processing => { %{ $default_processing->unblessed }, attributes => [] }
|
||||
}
|
||||
);
|
||||
|
||||
# Unauthorized access
|
||||
$t->get_ok( "//$unauth_userid:$password@/api/v1/preservation/trains/"
|
||||
. $train->train_id )->status_is(403);
|
||||
$t->get_ok( "//$unauth_userid:$password@/api/v1/preservation/trains/" . $train->train_id )->status_is(403);
|
||||
|
||||
# Attempt to get non-existent train
|
||||
my $train_to_delete =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Trains' } );
|
||||
my $train_to_delete = $builder->build_object( { class => 'Koha::Preservation::Trains' } );
|
||||
my $non_existent_id = $train_to_delete->train_id;
|
||||
$train_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/trains/$non_existent_id")
|
||||
->status_is(404)->json_is( '/error' => 'Train not found' );
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/trains/$non_existent_id")->status_is(404)
|
||||
->json_is( '/error' => 'Train not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
@ -169,7 +171,7 @@ subtest 'add() tests' => sub {
|
|||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $unauth_userid = $patron->userid;
|
||||
|
||||
my $default_processing = $builder->build_object({class => 'Koha::Preservation::Processings'});
|
||||
my $default_processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $train = {
|
||||
name => "train name",
|
||||
description => "train description",
|
||||
|
@ -178,8 +180,7 @@ subtest 'add() tests' => sub {
|
|||
};
|
||||
|
||||
# Unauthorized attempt to write
|
||||
$t->post_ok( "//$unauth_userid:$password@/api/v1/preservation/trains" => json =>
|
||||
$train )->status_is(403);
|
||||
$t->post_ok( "//$unauth_userid:$password@/api/v1/preservation/trains" => json => $train )->status_is(403);
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
my $train_with_invalid_field = {
|
||||
|
@ -187,8 +188,8 @@ subtest 'add() tests' => sub {
|
|||
%$train,
|
||||
};
|
||||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains" => json =>
|
||||
$train_with_invalid_field )->status_is(400)->json_is(
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains" => json => $train_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
@ -199,28 +200,22 @@ subtest 'add() tests' => sub {
|
|||
|
||||
# Authorized attempt to write
|
||||
my $train_id =
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains" => json => $train )
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains" => json => $train )
|
||||
->status_is( 201, 'SWAGGER3.2.1' )->header_like(
|
||||
Location => qr|^/api/v1/preservation/trains/\d*|,
|
||||
'SWAGGER3.4.1'
|
||||
)->json_is( '/name' => $train->{name} )
|
||||
->json_is( '/description' => $train->{description} )
|
||||
)->json_is( '/name' => $train->{name} )->json_is( '/description' => $train->{description} )
|
||||
->json_is( '/default_processing_id' => $train->{default_processing_id} )
|
||||
->json_is( '/not_for_loan' => $train->{not_for_loan} )
|
||||
->tx->res->json->{train_id};
|
||||
->json_is( '/not_for_loan' => $train->{not_for_loan} )->tx->res->json->{train_id};
|
||||
|
||||
# Authorized attempt to create with null id
|
||||
$train->{train_id} = undef;
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains" => json => $train )
|
||||
->status_is(400)->json_has('/errors');
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains" => json => $train )->status_is(400)
|
||||
->json_has('/errors');
|
||||
|
||||
# Authorized attempt to create with existing id
|
||||
$train->{train_id} = $train_id;
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains" => json => $train )
|
||||
->status_is(400)->json_is(
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains" => json => $train )->status_is(400)->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Read-only.",
|
||||
|
@ -258,25 +253,20 @@ subtest 'update() tests' => sub {
|
|||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $unauth_userid = $patron->userid;
|
||||
|
||||
my $train_id =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Trains' } )->train_id;
|
||||
my $train_id = $builder->build_object( { class => 'Koha::Preservation::Trains' } )->train_id;
|
||||
|
||||
# Unauthorized attempt to update
|
||||
$t->put_ok(
|
||||
"//$unauth_userid:$password@/api/v1/preservation/trains/$train_id" =>
|
||||
json => { name => 'New unauthorized name change' } )->status_is(403);
|
||||
$t->put_ok( "//$unauth_userid:$password@/api/v1/preservation/trains/$train_id" => json =>
|
||||
{ name => 'New unauthorized name change' } )->status_is(403);
|
||||
|
||||
# Attempt partial update on a PUT
|
||||
my $train_with_missing_field = {
|
||||
};
|
||||
my $train_with_missing_field = {};
|
||||
|
||||
$t->put_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id" => json =>
|
||||
$train_with_missing_field )->status_is(400)
|
||||
->json_is( "/errors" =>
|
||||
[ { message => "Missing property.", path => "/body/name" } ] );
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id" => json => $train_with_missing_field )
|
||||
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
|
||||
|
||||
my $default_processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
|
||||
my $default_processing = $builder->build_object({class => 'Koha::Preservation::Processings'});
|
||||
# Full object update on PUT
|
||||
my $train_with_updated_field = {
|
||||
name => "New name",
|
||||
|
@ -285,10 +275,8 @@ subtest 'update() tests' => sub {
|
|||
not_for_loan => 42,
|
||||
};
|
||||
|
||||
$t->put_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id" => json =>
|
||||
$train_with_updated_field )->status_is(200)
|
||||
->json_is( '/name' => 'New name' );
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id" => json => $train_with_updated_field )
|
||||
->status_is(200)->json_is( '/name' => 'New name' );
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
my $train_with_invalid_field = {
|
||||
|
@ -296,9 +284,8 @@ subtest 'update() tests' => sub {
|
|||
%$train_with_updated_field,
|
||||
};
|
||||
|
||||
$t->put_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id" => json =>
|
||||
$train_with_invalid_field )->status_is(400)->json_is(
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id" => json => $train_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
@ -308,20 +295,19 @@ subtest 'update() tests' => sub {
|
|||
);
|
||||
|
||||
# Attempt to update non-existent train
|
||||
my $train_to_delete =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Trains' } );
|
||||
my $train_to_delete = $builder->build_object( { class => 'Koha::Preservation::Trains' } );
|
||||
my $non_existent_id = $train_to_delete->train_id;
|
||||
$train_to_delete->delete;
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/preservation/trains/$non_existent_id" =>
|
||||
json => $train_with_updated_field )->status_is(404);
|
||||
$t->put_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$non_existent_id" => json => $train_with_updated_field )
|
||||
->status_is(404);
|
||||
|
||||
# Wrong method (POST)
|
||||
$train_with_updated_field->{train_id} = 2;
|
||||
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id" => json =>
|
||||
$train_with_updated_field )->status_is(404);
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id" => json => $train_with_updated_field )
|
||||
->status_is(404);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
@ -352,21 +338,17 @@ subtest 'delete() tests' => sub {
|
|||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $unauth_userid = $patron->userid;
|
||||
|
||||
my $train_id =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Trains' } )->train_id;
|
||||
my $train_id = $builder->build_object( { class => 'Koha::Preservation::Trains' } )->train_id;
|
||||
|
||||
# Unauthorized attempt to delete
|
||||
$t->delete_ok(
|
||||
"//$unauth_userid:$password@/api/v1/preservation/trains/$train_id")
|
||||
->status_is(403);
|
||||
$t->delete_ok("//$unauth_userid:$password@/api/v1/preservation/trains/$train_id")->status_is(403);
|
||||
|
||||
# Delete existing train
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/trains/$train_id")
|
||||
->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' );
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/trains/$train_id")->status_is( 204, 'SWAGGER3.2.4' )
|
||||
->content_is( '', 'SWAGGER3.3.4' );
|
||||
|
||||
# Attempt to delete non-existent train
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/trains/$train_id")
|
||||
->status_is(404);
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/trains/$train_id")->status_is(404);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
@ -390,13 +372,13 @@ subtest '*_item() tests' => sub {
|
|||
my $not_for_loan_waiting_list_in = 24;
|
||||
my $not_for_loan_train_in = 42;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'PreservationNotForLoanWaitingListIn',
|
||||
$not_for_loan_waiting_list_in );
|
||||
t::lib::Mocks::mock_preference(
|
||||
'PreservationNotForLoanWaitingListIn',
|
||||
$not_for_loan_waiting_list_in
|
||||
);
|
||||
|
||||
my $default_processing =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $another_processing =
|
||||
$builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $default_processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
my $another_processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
|
||||
|
||||
my $attributes = [
|
||||
{
|
||||
|
@ -411,12 +393,9 @@ subtest '*_item() tests' => sub {
|
|||
},
|
||||
];
|
||||
my $processing_attributes = $default_processing->attributes($attributes);
|
||||
my $color_attribute =
|
||||
$processing_attributes->search( { name => 'color' } )->next;
|
||||
my $title_attribute =
|
||||
$processing_attributes->search( { name => 'title' } )->next;
|
||||
my $height_attribute =
|
||||
$processing_attributes->search( { name => 'height' } )->next;
|
||||
my $color_attribute = $processing_attributes->search( { name => 'color' } )->next;
|
||||
my $title_attribute = $processing_attributes->search( { name => 'title' } )->next;
|
||||
my $height_attribute = $processing_attributes->search( { name => 'height' } )->next;
|
||||
|
||||
my $train = $builder->build_object(
|
||||
{
|
||||
|
@ -438,9 +417,8 @@ subtest '*_item() tests' => sub {
|
|||
|
||||
# Add item not in waiting list
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items" =>
|
||||
json => { item_id => $item_1->itemnumber } )->status_is(400)
|
||||
->json_is( { error => 'Item not in waiting list' } );
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items" => json => { item_id => $item_1->itemnumber }
|
||||
)->status_is(400)->json_is( { error => 'Item not in waiting list' } );
|
||||
|
||||
$item_1->notforloan($not_for_loan_waiting_list_in)->store;
|
||||
|
||||
|
@ -456,53 +434,44 @@ subtest '*_item() tests' => sub {
|
|||
},
|
||||
];
|
||||
my $train_item_id =
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items" =>
|
||||
json =>
|
||||
{ item_id => $item_1->itemnumber, attributes => $item_attributes } )
|
||||
->status_is( 201, 'SWAGGER3.2.1' )
|
||||
->json_is( '/item_id' => $item_1->itemnumber )
|
||||
->json_is( '/processing_id' => $train->default_processing_id )
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id/items" => json =>
|
||||
{ item_id => $item_1->itemnumber, attributes => $item_attributes } )->status_is( 201, 'SWAGGER3.2.1' )
|
||||
->json_is( '/item_id' => $item_1->itemnumber )->json_is( '/processing_id' => $train->default_processing_id )
|
||||
->json_has('/added_on')->tx->res->json->{train_item_id};
|
||||
my $train_item = Koha::Preservation::Train::Items->find($train_item_id);
|
||||
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items/$train_item_id"
|
||||
=> { 'x-koha-embed' => 'attributes' } )->status_is(200)->json_is(
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id/items/$train_item_id" =>
|
||||
{ 'x-koha-embed' => 'attributes' } )->status_is(200)->json_is(
|
||||
{
|
||||
%{ $train_item->to_api },
|
||||
attributes => $train_item->attributes->to_api
|
||||
}
|
||||
);
|
||||
|
||||
is( $item_1->get_from_storage->notforloan,
|
||||
is(
|
||||
$item_1->get_from_storage->notforloan,
|
||||
$train->not_for_loan,
|
||||
"Item not for loan has been set to train's not for loan" );
|
||||
"Item not for loan has been set to train's not for loan"
|
||||
);
|
||||
|
||||
# Add deleted item
|
||||
$item_2->delete;
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items" =>
|
||||
json => { item_id => $item_2->itemnumber } )->status_is(404)
|
||||
->json_is( { error => 'Item not found' } );
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items" => json => { item_id => $item_2->itemnumber }
|
||||
)->status_is(404)->json_is( { error => 'Item not found' } );
|
||||
|
||||
# batch add items
|
||||
# Nothing added (FIXME maybe not 201?)
|
||||
warning_is {
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items/batch"
|
||||
=> json => [ { item_id => $item_3->itemnumber } ] )
|
||||
->status_is(201)->json_is( [] );
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id/items/batch" => json =>
|
||||
[ { item_id => $item_3->itemnumber } ] )->status_is(201)->json_is( [] );
|
||||
}
|
||||
'Item not added to train: [Cannot add item to train, it is not in the waiting list]';
|
||||
|
||||
$item_3->notforloan($not_for_loan_waiting_list_in)->store;
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items/batch"
|
||||
=> json => [ { item_id => $item_3->itemnumber } ] )->status_is(201)
|
||||
->json_is( '/0/item_id' => $item_3->itemnumber )
|
||||
->json_is( '/0/processing_id' => $train->default_processing_id )
|
||||
->json_has('/0/added_on');
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id/items/batch" => json =>
|
||||
[ { item_id => $item_3->itemnumber } ] )->status_is(201)->json_is( '/0/item_id' => $item_3->itemnumber )
|
||||
->json_is( '/0/processing_id' => $train->default_processing_id )->json_has('/0/added_on');
|
||||
|
||||
# Update item
|
||||
my $new_item_attributes = [
|
||||
|
@ -516,16 +485,14 @@ subtest '*_item() tests' => sub {
|
|||
},
|
||||
];
|
||||
$t->put_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items/$train_item_id"
|
||||
=> json => {
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items/$train_item_id" => json => {
|
||||
item_id => $item_1->itemnumber,
|
||||
attributes => $new_item_attributes,
|
||||
}
|
||||
)->status_is(200);
|
||||
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/preservation/trains/$train_id/items/$train_item_id"
|
||||
=> { 'x-koha-embed' => 'attributes' } )->status_is(200)->json_is(
|
||||
$t->get_ok( "//$userid:$password@/api/v1/preservation/trains/$train_id/items/$train_item_id" =>
|
||||
{ 'x-koha-embed' => 'attributes' } )->status_is(200)->json_is(
|
||||
{
|
||||
%{ $train_item->to_api },
|
||||
attributes => $train_item->attributes->to_api
|
||||
|
@ -537,8 +504,8 @@ subtest '*_item() tests' => sub {
|
|||
->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' );
|
||||
|
||||
# Delete non existing item
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/trains/$train_id/items/$train_item_id")
|
||||
->status_is(404)->json_is( '/error' => 'Train item not found' );
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/trains/$train_id/items/$train_item_id")->status_is(404)
|
||||
->json_is( '/error' => 'Train item not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
@ -55,8 +55,7 @@ subtest 'add_item, list, remove_item tests' => sub {
|
|||
my $item_3 = $builder->build_sample_item;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'PreservationNotForLoanWaitingListIn', undef );
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/waiting-list/items")
|
||||
->status_is(400)->json_is(
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/waiting-list/items")->status_is(400)->json_is(
|
||||
{
|
||||
error => 'MissingSettings',
|
||||
parameter => 'PreservationNotForLoanWaitingListIn'
|
||||
|
@ -64,16 +63,16 @@ subtest 'add_item, list, remove_item tests' => sub {
|
|||
);
|
||||
|
||||
my $not_for_loan_waiting_list_in = 24;
|
||||
t::lib::Mocks::mock_preference( 'PreservationNotForLoanWaitingListIn',
|
||||
$not_for_loan_waiting_list_in );
|
||||
t::lib::Mocks::mock_preference(
|
||||
'PreservationNotForLoanWaitingListIn',
|
||||
$not_for_loan_waiting_list_in
|
||||
);
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/waiting-list/items")
|
||||
->status_is(200)->json_is( [] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/preservation/waiting-list/items")->status_is(200)->json_is( [] );
|
||||
|
||||
# Add items
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items" =>
|
||||
json => [
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items" => json => [
|
||||
{ item_id => $item_1->itemnumber },
|
||||
{ barcode => $item_3->barcode }
|
||||
]
|
||||
|
@ -89,8 +88,7 @@ subtest 'add_item, list, remove_item tests' => sub {
|
|||
is( $item_3->get_from_storage->notforloan, $not_for_loan_waiting_list_in );
|
||||
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items" =>
|
||||
json => [
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items" => json => [
|
||||
{ item_id => $item_2->itemnumber },
|
||||
{ barcode => $item_3->barcode }
|
||||
]
|
||||
|
@ -100,11 +98,11 @@ subtest 'add_item, list, remove_item tests' => sub {
|
|||
is( $item_2->get_from_storage->notforloan, $not_for_loan_waiting_list_in );
|
||||
is( $item_3->get_from_storage->notforloan, $not_for_loan_waiting_list_in );
|
||||
|
||||
$t->delete_ok(
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items/"
|
||||
. $item_2->itemnumber )->status_is(204);
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/preservation/waiting-list/items/" . $item_2->itemnumber )
|
||||
->status_is(204);
|
||||
|
||||
is( $item_2->get_from_storage->notforloan, 0,
|
||||
is(
|
||||
$item_2->get_from_storage->notforloan, 0,
|
||||
"Item removed from the waiting list has its notforloan status back to 0"
|
||||
);
|
||||
|
||||
|
@ -124,10 +122,8 @@ subtest 'add_item, list, remove_item tests' => sub {
|
|||
|
||||
# And try to add it to the waiting list
|
||||
warning_like {
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items" =>
|
||||
json => [ { item_id => $item_1->itemnumber } ] )->status_is(201)
|
||||
->json_is( [] );
|
||||
$t->post_ok( "//$userid:$password@/api/v1/preservation/waiting-list/items" => json =>
|
||||
[ { item_id => $item_1->itemnumber } ] )->status_is(201)->json_is( [] );
|
||||
}
|
||||
qr[Cannot add item to waiting list, it is already in a non-received train];
|
||||
|
||||
|
@ -147,21 +143,17 @@ subtest 'add_item, list, remove_item tests' => sub {
|
|||
$train->received_on(dt_from_string)->store;
|
||||
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items" =>
|
||||
json => [ { item_id => $item_3->itemnumber } ] )->status_is(201)
|
||||
->json_is( [ { item_id => $item_3->itemnumber } ] );
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items" => json => [ { item_id => $item_3->itemnumber } ]
|
||||
)->status_is(201)->json_is( [ { item_id => $item_3->itemnumber } ] );
|
||||
|
||||
$t->delete_ok(
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items/"
|
||||
. $item_2->itemnumber )->status_is(204);
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/preservation/waiting-list/items/" . $item_2->itemnumber )
|
||||
->status_is(204);
|
||||
|
||||
$item_2->delete;
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/waiting-list/items")
|
||||
->status_is(404);
|
||||
$t->delete_ok("//$userid:$password@/api/v1/preservation/waiting-list/items")->status_is(404);
|
||||
|
||||
$t->delete_ok(
|
||||
"//$userid:$password@/api/v1/preservation/waiting-list/items/"
|
||||
. $item_2->itemnumber )->status_is(404);
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/preservation/waiting-list/items/" . $item_2->itemnumber )
|
||||
->status_is(404);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue