Bug 41076: Adjust our perl tidiness for v20250105
Generated using `perl misc/devel/tidy.pl --perl` Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
f06c5fc5e6
commit
849f67988f
|
|
@ -1236,7 +1236,7 @@ sub checkauth {
|
|||
: Koha::Cash::Registers->search(
|
||||
{ branch => $branchcode, branch_default => 1 },
|
||||
{ rows => 1 }
|
||||
)->single;
|
||||
)->single;
|
||||
$register_id = $register->id if ($register);
|
||||
$register_name = $register->name if ($register);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1562,7 +1562,7 @@ sub GetAuthorisedValueDesc {
|
|||
Koha::AuthorisedValues->search(
|
||||
{ category => $category },
|
||||
{ columns => [ 'authorised_value', 'lib_opac', 'lib' ] }
|
||||
)->as_list
|
||||
)->as_list
|
||||
};
|
||||
$cache->set_in_cache( $cache_key, $av_descriptions );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ sub checkauth {
|
|||
# else we have a problem...
|
||||
# get the inputs from the incoming query
|
||||
my @inputs = ();
|
||||
foreach my $name ( param $query) {
|
||||
foreach my $name ( param $query ) {
|
||||
(next) if ( $name eq 'userid' || $name eq 'password' );
|
||||
my $value = $query->param($name);
|
||||
push @inputs, { name => $name, value => $value };
|
||||
|
|
|
|||
|
|
@ -214,8 +214,8 @@ sub GetLettersAvailableForALibrary {
|
|||
}
|
||||
|
||||
return [
|
||||
map { $letters{$_} }
|
||||
sort { $letters{$a}->{name} cmp $letters{$b}->{name} }
|
||||
map { $letters{$_} }
|
||||
sort { $letters{$a}->{name} cmp $letters{$b}->{name} }
|
||||
keys %letters
|
||||
];
|
||||
|
||||
|
|
@ -1211,7 +1211,7 @@ sub GetQueuedMessages {
|
|||
my $params = shift;
|
||||
|
||||
my $dbh = C4::Context->dbh();
|
||||
my $statement = << 'ENDSQL';
|
||||
my $statement = <<'ENDSQL';
|
||||
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, updated_on, failure_code, from_address, to_address, cc_address
|
||||
FROM message_queue
|
||||
ENDSQL
|
||||
|
|
|
|||
11
Koha/Item.pm
11
Koha/Item.pm
|
|
@ -179,7 +179,7 @@ sub store {
|
|||
|
||||
# If the field has changed otherwise, we much update
|
||||
# the 'on' field
|
||||
elsif (exists $updated_columns{$field}
|
||||
elsif ( exists $updated_columns{$field}
|
||||
&& $updated_columns{$field}
|
||||
&& !$pre_mod_item->$field )
|
||||
{
|
||||
|
|
@ -376,7 +376,7 @@ sub safe_to_delete {
|
|||
{
|
||||
itemnumber => undef,
|
||||
}
|
||||
)->count;
|
||||
)->count;
|
||||
|
||||
if ($error) {
|
||||
return Koha::Result::Boolean->new(0)->add_message( { message => $error } );
|
||||
|
|
@ -1525,8 +1525,8 @@ sub columns_to_str {
|
|||
$subfield
|
||||
? $subfield->{authorised_value}
|
||||
? C4::Biblio::GetAuthorisedValueDesc(
|
||||
$itemtagfield,
|
||||
$subfield->{tagsubfield}, $value, '', $tagslib
|
||||
$itemtagfield,
|
||||
$subfield->{tagsubfield}, $value, '', $tagslib
|
||||
)
|
||||
: $value
|
||||
: $value;
|
||||
|
|
@ -1750,7 +1750,8 @@ sub _set_found_trigger {
|
|||
if ($lost_fee_payment) {
|
||||
my $today = dt_from_string();
|
||||
my $payment_age_in_days =
|
||||
dt_from_string( $lost_fee_payment->created_on )->delta_days($today)
|
||||
dt_from_string( $lost_fee_payment->created_on )
|
||||
->delta_days($today)
|
||||
->in_units('days');
|
||||
if ( $payment_age_in_days > $no_refund_if_lost_fee_paid_age ) {
|
||||
$self->add_message(
|
||||
|
|
|
|||
|
|
@ -213,8 +213,11 @@ sub DelPatronsFromList {
|
|||
|
||||
return unless ( $list && $patron_list_patrons );
|
||||
|
||||
return Koha::Database->new()->schema()->resultset('PatronListPatron')
|
||||
->search( { patron_list_patron_id => { 'IN' => $patron_list_patrons } } )->delete();
|
||||
return Koha::Database->new()
|
||||
->schema()
|
||||
->resultset('PatronListPatron')
|
||||
->search( { patron_list_patron_id => { 'IN' => $patron_list_patrons } } )
|
||||
->delete();
|
||||
}
|
||||
|
||||
=head1 AUTHOR
|
||||
|
|
|
|||
|
|
@ -78,8 +78,10 @@ It returns undef if no library limits defined.
|
|||
sub get_library_limits {
|
||||
my ($self) = @_;
|
||||
|
||||
my @branchcodes = $self->_library_limit_rs->search( { $self->_library_limits->{id} => $self->id } )
|
||||
->get_column( $self->_library_limits->{library} )->all();
|
||||
my @branchcodes =
|
||||
$self->_library_limit_rs->search( { $self->_library_limits->{id} => $self->id } )
|
||||
->get_column( $self->_library_limits->{library} )
|
||||
->all();
|
||||
|
||||
return unless @branchcodes;
|
||||
|
||||
|
|
|
|||
|
|
@ -1088,7 +1088,7 @@ sub set_password {
|
|||
module => 'members',
|
||||
letter_code => 'PASSWORD_CHANGE',
|
||||
branchcode => $self_from_storage->branchcode,
|
||||
,
|
||||
|
||||
lang => $self_from_storage->lang || 'default',
|
||||
tables => {
|
||||
'branches' => $self_from_storage->branchcode,
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ LINE: while ( my $borrowerline = <$handle> ) {
|
|||
my $letter = GetPreparedLetter(
|
||||
module => 'members',
|
||||
letter_code => 'WELCOME',
|
||||
branchcode => $patron->branchcode,,
|
||||
branchcode => $patron->branchcode,
|
||||
lang => $patron->lang || 'default',
|
||||
tables => {
|
||||
'branches' => $patron->branchcode,
|
||||
|
|
|
|||
|
|
@ -235,8 +235,8 @@ sub GetPlugins {
|
|||
{
|
||||
enable_plugins => $self->{'enable_plugins'}
|
||||
|
||||
# loads even if plugins are disabled
|
||||
# FIXME: is this for testing without bothering to mock config?
|
||||
# loads even if plugins are disabled
|
||||
# FIXME: is this for testing without bothering to mock config?
|
||||
}
|
||||
);
|
||||
} catch {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ sub is_valid {
|
|||
cardnumber => $cardnumber,
|
||||
( $patron ? ( borrowernumber => { '!=' => $patron->borrowernumber } ) : () )
|
||||
}
|
||||
)->count;
|
||||
)->count;
|
||||
|
||||
my ( $min_length, $max_length ) = $class->get_valid_length();
|
||||
return Koha::Result::Boolean->new(0)->add_message( { message => "invalid_length" } )
|
||||
|
|
|
|||
|
|
@ -102,8 +102,10 @@ sub add {
|
|||
|
||||
if ( $max_total and $days_range ) {
|
||||
|
||||
my $total = Koha::Suggestions->search( { suggestedby => $body->{suggested_by} } )
|
||||
->filter_by_suggested_days_range($days_range)->count;
|
||||
my $total =
|
||||
Koha::Suggestions->search( { suggestedby => $body->{suggested_by} } )
|
||||
->filter_by_suggested_days_range($days_range)
|
||||
->count;
|
||||
|
||||
if ( $total >= $max_total ) {
|
||||
return $c->render(
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ sub _extra_column_info {
|
|||
$extra_info{extra}{list} = $dbi_info->{mysql_values};
|
||||
}
|
||||
if (
|
||||
( not blessed $dbi_info) # isa $sth
|
||||
( not blessed $dbi_info ) # isa $sth
|
||||
&& lc( $dbi_info->{COLUMN_DEF} ) =~ m/^current_timestamp/
|
||||
&& lc( $dbi_info->{mysql_type_name} ) eq 'timestamp'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -74,7 +74,9 @@ sub subscribers {
|
|||
my ($self) = @_;
|
||||
my $schema = Koha::Database->new->schema;
|
||||
my @borrowernumbers =
|
||||
$schema->resultset('Alert')->search( { externalid => $self->subscriptionid } )->get_column('borrowernumber')
|
||||
$schema->resultset('Alert')
|
||||
->search( { externalid => $self->subscriptionid } )
|
||||
->get_column('borrowernumber')
|
||||
->all;
|
||||
return Koha::Patrons->search( { borrowernumber => { -in => \@borrowernumbers } } );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ sub store {
|
|||
category => 'SUGGEST_STATUS',
|
||||
authorised_value => $self->STATUS
|
||||
}
|
||||
)->count;
|
||||
)->count;
|
||||
|
||||
$self->branchcode(undef) if defined $self->branchcode && $self->branchcode eq '';
|
||||
unless ( $self->suggesteddate() ) {
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ sub count {
|
|||
|
||||
sub result {
|
||||
my ($self) = @_;
|
||||
my @a = map { $self->{files}->{$_}->{id} }
|
||||
my @a = map { $self->{files}->{$_}->{id} }
|
||||
grep { !exists $self->{files}->{$_}->{errcode} }
|
||||
keys %{ $self->{files} };
|
||||
return @a ? ( join ',', @a ) : undef;
|
||||
|
|
|
|||
28
Makefile.PL
28
Makefile.PL
|
|
@ -340,8 +340,8 @@ my $target_map = {
|
|||
'./members' => 'INTRANET_CGI_DIR',
|
||||
'./misc' => { target => 'SCRIPT_NONDEV_DIR', trimdir => -1 },
|
||||
'./misc/bin' => { target => 'SCRIPT_DIR', trimdir => -1 },
|
||||
'./misc/release_notes' => { target => 'DOC_DIR', trimdir => 2 },
|
||||
'./misc/translator' => { target => 'MISC_DIR', trimdir => 2 },
|
||||
'./misc/release_notes' => { target => 'DOC_DIR', trimdir => 2 },
|
||||
'./misc/translator' => { target => 'MISC_DIR', trimdir => 2 },
|
||||
'./misc/koha-install-log' => { target => 'MISC_DIR', trimdir => -1 },
|
||||
'./misc/installer_devel_notes' => 'NONE',
|
||||
'./opac' => 'OPAC_CGI_DIR',
|
||||
|
|
@ -368,18 +368,18 @@ my $target_map = {
|
|||
'./skel/var/log/koha' => { target => 'LOG_DIR', trimdir => -1 },
|
||||
'./skel/var/spool/koha' => { target => 'BACKUP_DIR', trimdir => -1 },
|
||||
'./skel/var/run/koha/zebradb' => { target => 'ZEBRA_RUN_DIR', trimdir => -1 },
|
||||
'./skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/authorities/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/authorities/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/authorities/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/authorities/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lock/koha/zebradb/biblios' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/biblios/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/biblios/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/biblios/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/biblios/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lock/koha/zebradb/rebuild' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 },
|
||||
'./skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/authorities/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/authorities/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/authorities/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/authorities/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lock/koha/zebradb/biblios' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/biblios/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/biblios/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/biblios/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/zebradb/biblios/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
|
||||
'./skel/var/lock/koha/zebradb/rebuild' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
|
||||
'./skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 },
|
||||
'./sms' => 'INTRANET_CGI_DIR',
|
||||
'./suggestion' => 'INTRANET_CGI_DIR',
|
||||
'./svc' => 'INTRANET_CGI_DIR',
|
||||
|
|
|
|||
|
|
@ -178,9 +178,11 @@ if ( $op eq 'add_form' ) {
|
|||
|
||||
# This basket was created from an EDI order/quote
|
||||
# Check if the vendor EDI account is configured to use purchase order numbers
|
||||
my $schema = Koha::Database->new()->schema();
|
||||
my $vendor_edi_account = $schema->resultset('VendorEdiAccount')
|
||||
->search( { vendor_id => scalar $input->param('basketbooksellerid') } )->first;
|
||||
my $schema = Koha::Database->new()->schema();
|
||||
my $vendor_edi_account =
|
||||
$schema->resultset('VendorEdiAccount')
|
||||
->search( { vendor_id => scalar $input->param('basketbooksellerid') } )
|
||||
->first;
|
||||
|
||||
if ( $vendor_edi_account && $vendor_edi_account->po_is_basketname ) {
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ sub _get_chunk {
|
|||
@values = split /,/, $value if defined($value);
|
||||
$chunk->{'CHOICES'} = [
|
||||
sort { $a->{'text'} cmp $b->{'text'} }
|
||||
map {
|
||||
map {
|
||||
my $c = $_;
|
||||
{
|
||||
text => $options{'choices'}->{$c},
|
||||
|
|
@ -190,7 +190,7 @@ sub _get_chunk {
|
|||
$chunk->{type} = 'multiple';
|
||||
$chunk->{CHOICES} = [
|
||||
sort { $a->{'text'} cmp $b->{'text'} }
|
||||
map {
|
||||
map {
|
||||
my $option_value = $_;
|
||||
{
|
||||
text => $options{multiple}->{$option_value},
|
||||
|
|
|
|||
|
|
@ -144,12 +144,12 @@ if ($backends_available) {
|
|||
$op = 'historycheck';
|
||||
$template->param( $history_check->history_check_template_params($params) )
|
||||
|
||||
# ILLCheckAvailability operation
|
||||
# ILLCheckAvailability operation
|
||||
} elsif ( $availability->show_availability($request) ) {
|
||||
$op = 'availability';
|
||||
$template->param( $availability->availability_template_params($params) )
|
||||
|
||||
# ILLModuleDisclaimerByType operation
|
||||
# ILLModuleDisclaimerByType operation
|
||||
} elsif ( $type_disclaimer->show_type_disclaimer($request) ) {
|
||||
$op = 'typedisclaimer';
|
||||
$template->param( $type_disclaimer->type_disclaimer_template_params($params) );
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ return {
|
|||
)[0] == 0
|
||||
)
|
||||
{ # Check to make idempotent
|
||||
my $cc_template = <<~ 'END_TEMPLATE';
|
||||
my $cc_template = <<~'END_TEMPLATE';
|
||||
**Describe the concern**
|
||||
A clear and concise description of what the concern is.
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ GetOptions(
|
|||
'p|print' => \$stdout_log
|
||||
);
|
||||
|
||||
my $usage = << 'ENDUSAGE';
|
||||
my $usage = <<'ENDUSAGE';
|
||||
|
||||
Script for fixing unclosed (FU), non accruing fine records, which
|
||||
may still need FU -> F correction post-Bug 15675. For details,
|
||||
|
|
|
|||
|
|
@ -2136,7 +2136,7 @@ VALUES
|
|||
('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo')
|
||||
END_SQL
|
||||
|
||||
$dbh->do( <<'END_SQL');
|
||||
$dbh->do(<<'END_SQL');
|
||||
INSERT INTO `letter`
|
||||
(module, code, name, title, content)
|
||||
VALUES
|
||||
|
|
@ -3682,7 +3682,7 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
|
|||
|
||||
$DBversion = '3.01.00.080';
|
||||
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
|
||||
$dbh->do(<<BUDG_PERM );
|
||||
$dbh->do(<<BUDG_PERM);
|
||||
INSERT INTO permissions (module_bit, code, description) VALUES
|
||||
(11, 'vendors_manage', 'Manage vendors'),
|
||||
(11, 'contracts_manage', 'Manage contracts'),
|
||||
|
|
|
|||
|
|
@ -415,7 +415,7 @@ if ( $step && $step == 1 ) {
|
|||
my $cmd = C4::Context->config("intranetdir")
|
||||
. "/installer/data/$info{dbms}/updatedatabase.pl >> $logfilepath 2>> $logfilepath_errors";
|
||||
|
||||
system($cmd );
|
||||
system($cmd);
|
||||
|
||||
my $fh;
|
||||
open( $fh, "<:encoding(utf-8)", $logfilepath )
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ if ( $op eq 'cud-add' ) {
|
|||
borrowernumber => $borrowernumber
|
||||
},
|
||||
{ order_by => { -desc => 'returndate' }, rows => 1 }
|
||||
)->next;
|
||||
)->next;
|
||||
$issue_id = $checkout ? $checkout->issue_id : undef;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -301,7 +301,8 @@ if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && $guarantors_to_be_validated
|
|||
# If $patron's categorycode is about to change, check guarantor requirements against
|
||||
# the new category but keep the original $patron object intact
|
||||
# (this clone()s the $patron)
|
||||
( bless {%$patron}, ref $patron )->categorycode($categorycode)
|
||||
( bless {%$patron}, ref $patron )
|
||||
->categorycode($categorycode)
|
||||
->can_be_guaranteed_by($guarantors_to_be_validated);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -516,7 +517,7 @@ if ( ( !$nok ) and $nodouble and ( $op eq 'cud-insert' or $op eq 'cud-save' ) )
|
|||
my $letter = GetPreparedLetter(
|
||||
module => 'members',
|
||||
letter_code => 'WELCOME',
|
||||
branchcode => $patron->branchcode,,
|
||||
branchcode => $patron->branchcode,
|
||||
lang => $patron->lang || 'default',
|
||||
tables => {
|
||||
'branches' => $patron->branchcode,
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ if ( $op eq 'send_welcome' ) {
|
|||
my $letter = GetPreparedLetter(
|
||||
module => 'members',
|
||||
letter_code => 'WELCOME',
|
||||
branchcode => $patron->branchcode,,
|
||||
branchcode => $patron->branchcode,
|
||||
lang => $patron->lang || 'default',
|
||||
tables => {
|
||||
'branches' => $patron->branchcode,
|
||||
|
|
@ -99,7 +99,7 @@ if ( $op eq 'send_welcome' ) {
|
|||
my $print = GetPreparedLetter(
|
||||
module => 'members',
|
||||
letter_code => 'WELCOME',
|
||||
branchcode => $patron->branchcode,,
|
||||
branchcode => $patron->branchcode,
|
||||
lang => $patron->lang || 'default',
|
||||
tables => {
|
||||
'branches' => $patron->branchcode,
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ cronlogaction( { info => $command_line_options } );
|
|||
|
||||
GetOptions( 'h|hours=s' => \$hours, );
|
||||
|
||||
my $usage = << 'ENDUSAGE';
|
||||
my $usage = <<'ENDUSAGE';
|
||||
cart_to_shelf.pl: This cron script will set any item of the location CART ( Shelving Cart ) to it's original shelving location
|
||||
after the given number of hours has passed.
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ GetOptions(
|
|||
'm|maxdays:i' => \$maxdays,
|
||||
'i|verifyissue' => \$verify_issue,
|
||||
);
|
||||
my $usage = << 'ENDUSAGE';
|
||||
my $usage = <<'ENDUSAGE';
|
||||
|
||||
This script calculates and charges overdue fines
|
||||
to patron accounts. The Koha system preference 'finesMode' controls
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ GetOptions(
|
|||
'l|list' => \$list,
|
||||
'f|force' => \$force,
|
||||
);
|
||||
my $usage = << 'ENDUSAGE';
|
||||
my $usage = <<'ENDUSAGE';
|
||||
|
||||
This script starts an OAI Harvest
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ GetOptions(
|
|||
'w|where:s' => \$where,
|
||||
'e|exit-on-plugin-failure' => \$exit_on_plugin_failure,
|
||||
);
|
||||
my $usage = << 'ENDUSAGE';
|
||||
my $usage = <<'ENDUSAGE';
|
||||
|
||||
This script processes the message queue in the message_queue database
|
||||
table. It sends out the messages in that queue and marks them
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ GetOptions(
|
|||
'v|verbose' => \$verbose,
|
||||
);
|
||||
|
||||
my $usage = << 'ENDUSAGE';
|
||||
my $usage = <<'ENDUSAGE';
|
||||
This script deletes old suggestions
|
||||
Parameters:
|
||||
-help|? This message
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ GetOptions(
|
|||
'u|use-borrower-library' => \$useborrowerlibrary,
|
||||
'b|borrower:i' => \$borrowernumberlimit
|
||||
);
|
||||
my $usage = << 'ENDUSAGE';
|
||||
my $usage = <<'ENDUSAGE';
|
||||
|
||||
This script calculates and charges overdue fines to patron accounts.
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ GetOptions(
|
|||
'source-value=s' => $subfield_source_value,
|
||||
);
|
||||
|
||||
my $usage = << 'ENDUSAGE';
|
||||
my $usage = <<'ENDUSAGE';
|
||||
import_lexile.pl: Import lexile scores for records from csv.
|
||||
|
||||
import_lexile.pl -f /path/to/LexileTitles.txt
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ if ( $#ARGV >= 3 && !caller ) { # process command-line params only if not cal
|
|||
if ( !$file ) {
|
||||
my $marcxml = $svc->get($biblionumber);
|
||||
my $file = "bib-$biblionumber.xml";
|
||||
write_file $file , $marcxml;
|
||||
write_file $file, $marcxml;
|
||||
print "saved $file ", -s $file, " bytes\n";
|
||||
print $marcxml;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -71,8 +71,8 @@ sub new {
|
|||
filename => $filename,
|
||||
_parser => $parser
|
||||
|
||||
# , handle => $handle
|
||||
# , readahead => []
|
||||
# , handle => $handle
|
||||
# , readahead => []
|
||||
},
|
||||
__PACKAGE__;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ if ( $op eq 'cud-create' ) {
|
|||
my $letter = GetPreparedLetter(
|
||||
module => 'members',
|
||||
letter_code => 'WELCOME',
|
||||
branchcode => $patron->branchcode,,
|
||||
branchcode => $patron->branchcode,
|
||||
lang => $patron->lang || 'default',
|
||||
tables => {
|
||||
'branches' => $patron->branchcode,
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ if ( $rego_found
|
|||
my $letter = GetPreparedLetter(
|
||||
module => 'members',
|
||||
letter_code => 'WELCOME',
|
||||
branchcode => $patron->branchcode,,
|
||||
branchcode => $patron->branchcode,
|
||||
lang => $patron->lang || 'default',
|
||||
tables => {
|
||||
'branches' => $patron->branchcode,
|
||||
|
|
|
|||
|
|
@ -341,7 +341,8 @@ if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold )
|
|||
|
||||
if ( $patron && $multi_hold ) {
|
||||
my @multi_pickup_locations =
|
||||
Koha::Biblios->search( { biblionumber => \@biblionumbers } )->pickup_locations( { patron => $patron } )
|
||||
Koha::Biblios->search( { biblionumber => \@biblionumbers } )
|
||||
->pickup_locations( { patron => $patron } )
|
||||
->as_list;
|
||||
$template->param( multi_pickup_locations => \@multi_pickup_locations );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ find(
|
|||
}
|
||||
},
|
||||
},
|
||||
,
|
||||
|
||||
File::Spec->curdir()
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ my $mock_line_data = {
|
|||
sub_location_code => 'REFERENCE', # LSL field
|
||||
branch => 'BRANCH2'
|
||||
|
||||
# sequence_code missing for this item
|
||||
# sequence_code missing for this item
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -391,30 +391,32 @@ subtest 'extract_reserved_params() tests' => sub {
|
|||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->get_ok('/query?_page=2&_per_page=3&firstname=Manuel&surname=Cohen%20Arazi')->status_is(200)
|
||||
$t->get_ok('/query?_page=2&_per_page=3&firstname=Manuel&surname=Cohen%20Arazi')
|
||||
->status_is(200)
|
||||
->json_is( '/filtered_params' => { firstname => 'Manuel', surname => 'Cohen Arazi' } )
|
||||
->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } );
|
||||
|
||||
$t->get_ok(
|
||||
'/query_full/with/path?_match=exact&_order_by=blah&_page=2&_per_page=3&firstname=Manuel&surname=Cohen%20Arazi')
|
||||
->status_is(200)->json_is(
|
||||
->status_is(200)
|
||||
->json_is(
|
||||
'/filtered_params' => {
|
||||
firstname => 'Manuel',
|
||||
surname => 'Cohen Arazi'
|
||||
}
|
||||
)->json_is(
|
||||
)->json_is(
|
||||
'/reserved_params' => {
|
||||
_page => 2,
|
||||
_per_page => 3,
|
||||
_match => 'exact',
|
||||
_order_by => 'blah'
|
||||
}
|
||||
)->json_is(
|
||||
)->json_is(
|
||||
'/path_params' => {
|
||||
id => 'with',
|
||||
subid => 'path'
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -424,8 +426,11 @@ subtest 'dbic_merge_sorting() tests' => sub {
|
|||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->get_ok('/dbic_merge_sorting')->status_is(200)->json_is( '/a' => 'a', 'Existing values are kept (a)' )
|
||||
->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is(
|
||||
$t->get_ok('/dbic_merge_sorting')
|
||||
->status_is(200)
|
||||
->json_is( '/a' => 'a', 'Existing values are kept (a)' )
|
||||
->json_is( '/b' => 'b', 'Existing values are kept (b)' )
|
||||
->json_is(
|
||||
'/order_by' => [
|
||||
'uno',
|
||||
{ -desc => 'dos' },
|
||||
|
|
@ -434,9 +439,11 @@ subtest 'dbic_merge_sorting() tests' => sub {
|
|||
]
|
||||
);
|
||||
|
||||
$t->get_ok('/dbic_merge_sorting_result_set')->status_is(200)
|
||||
$t->get_ok('/dbic_merge_sorting_result_set')
|
||||
->status_is(200)
|
||||
->json_is( '/a' => 'a', 'Existing values are kept (a)' )
|
||||
->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is(
|
||||
->json_is( '/b' => 'b', 'Existing values are kept (b)' )
|
||||
->json_is(
|
||||
'/order_by' => [
|
||||
'city_name',
|
||||
{ -desc => 'city_zipcode' },
|
||||
|
|
@ -445,12 +452,17 @@ subtest 'dbic_merge_sorting() tests' => sub {
|
|||
]
|
||||
);
|
||||
|
||||
$t->get_ok('/dbic_merge_sorting_date')->status_is(200)->json_is( '/a' => 'a', 'Existing values are kept (a)' )
|
||||
$t->get_ok('/dbic_merge_sorting_date')
|
||||
->status_is(200)
|
||||
->json_is( '/a' => 'a', 'Existing values are kept (a)' )
|
||||
->json_is( '/b' => 'b', 'Existing values are kept (b)' )
|
||||
->json_is( '/order_by' => [ { -desc => 'reservedate' } ] );
|
||||
|
||||
$t->get_ok('/dbic_merge_sorting_single')->status_is(200)->json_is( '/a' => 'a', 'Existing values are kept (a)' )
|
||||
->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is( '/order_by' => [ { '-desc' => 'uno' } ] );
|
||||
$t->get_ok('/dbic_merge_sorting_single')
|
||||
->status_is(200)
|
||||
->json_is( '/a' => 'a', 'Existing values are kept (a)' )
|
||||
->json_is( '/b' => 'b', 'Existing values are kept (b)' )
|
||||
->json_is( '/order_by' => [ { '-desc' => 'uno' } ] );
|
||||
};
|
||||
|
||||
subtest '/dbic_merge_prefetch' => sub {
|
||||
|
|
@ -458,7 +470,9 @@ subtest '/dbic_merge_prefetch' => sub {
|
|||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->get_ok('/dbic_merge_prefetch')->status_is(200)->json_is( '/prefetch/0' => { 'biblio' => 'orders' } )
|
||||
$t->get_ok('/dbic_merge_prefetch')
|
||||
->status_is(200)
|
||||
->json_is( '/prefetch/0' => { 'biblio' => 'orders' } )
|
||||
->json_is( '/prefetch/1' => 'item' );
|
||||
|
||||
$t->get_ok('/dbic_merge_prefetch_recursive')->status_is(200)->json_is(
|
||||
|
|
@ -519,23 +533,28 @@ subtest '_build_query_params_from_api' => sub {
|
|||
my $t = Test::Mojo->new;
|
||||
|
||||
# _match => contains
|
||||
$t->get_ok('/build_query?_match=contains&title=Ender&author=Orson')->status_is(200)
|
||||
$t->get_ok('/build_query?_match=contains&title=Ender&author=Orson')
|
||||
->status_is(200)
|
||||
->json_is( '/query' => { author => { like => '%Orson%' }, title => { like => '%Ender%' } } );
|
||||
|
||||
# _match => starts_with
|
||||
$t->get_ok('/build_query?_match=starts_with&title=Ender&author=Orson')->status_is(200)
|
||||
$t->get_ok('/build_query?_match=starts_with&title=Ender&author=Orson')
|
||||
->status_is(200)
|
||||
->json_is( '/query' => { author => { like => 'Orson%' }, title => { like => 'Ender%' } } );
|
||||
|
||||
# _match => ends_with
|
||||
$t->get_ok('/build_query?_match=ends_with&title=Ender&author=Orson')->status_is(200)
|
||||
$t->get_ok('/build_query?_match=ends_with&title=Ender&author=Orson')
|
||||
->status_is(200)
|
||||
->json_is( '/query' => { author => { like => '%Orson' }, title => { like => '%Ender' } } );
|
||||
|
||||
# _match => exact
|
||||
$t->get_ok('/build_query?_match=exact&title=Ender&author=Orson')->status_is(200)
|
||||
$t->get_ok('/build_query?_match=exact&title=Ender&author=Orson')
|
||||
->status_is(200)
|
||||
->json_is( '/query' => { author => 'Orson', title => 'Ender' } );
|
||||
|
||||
# _match => blah
|
||||
$t->get_ok('/build_query?_match=blah&title=Ender&author=Orson')->status_is(400)
|
||||
$t->get_ok('/build_query?_match=blah&title=Ender&author=Orson')
|
||||
->status_is(400)
|
||||
->json_is( '/exception_msg' => 'Invalid value for _match param (blah)' )
|
||||
->json_is( '/exception_type' => 'Koha::Exceptions::WrongParameter' );
|
||||
|
||||
|
|
@ -580,7 +599,8 @@ subtest 'stash_embed() tests' => sub {
|
|||
}
|
||||
)->json_is( '/strings' => 1 );
|
||||
|
||||
$t->get_ok( '/stash_embed_no_spec' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } )->status_is(400)
|
||||
$t->get_ok( '/stash_embed_no_spec' => { 'x-koha-embed' => 'checkouts,checkouts.item,patron' } )
|
||||
->status_is(400)
|
||||
->json_is( '/error' =>
|
||||
qq{Exception 'Koha::Exceptions::BadParameter' thrown 'Embedding objects is not allowed on this endpoint.'\n}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ my $dt_1 = dt_from_string($date_1);
|
|||
my $dt_2 = dt_from_string($date_2);
|
||||
|
||||
is( t::lib::Dates::compare( $dt_1, $dt_2 ), -1, '2017 is before 2018' );
|
||||
is( t::lib::Dates::compare( $dt_2, $dt_1 ), 1, '2018 is after 2017' );
|
||||
is( t::lib::Dates::compare( $dt_2, $dt_1 ), 1, '2018 is after 2017' );
|
||||
|
||||
is( t::lib::Dates::compare( $date_1, $date_2 ), -1, '2017 is before 2018 (strings comparison)' );
|
||||
is( t::lib::Dates::compare( $date_2, $date_1 ), 1, '2018 is after 2017 (strings comparison)' );
|
||||
is( t::lib::Dates::compare( $date_2, $date_1 ), 1, '2018 is after 2017 (strings comparison)' );
|
||||
|
||||
my $dt_3 = $dt_1->clone->subtract( seconds => 5 );
|
||||
is(
|
||||
|
|
|
|||
|
|
@ -168,7 +168,8 @@ subtest "get_login_shib tests" => sub {
|
|||
|
||||
my $login = get_login_shib();
|
||||
$logger->debug_is( "koha borrower field to match: userid", "borrower match field debug info" )
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )->clear();
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )
|
||||
->clear();
|
||||
is( $login, "test1234", "good config, attribute value returned" );
|
||||
};
|
||||
|
||||
|
|
@ -207,7 +208,8 @@ subtest "checkpw_shib tests" => sub {
|
|||
is( ref($retpatron), 'Koha::Patron', "expected Koha::Patron object returned" );
|
||||
|
||||
$logger->debug_is( "koha borrower field to match: userid", "borrower match field debug info" )
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )->clear();
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )
|
||||
->clear();
|
||||
|
||||
# bad user
|
||||
$shib_login = 'martin';
|
||||
|
|
@ -217,7 +219,8 @@ subtest "checkpw_shib tests" => sub {
|
|||
is( $retuserid, undef );
|
||||
is( $retpatron, undef );
|
||||
$logger->debug_is( "koha borrower field to match: userid", "borrower match field debug info" )
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )->clear();
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )
|
||||
->clear();
|
||||
|
||||
# duplicated matchpoint
|
||||
change_config( { matchpoint => 'email', mapping => { email => { is => 'email' } } } );
|
||||
|
|
@ -228,7 +231,8 @@ subtest "checkpw_shib tests" => sub {
|
|||
is( $retuserid, undef );
|
||||
is( $retpatron, undef );
|
||||
$logger->debug_is( "koha borrower field to match: email", "borrower match field debug info" )
|
||||
->debug_is( "shibboleth attribute to match: email", "shib match attribute debug info" )->clear();
|
||||
->debug_is( "shibboleth attribute to match: email", "shib match attribute debug info" )
|
||||
->clear();
|
||||
|
||||
( $retval, $retcard, $retuserid, $retpatron ) = checkpw_shib($shib_login);
|
||||
is( $retval, 0 );
|
||||
|
|
@ -236,10 +240,11 @@ subtest "checkpw_shib tests" => sub {
|
|||
is( $retuserid, undef );
|
||||
is( $retpatron, undef );
|
||||
$logger->debug_is( "koha borrower field to match: email", "borrower match field debug info" )
|
||||
->debug_is( "shibboleth attribute to match: email", "shib match attribute debug info" )->warn_is(
|
||||
->debug_is( "shibboleth attribute to match: email", "shib match attribute debug info" )
|
||||
->warn_is(
|
||||
'There are several users with email of kid@clamp.io, matchpoints must be unique',
|
||||
"duplicated matchpoint warned with debug"
|
||||
)->clear();
|
||||
)->clear();
|
||||
|
||||
# autocreate user (welcome)
|
||||
change_config( { autocreate => 1, welcome => 1 } );
|
||||
|
|
@ -261,7 +266,8 @@ subtest "checkpw_shib tests" => sub {
|
|||
is( $retuserid, "test4321", "expected userid returned" );
|
||||
is( ref($retpatron), 'Koha::Patron', "expected Koha::Patron object returned" );
|
||||
$logger->debug_is( "koha borrower field to match: userid", "borrower match field debug info" )
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )->clear();
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )
|
||||
->clear();
|
||||
|
||||
ok my $new_user = $schema->resultset('Borrower')->search( { 'userid' => 'test4321' }, { rows => 1 } ),
|
||||
"new user found";
|
||||
|
|
@ -280,7 +286,8 @@ subtest "checkpw_shib tests" => sub {
|
|||
is( $retuserid, $shib_login, "expected userid returned" );
|
||||
is( ref($retpatron), 'Koha::Patron', "expected Koha::Patron object returned" );
|
||||
$logger->debug_is( "koha borrower field to match: userid", "borrower match field debug info" )
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )->clear();
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )
|
||||
->clear();
|
||||
|
||||
ok my $sync_user = $schema->resultset('Borrower')->search( { 'userid' => 'test4321' }, { rows => 1 } ),
|
||||
"sync user found";
|
||||
|
|
@ -301,7 +308,8 @@ subtest "checkpw_shib tests" => sub {
|
|||
is( $retuserid, "test1234", "expected userid returned" );
|
||||
is( ref($retpatron), 'Koha::Patron', "expected Koha::Patron object returned" );
|
||||
$logger->debug_is( "koha borrower field to match: userid", "borrower match field debug info" )
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )->clear();
|
||||
->debug_is( "shibboleth attribute to match: uid", "shib match attribute debug info" )
|
||||
->clear();
|
||||
|
||||
# bad user
|
||||
$shib_login = "martin";
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ $dbh->do('DELETE FROM special_holidays');
|
|||
$dbh->do('DELETE FROM repeatable_holidays');
|
||||
|
||||
my $daysago20 = dt_from_string->add_duration( DateTime::Duration->new( days => -20 ) );
|
||||
my $daysafter40 = dt_from_string->add_duration( DateTime::Duration->new( days => 40 ) );
|
||||
my $daysafter40 = dt_from_string->add_duration( DateTime::Duration->new( days => 40 ) );
|
||||
|
||||
AddIssue( $patron, $barcode, $daysago20 );
|
||||
AddReturn( $barcode, $branchcode );
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ sub run_hiding_tests {
|
|||
my @valid_hidden_values = ( -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8 );
|
||||
|
||||
my $hidden = {
|
||||
'opac' => [ -8, 1, 2, 3, 4, 5, 6, 7, 8 ],
|
||||
'opac' => [ -8, 1, 2, 3, 4, 5, 6, 7, 8 ],
|
||||
'intranet' => [ -8, -7, -4, -3, -2, 2, 3, 5, 8 ]
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -358,7 +358,8 @@ subtest "delete() tests" => sub {
|
|||
|
||||
my $number_of_logs =
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'HOLDS', action => 'DELETE', object => $hold->{reserve_id} } )->count;
|
||||
->search( { module => 'HOLDS', action => 'DELETE', object => $hold->{reserve_id} } )
|
||||
->count;
|
||||
is( $number_of_logs, 0, 'With HoldsLogs, Koha::Hold->delete shouldn\'t have been logged' );
|
||||
|
||||
# Enable logging
|
||||
|
|
@ -379,7 +380,8 @@ subtest "delete() tests" => sub {
|
|||
|
||||
$number_of_logs =
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'HOLDS', action => 'DELETE', object => $hold->{reserve_id} } )->count;
|
||||
->search( { module => 'HOLDS', action => 'DELETE', object => $hold->{reserve_id} } )
|
||||
->count;
|
||||
is( $number_of_logs, 1, 'With HoldsLogs, Koha::Hold->delete should have been logged' );
|
||||
|
||||
$schema->storage->txn_rollback();
|
||||
|
|
@ -471,7 +473,8 @@ subtest 'suspend() tests' => sub {
|
|||
t::lib::Mocks::mock_preference( 'HoldsLog', 1 );
|
||||
|
||||
my $logs_count =
|
||||
$schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'SUSPEND', object => $hold->id } )
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'HOLDS', action => 'SUSPEND', object => $hold->id } )
|
||||
->count;
|
||||
|
||||
$hold = $builder->build_object(
|
||||
|
|
@ -483,7 +486,8 @@ subtest 'suspend() tests' => sub {
|
|||
|
||||
$hold->suspend_hold;
|
||||
my $new_logs_count =
|
||||
$schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'SUSPEND', object => $hold->id } )
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'HOLDS', action => 'SUSPEND', object => $hold->id } )
|
||||
->count;
|
||||
|
||||
is( $new_logs_count, $logs_count + 1, 'If logging is enabled, suspending a hold gets logged' );
|
||||
|
|
|
|||
|
|
@ -273,8 +273,8 @@ test_allocation(
|
|||
test_allocation(
|
||||
"different costs 1",
|
||||
[
|
||||
[ 0, 2, 2 ],
|
||||
[ 1, 0, 1 ],
|
||||
[ 0, 2, 2 ],
|
||||
[ 1, 0, 1 ],
|
||||
[ -1, -1, 0 ]
|
||||
],
|
||||
[ 3, 3, 0 ],
|
||||
|
|
@ -286,8 +286,8 @@ test_allocation(
|
|||
test_allocation(
|
||||
"different costs 2",
|
||||
[
|
||||
[ 0, 2, 2 ],
|
||||
[ 1, 0, 1 ],
|
||||
[ 0, 2, 2 ],
|
||||
[ 1, 0, 1 ],
|
||||
[ -1, -1, 0 ]
|
||||
],
|
||||
[ 2, 2, 0 ],
|
||||
|
|
@ -299,8 +299,8 @@ test_allocation(
|
|||
test_allocation(
|
||||
"allocation prohibited",
|
||||
[
|
||||
[ 0, -1 ],
|
||||
[ -1, 0 ],
|
||||
[ 0, -1 ],
|
||||
[ -1, 0 ],
|
||||
],
|
||||
[ 2, 0 ],
|
||||
[ 0, 2 ],
|
||||
|
|
@ -311,9 +311,9 @@ test_allocation(
|
|||
test_allocation(
|
||||
"some allocation prohibited",
|
||||
[
|
||||
[ 0, -1, -1 ],
|
||||
[ -1, 0, 1 ],
|
||||
[ -1, -1, 0 ]
|
||||
[ 0, -1, -1 ],
|
||||
[ -1, 0, 1 ],
|
||||
[ -1, -1, 0 ]
|
||||
],
|
||||
[ 2, 2, 0 ],
|
||||
[ 0, 0, 4 ],
|
||||
|
|
@ -337,11 +337,11 @@ test_allocation(
|
|||
test_allocation(
|
||||
"prefer fewer fails",
|
||||
[
|
||||
[ 0, 1, 1, 1, 1 ],
|
||||
[ -1, 0, -1, -1, 1 ],
|
||||
[ -1, -1, 0, -1, -1 ],
|
||||
[ -1, -1, -1, 0, -1 ],
|
||||
[ -1, -1, -1, -1, 0 ]
|
||||
[ 0, 1, 1, 1, 1 ],
|
||||
[ -1, 0, -1, -1, 1 ],
|
||||
[ -1, -1, 0, -1, -1 ],
|
||||
[ -1, -1, -1, 0, -1 ],
|
||||
[ -1, -1, -1, -1, 0 ]
|
||||
],
|
||||
[ 1, 1, 0, 0, 0 ],
|
||||
[ 0, 0, 1, 1, 1 ],
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ subtest 'outstanding_debits() tests' => sub {
|
|||
{
|
||||
borrowernumber => $patron_4->id,
|
||||
amount => -3,
|
||||
amountoutstanding => 3,
|
||||
amountoutstanding => 3,
|
||||
interface => 'commandline',
|
||||
credit_type_code => 'PAYMENT'
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ subtest 'outstanding_credits() tests' => sub {
|
|||
Koha::Account::Line->new(
|
||||
{
|
||||
borrowernumber => $patron_2->id,
|
||||
amount => 2,
|
||||
amount => 2,
|
||||
amountoutstanding => -3,
|
||||
interface => 'commandline',
|
||||
debit_type_code => 'OVERDUE'
|
||||
|
|
@ -544,13 +544,13 @@ subtest 'reconcile_balance' => sub {
|
|||
)->store;
|
||||
|
||||
is( $account->balance(), -5, "Account balance is -5" );
|
||||
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
|
||||
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
|
||||
is( $account->outstanding_credits->total_outstanding, -15, 'Outstanding credits sum -15' );
|
||||
|
||||
$account->reconcile_balance();
|
||||
|
||||
is( $account->balance(), -5, "Account balance is -5" );
|
||||
is( $account->outstanding_debits->total_outstanding, 0, 'No outstanding debits' );
|
||||
is( $account->outstanding_debits->total_outstanding, 0, 'No outstanding debits' );
|
||||
is( $account->outstanding_credits->total_outstanding, -5, 'Outstanding credits sum -5' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -597,8 +597,8 @@ subtest 'reconcile_balance' => sub {
|
|||
}
|
||||
)->store;
|
||||
|
||||
is( $account->balance(), 0, "Account balance is 0" );
|
||||
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
|
||||
is( $account->balance(), 0, "Account balance is 0" );
|
||||
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' );
|
||||
is( $account->outstanding_credits->total_outstanding, -10, 'Outstanding credits sum -10' );
|
||||
|
||||
$account->reconcile_balance();
|
||||
|
|
@ -652,8 +652,8 @@ subtest 'reconcile_balance' => sub {
|
|||
}
|
||||
)->store;
|
||||
|
||||
is( $account->balance(), 5, "Account balance is 5" );
|
||||
is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' );
|
||||
is( $account->balance(), 5, "Account balance is 5" );
|
||||
is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' );
|
||||
is( $account->outstanding_credits->total_outstanding, -10, 'Outstanding credits sum -10' );
|
||||
|
||||
$account->reconcile_balance();
|
||||
|
|
@ -683,8 +683,8 @@ subtest 'reconcile_balance' => sub {
|
|||
my $debit_2 = $account->add_debit( { amount => 2, interface => 'commandline', type => 'OVERDUE' } );
|
||||
my $debit_3 = $account->add_debit( { amount => 3, interface => 'commandline', type => 'OVERDUE' } );
|
||||
|
||||
is( $account->balance(), 2, "Account balance is 2" );
|
||||
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' );
|
||||
is( $account->balance(), 2, "Account balance is 2" );
|
||||
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' );
|
||||
is( $account->outstanding_credits->total_outstanding, -4, 'Outstanding credits sum -4' );
|
||||
|
||||
$account->reconcile_balance();
|
||||
|
|
@ -1019,7 +1019,7 @@ subtest 'pay() handles lost items when paying by amount ( not specifying the los
|
|||
|
||||
$account->pay(
|
||||
{
|
||||
amount => .5,,
|
||||
amount => .5,
|
||||
library_id => $library->id,
|
||||
}
|
||||
);
|
||||
|
|
@ -1363,7 +1363,7 @@ subtest 'Koha::Account::payout_amount() tests' => sub {
|
|||
my $credit_3 = $account->add_credit( { amount => 5, interface => 'commandline' } );
|
||||
my $credit_4 = $account->add_credit( { amount => 10, interface => 'commandline' } );
|
||||
my $credits = $account->outstanding_credits();
|
||||
is( $credits->count, 4, "Found 4 credits with outstanding amounts" );
|
||||
is( $credits->count, 4, "Found 4 credits with outstanding amounts" );
|
||||
is( $credits->total_outstanding + 0, -20, "Total -20 outstanding credit" );
|
||||
|
||||
my $payout = $account->payout_amount($payout_params);
|
||||
|
|
@ -1371,7 +1371,7 @@ subtest 'Koha::Account::payout_amount() tests' => sub {
|
|||
is( $payout->amount + 0, 10, "Payout amount recorded correctly" );
|
||||
is( $payout->amountoutstanding + 0, 0, "Full amount was paid out" );
|
||||
$credits = $account->outstanding_credits();
|
||||
is( $credits->count, 1, "Payout was applied against oldest outstanding credits first" );
|
||||
is( $credits->count, 1, "Payout was applied against oldest outstanding credits first" );
|
||||
is( $credits->total_outstanding + 0, -10, "Total of 10 outstanding credit remaining" );
|
||||
|
||||
my $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } );
|
||||
|
|
@ -1400,7 +1400,7 @@ subtest 'Koha::Account::payout_amount() tests' => sub {
|
|||
$payout = $account->payout_amount($payout_params);
|
||||
|
||||
$credits = $account->outstanding_credits();
|
||||
is( $credits->count, 2, "Second credit not fully paid off" );
|
||||
is( $credits->count, 2, "Second credit not fully paid off" );
|
||||
is( $credits->total_outstanding + 0, -12.50, "12.50 outstanding credit remaining" );
|
||||
$credit_4->discard_changes;
|
||||
$credit_5->discard_changes;
|
||||
|
|
@ -1496,7 +1496,7 @@ subtest 'Koha::Account::payin_amount() tests' => sub {
|
|||
my $payin = $account->payin_amount($payin_params);
|
||||
is( ref($payin), 'Koha::Account::Line', 'Return the Koha::Account::Line object for the payin' );
|
||||
is( $payin->amount + 0, -10, "Payin amount recorded correctly" );
|
||||
is( $payin->amountoutstanding + 0, 0, "Full amount was used to pay debts" );
|
||||
is( $payin->amountoutstanding + 0, 0, "Full amount was used to pay debts" );
|
||||
$debits = $account->outstanding_debits();
|
||||
is( $debits->count, 1, "Payin was applied against oldest outstanding debits first" );
|
||||
is( $debits->total_outstanding + 0, 10, "Total of 10 outstanding debit remaining" );
|
||||
|
|
|
|||
|
|
@ -966,7 +966,7 @@ subtest "void() tests" => sub {
|
|||
is( $account_payment->credit_type_code, 'PAYMENT', 'Voided payment credit_type_code is still PAYMENT' );
|
||||
is( $account_payment->status, 'VOID', 'Voided payment status is VOID' );
|
||||
is( $account_payment->amount + 0, -30, 'Voided payment amount is still -30' );
|
||||
is( $account_payment->amountoutstanding + 0, 0, 'Voided payment amount outstanding is 0' );
|
||||
is( $account_payment->amountoutstanding + 0, 0, 'Voided payment amount outstanding is 0' );
|
||||
|
||||
is( $line1->amountoutstanding + 0, 10, 'First fee again has amount outstanding of 10' );
|
||||
is( $line2->amountoutstanding + 0, 20, 'Second fee again has amount outstanding of 20' );
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ subtest 'debits_total() tests' => sub {
|
|||
borrowernumber => $patron->id,
|
||||
credit_type_code => "PAYMENT",
|
||||
amount => -10,
|
||||
amountoutstanding => 0,
|
||||
amountoutstanding => 0,
|
||||
interface => 'commandline',
|
||||
}
|
||||
)->store;
|
||||
|
|
@ -324,7 +324,7 @@ subtest 'debits_total() tests' => sub {
|
|||
borrowernumber => $patron->id,
|
||||
credit_type_code => "PAYMENT",
|
||||
amount => -10,
|
||||
amountoutstanding => 0,
|
||||
amountoutstanding => 0,
|
||||
interface => 'commandline',
|
||||
}
|
||||
)->store;
|
||||
|
|
@ -337,7 +337,7 @@ subtest 'debits_total() tests' => sub {
|
|||
borrowernumber => $patron->id,
|
||||
credit_type_code => "PAYMENT",
|
||||
amount => -100,
|
||||
amountoutstanding => 0,
|
||||
amountoutstanding => 0,
|
||||
interface => 'commandline',
|
||||
}
|
||||
)->store;
|
||||
|
|
|
|||
|
|
@ -178,8 +178,12 @@ subtest 'filter_by_obsolete and cancel' => sub {
|
|||
|
||||
# First make order 1 obsolete by removing biblio, and order 3 by status problem.
|
||||
my $date = Koha::DateUtils::dt_from_string->subtract( days => 7 );
|
||||
$order_1->orderstatus('ordered')->quantity(2)->quantityreceived(0)->datecancellationprinted(undef)
|
||||
->entrydate($date)->store;
|
||||
$order_1->orderstatus('ordered')
|
||||
->quantity(2)
|
||||
->quantityreceived(0)
|
||||
->datecancellationprinted(undef)
|
||||
->entrydate($date)
|
||||
->store;
|
||||
Koha::Biblios->find( $order_1->biblionumber )->delete;
|
||||
$order_1->discard_changes;
|
||||
$order_2->orderstatus('ordered')->quantity(3)->quantityreceived(0)->datecancellationprinted(undef)->store;
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ subtest '->is_expired' => sub {
|
|||
|
||||
my $today = dt_from_string;
|
||||
my $yesterday = dt_from_string->add( days => -1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $new_today = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::AdditionalContents',
|
||||
|
|
@ -200,7 +200,7 @@ subtest '->search_for_display' => sub {
|
|||
|
||||
my $today = dt_from_string;
|
||||
my $yesterday = dt_from_string->add( days => -1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ subtest 'purchase tests' => sub {
|
|||
ok( $credit->is_credit, "return is a credit for payment" );
|
||||
is( $credit->credit_type_code, 'PURCHASE', "credit_type_code set correctly to 'PURCHASE' for payment" );
|
||||
is( $credit->amount * 1, -5, "amount is calculated correctly for payment" );
|
||||
is( $credit->amountoutstanding * 1, 0, "amountoutstanding is set to zero for payment" );
|
||||
is( $credit->amountoutstanding * 1, 0, "amountoutstanding is set to zero for payment" );
|
||||
is( $credit->manager_id, $staff->borrowernumber, "manager_id set correctionly for payment" );
|
||||
is( $credit->register_id, $cash_register->id, "register_id set correctly for payment" );
|
||||
is( $credit->payment_type, 'CASH', "payment_type set correctly for payment" );
|
||||
|
|
|
|||
|
|
@ -78,9 +78,9 @@ is(
|
|||
subtest 'is_overdue' => sub {
|
||||
plan tests => 6;
|
||||
my $ten_days_ago = dt_from_string->add( days => -10 );
|
||||
my $ten_days_later = dt_from_string->add( days => 10 );
|
||||
my $ten_days_later = dt_from_string->add( days => 10 );
|
||||
my $yesterday = dt_from_string->add( days => -1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
|
||||
$retrieved_checkout_1->date_due($ten_days_ago)->store;
|
||||
is(
|
||||
|
|
@ -299,7 +299,7 @@ subtest 'Koha::Old::Checkouts->filter_by_todays_checkins' => sub {
|
|||
itemnumber => $item->itemnumber,
|
||||
branchcode => $library->{branchcode},
|
||||
}
|
||||
)->store;
|
||||
)->store;
|
||||
}
|
||||
|
||||
# Checkin 3 today - 2 days
|
||||
|
|
|
|||
|
|
@ -466,7 +466,8 @@ subtest 'cancel' => sub {
|
|||
my $reserve_id = C4::Reserves::AddReserve($hold_info);
|
||||
Koha::Holds->find($reserve_id)->cancel;
|
||||
my $number_of_logs =
|
||||
$schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )
|
||||
->count;
|
||||
is( $number_of_logs, 0, 'Without HoldsLog, Koha::Hold->cancel should not have logged' );
|
||||
|
||||
|
|
@ -474,7 +475,8 @@ subtest 'cancel' => sub {
|
|||
$reserve_id = C4::Reserves::AddReserve($hold_info);
|
||||
Koha::Holds->find($reserve_id)->cancel;
|
||||
$number_of_logs =
|
||||
$schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )
|
||||
->count;
|
||||
is( $number_of_logs, 1, 'With HoldsLog, Koha::Hold->cancel should have logged' );
|
||||
};
|
||||
|
|
@ -828,8 +830,8 @@ subtest 'get_items_that_can_fill' => sub {
|
|||
my $item_4 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $itype_1->itemtype } )
|
||||
; # in transfer
|
||||
my $item_5 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itype => $itype_2->itemtype } );
|
||||
my $lost = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1 } );
|
||||
my $withdrawn = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1 } );
|
||||
my $lost = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, itemlost => 1 } );
|
||||
my $withdrawn = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, withdrawn => 1 } );
|
||||
my $notforloan = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, notforloan => -1 } );
|
||||
|
||||
my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ subtest 'opac_available_backends() tests' => sub {
|
|||
};
|
||||
|
||||
my $base_limits = {
|
||||
branch => { CPL => { count => 1, method => 'annual' } },
|
||||
branch => { CPL => { count => 1, method => 'annual' } },
|
||||
brw_cat => { A => { count => -1, method => 'active' } },
|
||||
default => { count => 10, method => 'annual' },
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1011,7 +1011,7 @@ subtest 'Backend core methods' => sub {
|
|||
);
|
||||
|
||||
Koha::AdditionalContents->search->delete;
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $yesterday = dt_from_string->add( days => -1 );
|
||||
|
||||
my $library_additional_contents = $builder->build_object(
|
||||
|
|
|
|||
|
|
@ -2863,7 +2863,7 @@ subtest 'store() tests' => sub {
|
|||
{
|
||||
borrowernumber => $patron->id,
|
||||
date => '1970-01-01 14:00:01',
|
||||
amountoutstanding => 0,
|
||||
amountoutstanding => 0,
|
||||
amount => -5,
|
||||
interface => 'commandline',
|
||||
credit_type_code => 'PAYMENT'
|
||||
|
|
|
|||
|
|
@ -1254,7 +1254,7 @@ subtest "filter_by_last_update" => sub {
|
|||
class => 'Koha::Patrons',
|
||||
value => { updated_on => $now->clone->subtract( days => $i ) }
|
||||
}
|
||||
)->borrowernumber;
|
||||
)->borrowernumber;
|
||||
}
|
||||
|
||||
my $patrons = Koha::Patrons->search( { borrowernumber => { -in => \@borrowernumbers } } );
|
||||
|
|
|
|||
|
|
@ -502,7 +502,8 @@ subtest 'renew_account' => sub {
|
|||
);
|
||||
my $number_of_logs =
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
|
||||
->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )
|
||||
->count;
|
||||
is( $number_of_logs, 1, 'With BorrowersLog, Koha::Patron->renew_account should have logged' );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' );
|
||||
|
|
@ -518,7 +519,8 @@ subtest 'renew_account' => sub {
|
|||
is( dt_from_string($retrieved_expiry_date), $a_year_later, "today + 12 months must be $a_year_later" );
|
||||
$number_of_logs =
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
|
||||
->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )
|
||||
->count;
|
||||
is( $number_of_logs, 1, 'Without BorrowersLog, Koha::Patron->renew_account should not have logged' );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'combination' );
|
||||
|
|
@ -654,7 +656,8 @@ subtest "delete" => sub {
|
|||
|
||||
my $number_of_logs =
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )->count;
|
||||
->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )
|
||||
->count;
|
||||
is( $number_of_logs, 1, 'With BorrowersLog, Koha::Patron->delete should have logged' );
|
||||
|
||||
# Test deletion with designated fallback owner
|
||||
|
|
@ -727,7 +730,8 @@ subtest 'add_enrolment_fee_if_needed' => sub {
|
|||
foreach ( keys %{$enrolmentfees} ) {
|
||||
( Koha::Patron::Categories->find($_)
|
||||
// $builder->build_object( { class => 'Koha::Patron::Categories', value => { categorycode => $_ } } ) )
|
||||
->enrolmentfee( $enrolmentfees->{$_} )->store;
|
||||
->enrolmentfee( $enrolmentfees->{$_} )
|
||||
->store;
|
||||
}
|
||||
my $enrolmentfee_K = $enrolmentfees->{K};
|
||||
my $enrolmentfee_J = $enrolmentfees->{J};
|
||||
|
|
@ -2475,7 +2479,8 @@ subtest '->set_password' => sub {
|
|||
|
||||
my $number_of_logs =
|
||||
$schema->resultset('ActionLog')
|
||||
->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count;
|
||||
->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )
|
||||
->count;
|
||||
is( $number_of_logs, 0, 'Without BorrowersLog, Koha::Patron->set_password doesn\'t log password changes' );
|
||||
|
||||
# Enable logging password changes
|
||||
|
|
@ -3005,8 +3010,8 @@ subtest "search_patrons_to_update_category tests" => sub {
|
|||
class => 'Koha::Patrons',
|
||||
value => {
|
||||
categorycode => $category_code,
|
||||
dateofbirth =>
|
||||
$current_dt->clone->subtract( years => $category->upperagelimit + 1 )->subtract( days => 1 )
|
||||
dateofbirth => $current_dt->clone->subtract( years => $category->upperagelimit + 1 )
|
||||
->subtract( days => 1 )
|
||||
->ymd,
|
||||
}
|
||||
}
|
||||
|
|
@ -3456,7 +3461,8 @@ subtest 'filter_by_have_permission' => sub {
|
|||
is_deeply(
|
||||
[
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_permission('suggestions.suggestions_manage')->get_column('borrowernumber')
|
||||
->filter_by_have_permission('suggestions.suggestions_manage')
|
||||
->get_column('borrowernumber')
|
||||
],
|
||||
[ $patron_1->borrowernumber, $patron_2->borrowernumber ],
|
||||
'Superlibrarian and patron with suggestions.suggestions_manage'
|
||||
|
|
@ -3465,7 +3471,8 @@ subtest 'filter_by_have_permission' => sub {
|
|||
is_deeply(
|
||||
[
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_permission('acquisition.order_manage')->get_column('borrowernumber')
|
||||
->filter_by_have_permission('acquisition.order_manage')
|
||||
->get_column('borrowernumber')
|
||||
],
|
||||
[ $patron_1->borrowernumber, $patron_3->borrowernumber ],
|
||||
'Superlibrarian and patron with acquisition.order_manage'
|
||||
|
|
@ -3474,7 +3481,8 @@ subtest 'filter_by_have_permission' => sub {
|
|||
is_deeply(
|
||||
[
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_permission('parameters.manage_cities')->get_column('borrowernumber')
|
||||
->filter_by_have_permission('parameters.manage_cities')
|
||||
->get_column('borrowernumber')
|
||||
],
|
||||
[ $patron_1->borrowernumber ],
|
||||
'Only Superlibrarian is returned'
|
||||
|
|
@ -3482,7 +3490,8 @@ subtest 'filter_by_have_permission' => sub {
|
|||
|
||||
is_deeply(
|
||||
[
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )->filter_by_have_permission('suggestions')
|
||||
Koha::Patrons->search( { branchcode => $library->branchcode } )
|
||||
->filter_by_have_permission('suggestions')
|
||||
->get_column('borrowernumber')
|
||||
],
|
||||
[ $patron_1->borrowernumber, $patron_2->borrowernumber ],
|
||||
|
|
|
|||
|
|
@ -563,20 +563,20 @@ subtest 'Test _version_compare' => sub {
|
|||
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
|
||||
|
||||
is( Koha::Plugins::Base::_version_compare( '1.1.1', '2.2.2' ), -1, "1.1.1 is less then 2.2.2" );
|
||||
is( Koha::Plugins::Base::_version_compare( '2.2.2', '1.1.1' ), 1, "1.1.1 is greater then 2.2.2" );
|
||||
is( Koha::Plugins::Base::_version_compare( '1.1.1', '1.1.1' ), 0, "1.1.1 is equal to 1.1.1" );
|
||||
is( Koha::Plugins::Base::_version_compare( '1.01.001', '1.1.1' ), 0, "1.01.001 is equal to 1.1.1" );
|
||||
is( Koha::Plugins::Base::_version_compare( '1', '1.0.0' ), 0, "1 is equal to 1.0.0" );
|
||||
is( Koha::Plugins::Base::_version_compare( '1.0', '1.0.0' ), 0, "1.0 is equal to 1.0.0" );
|
||||
is( Koha::Plugins::Base::_version_compare( '2.2.2', '1.1.1' ), 1, "1.1.1 is greater then 2.2.2" );
|
||||
is( Koha::Plugins::Base::_version_compare( '1.1.1', '1.1.1' ), 0, "1.1.1 is equal to 1.1.1" );
|
||||
is( Koha::Plugins::Base::_version_compare( '1.01.001', '1.1.1' ), 0, "1.01.001 is equal to 1.1.1" );
|
||||
is( Koha::Plugins::Base::_version_compare( '1', '1.0.0' ), 0, "1 is equal to 1.0.0" );
|
||||
is( Koha::Plugins::Base::_version_compare( '1.0', '1.0.0' ), 0, "1.0 is equal to 1.0.0" );
|
||||
|
||||
# OO tests
|
||||
my $plugin = Koha::Plugin::Test->new;
|
||||
is( $plugin->_version_compare( '1.1.1', '2.2.2' ), -1, "1.1.1 is less then 2.2.2" );
|
||||
is( $plugin->_version_compare( '2.2.2', '1.1.1' ), 1, "1.1.1 is greater then 2.2.2" );
|
||||
is( $plugin->_version_compare( '1.1.1', '1.1.1' ), 0, "1.1.1 is equal to 1.1.1" );
|
||||
is( $plugin->_version_compare( '1.01.001', '1.1.1' ), 0, "1.01.001 is equal to 1.1.1" );
|
||||
is( $plugin->_version_compare( '1', '1.0.0' ), 0, "1 is equal to 1.0.0" );
|
||||
is( $plugin->_version_compare( '1.0', '1.0.0' ), 0, "1.0 is equal to 1.0.0" );
|
||||
is( $plugin->_version_compare( '2.2.2', '1.1.1' ), 1, "1.1.1 is greater then 2.2.2" );
|
||||
is( $plugin->_version_compare( '1.1.1', '1.1.1' ), 0, "1.1.1 is equal to 1.1.1" );
|
||||
is( $plugin->_version_compare( '1.01.001', '1.1.1' ), 0, "1.01.001 is equal to 1.1.1" );
|
||||
is( $plugin->_version_compare( '1', '1.0.0' ), 0, "1 is equal to 1.0.0" );
|
||||
is( $plugin->_version_compare( '1.0', '1.0.0' ), 0, "1.0 is equal to 1.0.0" );
|
||||
};
|
||||
|
||||
subtest 'bundle_path() tests' => sub {
|
||||
|
|
|
|||
|
|
@ -150,11 +150,13 @@ subtest 'auth.register helper' => sub {
|
|||
)->status_is(200)->json_is( '/userid', $userid_1 );
|
||||
|
||||
$t->post_ok( '/register_user' => json =>
|
||||
{ data => {}, domain_id => $domain_2->identity_provider_domain_id, interface => 'opac' } )->status_is(401)
|
||||
{ data => {}, domain_id => $domain_2->identity_provider_domain_id, interface => 'opac' } )
|
||||
->status_is(401)
|
||||
->json_is( '/message', 'unauthorized' );
|
||||
|
||||
$t->post_ok( '/register_user' => json =>
|
||||
{ data => {}, domain_id => $domain_1->identity_provider_domain_id, interface => 'staff' } )->status_is(401)
|
||||
{ data => {}, domain_id => $domain_1->identity_provider_domain_id, interface => 'staff' } )
|
||||
->status_is(401)
|
||||
->json_is( '/message', 'unauthorized' );
|
||||
|
||||
$t->post_ok(
|
||||
|
|
@ -172,11 +174,13 @@ subtest 'auth.register helper' => sub {
|
|||
)->status_is(200)->json_is( '/userid', $userid_2 );
|
||||
|
||||
$t->post_ok( '/register_user' => json => { data => {}, domain_id => $domain_1->identity_provider_domain_id } )
|
||||
->status_is(400)->json_is( '/message', 'missing parameter: interface' );
|
||||
->status_is(400)
|
||||
->json_is( '/message', 'missing parameter: interface' );
|
||||
|
||||
$t->post_ok( '/register_user' => json =>
|
||||
{ data => {}, domain_id => $domain_1->identity_provider_domain_id, interface => 'invalid' } )
|
||||
->status_is(400)->json_is( '/message', 'bad parameter: interface' );
|
||||
->status_is(400)
|
||||
->json_is( '/message', 'bad parameter: interface' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -188,7 +192,8 @@ subtest 'auth.session helper' => sub {
|
|||
|
||||
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||
|
||||
$t->post_ok( '/start_session' => json => { userid => $patron->userid } )->status_is(200)
|
||||
$t->post_ok( '/start_session' => json => { userid => $patron->userid } )
|
||||
->status_is(200)
|
||||
->json_has( '/status', 'ok' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
|
|
@ -96,16 +96,19 @@ subtest 'auth.public helper' => sub {
|
|||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->post_ok( '/public' => json => { patron_id => $another_patron->borrowernumber } )->status_is(401)
|
||||
$t->post_ok( '/public' => json => { patron_id => $another_patron->borrowernumber } )
|
||||
->status_is(401)
|
||||
->json_is( { message => 'authentication_required' } );
|
||||
|
||||
$t->post_ok( '/public' => json =>
|
||||
{ user => $unprivileged_patron->borrowernumber, patron_id => $another_patron->borrowernumber } )
|
||||
->status_is(403)->json_is( { message => 'unauthorized' } );
|
||||
->status_is(403)
|
||||
->json_is( { message => 'unauthorized' } );
|
||||
|
||||
$t->post_ok( '/public' => json =>
|
||||
{ user => $unprivileged_patron->borrowernumber, patron_id => $unprivileged_patron->borrowernumber } )
|
||||
->status_is(200)->json_is('OK');
|
||||
->status_is(200)
|
||||
->json_is('OK');
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -124,21 +127,25 @@ subtest 'auth.public_guarantor helper' => sub {
|
|||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->post_ok( '/public_guarantor' => json => { patron_id => $another_patron->borrowernumber } )->status_is(401)
|
||||
$t->post_ok( '/public_guarantor' => json => { patron_id => $another_patron->borrowernumber } )
|
||||
->status_is(401)
|
||||
->json_is( { message => 'authentication_required' } );
|
||||
|
||||
$t->post_ok( '/public_guarantor' => json =>
|
||||
{ user => $guarantor->borrowernumber, patron_id => $another_patron->borrowernumber } )->status_is(403)
|
||||
{ user => $guarantor->borrowernumber, patron_id => $another_patron->borrowernumber } )
|
||||
->status_is(403)
|
||||
->json_is( { message => 'unauthorized' } );
|
||||
|
||||
# user is not a guarantor of themself
|
||||
$t->post_ok(
|
||||
'/public_guarantor' => json => { user => $guarantor->borrowernumber, patron_id => $guarantor->borrowernumber } )
|
||||
->status_is(403)->json_is( { message => 'unauthorized' } );
|
||||
->status_is(403)
|
||||
->json_is( { message => 'unauthorized' } );
|
||||
|
||||
$t->post_ok(
|
||||
'/public_guarantor' => json => { user => $guarantor->borrowernumber, patron_id => $guarantee->borrowernumber } )
|
||||
->status_is(200)->json_is('OK');
|
||||
->status_is(200)
|
||||
->json_is('OK');
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -186,8 +186,11 @@ subtest 'objects.search helper' => sub {
|
|||
);
|
||||
|
||||
my $t = Test::Mojo->new;
|
||||
$t->get_ok('/cities?name=manuel&_per_page=1&_page=1')->status_is(200)
|
||||
->header_like( 'Link' => qr/<http:\/\/.*[\?&]_page=2.*>; rel="next",/ )->json_has('/0')->json_hasnt('/1')
|
||||
$t->get_ok('/cities?name=manuel&_per_page=1&_page=1')
|
||||
->status_is(200)
|
||||
->header_like( 'Link' => qr/<http:\/\/.*[\?&]_page=2.*>; rel="next",/ )
|
||||
->json_has('/0')
|
||||
->json_hasnt('/1')
|
||||
->json_is( '/0/name' => 'Manuel' );
|
||||
|
||||
$builder->build_object(
|
||||
|
|
@ -198,22 +201,44 @@ subtest 'objects.search helper' => sub {
|
|||
);
|
||||
|
||||
# _match=starts_with
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=starts_with')->status_is(200)->json_has('/0')
|
||||
->json_has('/1')->json_has('/2')->json_hasnt('/3')->json_is( '/0/name' => 'Manuel' )
|
||||
->json_is( '/1/name' => 'Manuela' )->json_is( '/2/name' => 'Manuelab' );
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=starts_with')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_has('/2')
|
||||
->json_hasnt('/3')
|
||||
->json_is( '/0/name' => 'Manuel' )
|
||||
->json_is( '/1/name' => 'Manuela' )
|
||||
->json_is( '/2/name' => 'Manuelab' );
|
||||
|
||||
# _match=ends_with
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=ends_with')->status_is(200)->json_has('/0')
|
||||
->json_has('/1')->json_hasnt('/2')->json_is( '/0/name' => 'Manuel' )->json_is( '/1/name' => 'Emanuel' );
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=ends_with')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_hasnt('/2')
|
||||
->json_is( '/0/name' => 'Manuel' )
|
||||
->json_is( '/1/name' => 'Emanuel' );
|
||||
|
||||
# _match=exact
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=exact')->status_is(200)->json_has('/0')
|
||||
->json_hasnt('/1')->json_is( '/0/name' => 'Manuel' );
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=exact')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_hasnt('/1')
|
||||
->json_is( '/0/name' => 'Manuel' );
|
||||
|
||||
# _match=contains
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=contains')->status_is(200)->json_has('/0')
|
||||
->json_has('/1')->json_has('/2')->json_has('/3')->json_hasnt('/4')->json_is( '/0/name' => 'Manuel' )
|
||||
->json_is( '/1/name' => 'Manuela' )->json_is( '/2/name' => 'Manuelab' )->json_is( '/3/name' => 'Emanuel' );
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=contains')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_has('/2')
|
||||
->json_has('/3')
|
||||
->json_hasnt('/4')
|
||||
->json_is( '/0/name' => 'Manuel' )
|
||||
->json_is( '/1/name' => 'Manuela' )
|
||||
->json_is( '/2/name' => 'Manuelab' )
|
||||
->json_is( '/3/name' => 'Emanuel' );
|
||||
|
||||
# Add 20 more cities
|
||||
for ( 1 .. 20 ) {
|
||||
|
|
@ -262,26 +287,54 @@ subtest 'objects.search helper, sorting on mapped column' => sub {
|
|||
my $t = Test::Mojo->new;
|
||||
|
||||
# CSV-param
|
||||
$t->get_ok('/cities?_order_by=%2Bname,-country')->status_is(200)->json_has('/0')->json_has('/1')
|
||||
->json_is( '/0/name' => 'A' )->json_is( '/1/name' => 'B' )->json_is( '/2/name' => 'C' )
|
||||
->json_is( '/2/country' => 'Belarus' )->json_is( '/3/name' => 'C' )->json_is( '/3/country' => 'Argentina' )
|
||||
$t->get_ok('/cities?_order_by=%2Bname,-country')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_is( '/0/name' => 'A' )
|
||||
->json_is( '/1/name' => 'B' )
|
||||
->json_is( '/2/name' => 'C' )
|
||||
->json_is( '/2/country' => 'Belarus' )
|
||||
->json_is( '/3/name' => 'C' )
|
||||
->json_is( '/3/country' => 'Argentina' )
|
||||
->json_hasnt('/4');
|
||||
|
||||
# Multi-param: traditional
|
||||
$t->get_ok('/cities?_order_by=%2Bname&_order_by=-country')->status_is(200)->json_has('/0')->json_has('/1')
|
||||
->json_is( '/0/name' => 'A' )->json_is( '/1/name' => 'B' )->json_is( '/2/name' => 'C' )
|
||||
->json_is( '/2/country' => 'Belarus' )->json_is( '/3/name' => 'C' )->json_is( '/3/country' => 'Argentina' )
|
||||
$t->get_ok('/cities?_order_by=%2Bname&_order_by=-country')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_is( '/0/name' => 'A' )
|
||||
->json_is( '/1/name' => 'B' )
|
||||
->json_is( '/2/name' => 'C' )
|
||||
->json_is( '/2/country' => 'Belarus' )
|
||||
->json_is( '/3/name' => 'C' )
|
||||
->json_is( '/3/country' => 'Argentina' )
|
||||
->json_hasnt('/4');
|
||||
|
||||
# Multi-param: PHP Style, Passes validation as above, subsequently explodes
|
||||
$t->get_ok('/cities?_order_by[]=%2Bname&_order_by[]=-country')->status_is(200)->json_has('/0')->json_has('/1')
|
||||
->json_is( '/0/name' => 'A' )->json_is( '/1/name' => 'B' )->json_is( '/2/name' => 'C' )
|
||||
->json_is( '/2/country' => 'Belarus' )->json_is( '/3/name' => 'C' )->json_is( '/3/country' => 'Argentina' )
|
||||
$t->get_ok('/cities?_order_by[]=%2Bname&_order_by[]=-country')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_is( '/0/name' => 'A' )
|
||||
->json_is( '/1/name' => 'B' )
|
||||
->json_is( '/2/name' => 'C' )
|
||||
->json_is( '/2/country' => 'Belarus' )
|
||||
->json_is( '/3/name' => 'C' )
|
||||
->json_is( '/3/country' => 'Argentina' )
|
||||
->json_hasnt('/4');
|
||||
|
||||
# Single-param
|
||||
$t->get_ok('/cities?_order_by=-name')->status_is(200)->json_has('/0')->json_has('/1')->json_is( '/0/name' => 'C' )
|
||||
->json_is( '/1/name' => 'C' )->json_is( '/2/name' => 'B' )->json_is( '/3/name' => 'A' )->json_hasnt('/4');
|
||||
$t->get_ok('/cities?_order_by=-name')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_is( '/0/name' => 'C' )
|
||||
->json_is( '/1/name' => 'C' )
|
||||
->json_is( '/2/name' => 'B' )
|
||||
->json_is( '/3/name' => 'A' )
|
||||
->json_hasnt('/4');
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -298,7 +351,10 @@ subtest 'objects.search helper, encoding' => sub {
|
|||
$builder->build_object( { class => 'Koha::Cities', value => { city_name => 'B', city_country => '❤Argentina❤' } } );
|
||||
|
||||
my $t = Test::Mojo->new;
|
||||
$t->get_ok('/cities?q={"country": "❤Argentina❤"}')->status_is(200)->json_has('/0')->json_hasnt('/1')
|
||||
$t->get_ok('/cities?q={"country": "❤Argentina❤"}')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_hasnt('/1')
|
||||
->json_is( '/0/name' => 'B' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -326,11 +382,13 @@ subtest 'objects.search helper, X-Total-Count and X-Base-Total-Count' => sub {
|
|||
}
|
||||
|
||||
my $t = Test::Mojo->new;
|
||||
$t->get_ok('/cities?name=L&_per_page=10&_page=1&_match=starts_with')->status_is(200)
|
||||
$t->get_ok('/cities?name=L&_per_page=10&_page=1&_match=starts_with')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 20, 'X-Total-Count header present' )
|
||||
->header_is( 'X-Base-Total-Count' => 20, 'X-Base-Total-Count header present' );
|
||||
|
||||
$t->get_ok('/cities?name=Llan&_per_page=10&_page=1&_match=starts_with')->status_is(200)
|
||||
$t->get_ok('/cities?name=Llan&_per_page=10&_page=1&_match=starts_with')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 17, 'X-Total-Count header present' )
|
||||
->header_is( 'X-Base-Total-Count' => 20, 'X-Base-Total-Count header present' );
|
||||
|
||||
|
|
@ -656,13 +714,18 @@ subtest 'objects.search helper, search_limited() tests' => sub {
|
|||
t::lib::Mocks::mock_userenv( { patron => $patron } );
|
||||
|
||||
$t->get_ok( "/my_patrons?q=" . encode_json( { library_id => [ $library_1->id, $library_2->id ] } ) )
|
||||
->status_is(200)->json_is( '/0/patron_id' => $patron_1->id )->json_is( '/1/patron_id' => $patron_2->id )
|
||||
->status_is(200)
|
||||
->json_is( '/0/patron_id' => $patron_1->id )
|
||||
->json_is( '/1/patron_id' => $patron_2->id )
|
||||
->json_is( '/2/patron_id' => $patron_3->id );
|
||||
|
||||
@libraries_where_can_see_patrons = ( $library_2->id );
|
||||
|
||||
my $res = $t->get_ok( "/my_patrons?q=" . encode_json( { library_id => [ $library_1->id, $library_2->id ] } ) )
|
||||
->status_is(200)->json_is( '/0/patron_id' => $patron_3->id, 'Returns the only allowed patron' )->tx->res->json;
|
||||
my $res =
|
||||
$t->get_ok( "/my_patrons?q=" . encode_json( { library_id => [ $library_1->id, $library_2->id ] } ) )
|
||||
->status_is(200)
|
||||
->json_is( '/0/patron_id' => $patron_3->id, 'Returns the only allowed patron' )
|
||||
->tx->res->json;
|
||||
|
||||
is( scalar @{$res}, 1, 'Only one patron returned' );
|
||||
|
||||
|
|
@ -760,16 +823,24 @@ subtest 'objects.find helper with expanded authorised values' => sub {
|
|||
}
|
||||
);
|
||||
|
||||
$t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '+strings' } )->status_is(200)
|
||||
->json_is( '/name' => 'Manuel' )->json_has('/_strings')->json_is( '/_strings/country/type' => 'av' )
|
||||
$t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '+strings' } )
|
||||
->status_is(200)
|
||||
->json_is( '/name' => 'Manuel' )
|
||||
->json_has('/_strings')
|
||||
->json_is( '/_strings/country/type' => 'av' )
|
||||
->json_is( '/_strings/country/category' => $cat->category_name )
|
||||
->json_is( '/_strings/country/str' => $ar->lib );
|
||||
|
||||
$t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '' } )->status_is(200)->json_is( '/name' => 'Manuel' )
|
||||
$t->get_ok( '/cities/' . $manuel->id => { 'x-koha-embed' => '' } )
|
||||
->status_is(200)
|
||||
->json_is( '/name' => 'Manuel' )
|
||||
->json_hasnt('/_strings');
|
||||
|
||||
$t->get_ok( '/cities/' . $manuela->id => { 'x-koha-embed' => '+strings' } )->status_is(200)
|
||||
->json_is( '/name' => 'Manuela' )->json_has('/_strings')->json_is( '/_strings/country/type' => 'av' )
|
||||
$t->get_ok( '/cities/' . $manuela->id => { 'x-koha-embed' => '+strings' } )
|
||||
->status_is(200)
|
||||
->json_is( '/name' => 'Manuela' )
|
||||
->json_has('/_strings')
|
||||
->json_is( '/_strings/country/type' => 'av' )
|
||||
->json_is( '/_strings/country/category' => $cat->category_name )
|
||||
->json_is( '/_strings/country/str' => $us->lib );
|
||||
|
||||
|
|
@ -868,17 +939,30 @@ subtest 'objects.search helper with expanded authorised values' => sub {
|
|||
);
|
||||
|
||||
$t->get_ok( '/cities?name=manuel&_per_page=4&_page=1&_match=starts_with' => { 'x-koha-embed' => '+strings' } )
|
||||
->status_is(200)->json_has('/0')->json_has('/1')->json_hasnt('/2')->json_is( '/0/name' => 'Manuel' )
|
||||
->json_has('/0/_strings')->json_is( '/0/_strings/country/str' => $ar->lib )
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_hasnt('/2')
|
||||
->json_is( '/0/name' => 'Manuel' )
|
||||
->json_has('/0/_strings')
|
||||
->json_is( '/0/_strings/country/str' => $ar->lib )
|
||||
->json_is( '/0/_strings/country/type' => 'av' )
|
||||
->json_is( '/0/_strings/country/category' => $cat->category_name )->json_is( '/1/name' => 'Manuela' )
|
||||
->json_has('/1/_strings')->json_is( '/1/_strings/country/str' => $us->lib )
|
||||
->json_is( '/0/_strings/country/category' => $cat->category_name )
|
||||
->json_is( '/1/name' => 'Manuela' )
|
||||
->json_has('/1/_strings')
|
||||
->json_is( '/1/_strings/country/str' => $us->lib )
|
||||
->json_is( '/1/_strings/country/type' => 'av' )
|
||||
->json_is( '/1/_strings/country/category' => $cat->category_name );
|
||||
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=starts_with')->status_is(200)->json_has('/0')
|
||||
->json_has('/1')->json_hasnt('/2')->json_is( '/0/name' => 'Manuel' )->json_hasnt('/0/_strings')
|
||||
->json_is( '/1/name' => 'Manuela' )->json_hasnt('/1/_strings');
|
||||
$t->get_ok('/cities?name=manuel&_per_page=4&_page=1&_match=starts_with')
|
||||
->status_is(200)
|
||||
->json_has('/0')
|
||||
->json_has('/1')
|
||||
->json_hasnt('/2')
|
||||
->json_is( '/0/name' => 'Manuel' )
|
||||
->json_hasnt('/0/_strings')
|
||||
->json_is( '/1/name' => 'Manuela' )
|
||||
->json_hasnt('/1/_strings');
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -994,7 +1078,9 @@ subtest 'date handling' => sub {
|
|||
borrowernumber => $patron->id
|
||||
}
|
||||
);
|
||||
$t->get_ok( "//$userid:$password@/api/v1/jobs?q=" . $q )->status_is(200)->json_is( '/0/job_id' => $job_1->id )
|
||||
$t->get_ok( "//$userid:$password@/api/v1/jobs?q=" . $q )
|
||||
->status_is(200)
|
||||
->json_is( '/0/job_id' => $job_1->id )
|
||||
->json_is( '/1/job_id' => $job_3->id );
|
||||
$response_count = scalar @{ $t->tx->res->json };
|
||||
is( $response_count, 2 );
|
||||
|
|
|
|||
|
|
@ -101,11 +101,14 @@ subtest 'add_pagination_headers() tests' => sub {
|
|||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->get_ok('/empty')->status_is(200)->header_is( 'X-Total-Count' => undef, 'X-Total-Count is undefined' )
|
||||
$t->get_ok('/empty')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => undef, 'X-Total-Count is undefined' )
|
||||
->header_is( 'X-Base-Total-Count' => undef, 'X-Base-Total-Count is undefined' )
|
||||
->header_is( 'Link' => undef, 'Link is undefined' );
|
||||
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_page=2&_per_page=3')->status_is(200)
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_page=2&_per_page=3')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 10, 'X-Total-Count correctly set' )
|
||||
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count correctly set' )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ )
|
||||
|
|
@ -121,7 +124,8 @@ subtest 'add_pagination_headers() tests' => sub {
|
|||
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=4.*>; rel="last"/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
|
||||
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_page=1&_per_page=3')->status_is(200)
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_page=1&_per_page=3')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 10, 'X-Total-Count correctly set' )
|
||||
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count correctly set' )
|
||||
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*>; rel="prev",/ )
|
||||
|
|
@ -135,7 +139,8 @@ subtest 'add_pagination_headers() tests' => sub {
|
|||
->header_like( 'Link' => qr/<http:\/\/.*\?.*_page=4.*>; rel="last"/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
|
||||
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_page=4&_per_page=3')->status_is(200)
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_page=4&_per_page=3')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 10, 'X-Total-Count correctly set' )
|
||||
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count correctly set' )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*_per_page=3.*>; rel="prev",/ )
|
||||
|
|
@ -150,7 +155,8 @@ subtest 'add_pagination_headers() tests' => sub {
|
|||
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'RESTdefaultPageSize', 3 );
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_page=2')->status_is(200)
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_page=2')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 10, 'X-Total-Count correctly set' )
|
||||
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count correctly set' )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/ )
|
||||
|
|
@ -166,7 +172,8 @@ subtest 'add_pagination_headers() tests' => sub {
|
|||
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=4.*>; rel="last"/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
|
||||
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_per_page=3')->status_is(200)
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_per_page=3')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, even without page param' )
|
||||
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count correctly set' )
|
||||
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=3.*>; rel="prev",/, 'First page, no previous' )
|
||||
|
|
@ -182,7 +189,8 @@ subtest 'add_pagination_headers() tests' => sub {
|
|||
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=4.*>; rel="last"/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
|
||||
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_per_page=-1')->status_is(200)
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_per_page=-1')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' )
|
||||
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count correctly set' )
|
||||
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' )
|
||||
|
|
@ -191,14 +199,16 @@ subtest 'add_pagination_headers() tests' => sub {
|
|||
->header_unlike(
|
||||
'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="next",/,
|
||||
'No next page, all resources are fetched'
|
||||
)->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="first",/ )
|
||||
)
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="first",/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="first",/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="first",/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="last"/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="last"/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="last"/ );
|
||||
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_per_page=-1&_page=100')->status_is(200)
|
||||
$t->get_ok('/pagination_headers?firstname=Jonathan&_per_page=-1&_page=100')
|
||||
->status_is(200)
|
||||
->header_is( 'X-Total-Count' => 10, 'X-Total-Count header present, with per_page=-1' )
|
||||
->header_is( 'X-Base-Total-Count' => 12, 'X-Base-Total-Count correctly set' )
|
||||
->header_unlike( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="prev",/, 'First page, no previous' )
|
||||
|
|
@ -207,7 +217,8 @@ subtest 'add_pagination_headers() tests' => sub {
|
|||
->header_unlike(
|
||||
'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="next",/,
|
||||
'No next page, all resources are fetched'
|
||||
)->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="first",/ )
|
||||
)
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="first",/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*page=1.*>; rel="first",/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*firstname=Jonathan.*>; rel="first",/ )
|
||||
->header_like( 'Link' => qr/<http:\/\/.*\?.*per_page=-1.*>; rel="last"/ )
|
||||
|
|
@ -221,6 +232,7 @@ subtest 'dbic_merge_pagination() tests' => sub {
|
|||
|
||||
my $t = Test::Mojo->new;
|
||||
|
||||
$t->get_ok('/dbic_merge_pagination')->status_is(200)
|
||||
$t->get_ok('/dbic_merge_pagination')
|
||||
->status_is(200)
|
||||
->json_is( { firstname => 'Kyle', surname => 'Hall', page => 1, rows => 3 } );
|
||||
};
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ subtest 'authorised values' => sub {
|
|||
$subfield->{marc_value}->{values},
|
||||
[
|
||||
"",
|
||||
map { $_->authorised_value }
|
||||
map { $_->authorised_value }
|
||||
sort { $a->lib cmp $b->lib } $avs->as_list
|
||||
],
|
||||
'AVs are sorted by lib and en empty option is created first'
|
||||
|
|
|
|||
|
|
@ -247,10 +247,12 @@ subtest "Update patron categories" => sub {
|
|||
is( Koha::Patrons->search_patrons_to_update_category( { from => $c_categorycode, too_old => 1 } )
|
||||
->next->borrowernumber, $child3->borrowernumber, 'Over age patron in child category is expected one' );
|
||||
is( Koha::Patrons->search( { branchcode => $branchcode2 } )
|
||||
->search_patrons_to_update_category( { from => $a_categorycode } )->count, 1, 'One patron in branch 2' );
|
||||
->search_patrons_to_update_category( { from => $a_categorycode } )
|
||||
->count, 1, 'One patron in branch 2' );
|
||||
is(
|
||||
Koha::Patrons->search( { branchcode => $branchcode2 } )
|
||||
->search_patrons_to_update_category( { from => $a_categorycode } )->next->borrowernumber,
|
||||
->search_patrons_to_update_category( { from => $a_categorycode } )
|
||||
->next->borrowernumber,
|
||||
$adult2->borrowernumber, 'Adult patron in branch 2 is expected one'
|
||||
);
|
||||
is(
|
||||
|
|
@ -344,7 +346,8 @@ subtest "Update patron categories" => sub {
|
|||
|
||||
is(
|
||||
Koha::Patrons->search_patrons_to_update_category( { from => $a_categorycode, fine_max => 5 } )
|
||||
->search( { "me.borrowernumber" => $adult1->borrowernumber } )->next->borrowernumber,
|
||||
->search( { "me.borrowernumber" => $adult1->borrowernumber } )
|
||||
->next->borrowernumber,
|
||||
$adult1->borrowernumber, 'Expected patron is in the list of patrons to update'
|
||||
);
|
||||
my $userid_before = $adult1->userid;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ subtest 'Test handling of waiting reserves by CancelExpiredReserves' => sub {
|
|||
|
||||
my $resdate = dt_from_string->add( days => -20 );
|
||||
my $expdate = dt_from_string->add( days => -2 );
|
||||
my $notexpdate = dt_from_string->add( days => 2 );
|
||||
my $notexpdate = dt_from_string->add( days => 2 );
|
||||
|
||||
my $hold1 = Koha::Hold->new(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,7 +59,8 @@ subtest 'get_report' => sub {
|
|||
is( $report->{'without'}->[0]->{'isbn'}, '9780596526740', 'testing get_report' );
|
||||
|
||||
# test if we can get with key instead
|
||||
$schema->resultset('SocialData')->search( { isbn => '0-596-52674-1' } )
|
||||
$schema->resultset('SocialData')
|
||||
->search( { isbn => '0-596-52674-1' } )
|
||||
->next->update( { isbn => '9780596526740' } );
|
||||
$report = C4::SocialData::get_report();
|
||||
is( $report->{with}->[0]->{isbn}, '9780596526740', 'this isbn has social data' );
|
||||
|
|
|
|||
|
|
@ -162,7 +162,8 @@ subtest 'Test FKs in overduerules_transport_type' => sub {
|
|||
'build stores the categorycode correctly'
|
||||
);
|
||||
is(
|
||||
$schema->resultset('MessageTransportType')->find( $overduerules_transport_type->{message_transport_type} )
|
||||
$schema->resultset('MessageTransportType')
|
||||
->find( $overduerules_transport_type->{message_transport_type} )
|
||||
->message_transport_type,
|
||||
$overduerules_transport_type->{message_transport_type},
|
||||
'build stores the foreign key message_transport_type correctly'
|
||||
|
|
|
|||
|
|
@ -133,7 +133,9 @@ subtest 'add() tests' => sub {
|
|||
|
||||
$t->post_ok( $url, json => {} )->status_is(400);
|
||||
|
||||
$t->post_ok( $url, json => { vendor_id => $vendor->id } )->status_is(201)->json_has('/basket_id')
|
||||
$t->post_ok( $url, json => { vendor_id => $vendor->id } )
|
||||
->status_is(201)
|
||||
->json_has('/basket_id')
|
||||
->json_is( '/vendor_id', $vendor->id );
|
||||
|
||||
my $basket = {
|
||||
|
|
@ -141,8 +143,11 @@ subtest 'add() tests' => sub {
|
|||
name => 'Basket #1',
|
||||
vendor_note => 'Vendor note',
|
||||
};
|
||||
$t->post_ok( $url, json => $basket )->status_is(201)->json_has('/basket_id')
|
||||
->json_is( '/vendor_id', $basket->{vendor_id} )->json_is( '/name', $basket->{name} )
|
||||
$t->post_ok( $url, json => $basket )
|
||||
->status_is(201)
|
||||
->json_has('/basket_id')
|
||||
->json_is( '/vendor_id', $basket->{vendor_id} )
|
||||
->json_is( '/name', $basket->{name} )
|
||||
->json_is( '/vendor_note', $basket->{vendor_note} );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ $t->get_ok( "//$unauth_userid:$unauth_password@/api/v1/acquisitions/funds?name="
|
|||
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/funds")->status_is(200);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/funds?name=" . $fund_name )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/funds?name=" . $fund_name )
|
||||
->status_is(200)
|
||||
->json_like( '/0/name' => qr/$fund_name/ );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ subtest 'list() tests' => sub {
|
|||
|
||||
# Make sure we are returned with the correct amount of orders
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/orders?status=new&_per_page=-1")
|
||||
->status_is( 200, 'REST3.2.2' )->json_has( '/' . ( $count_of_orders - 1 ) . '/order_id' )
|
||||
->status_is( 200, 'REST3.2.2' )
|
||||
->json_has( '/' . ( $count_of_orders - 1 ) . '/order_id' )
|
||||
->json_hasnt( '/' . ($count_of_orders) . '/order_id' );
|
||||
|
||||
subtest 'query parameters' => sub {
|
||||
|
|
@ -146,7 +147,8 @@ subtest 'list() tests' => sub {
|
|||
is( scalar @{ $result->tx->res->json }, 1, 'Only one order is active' );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/orders?order_blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/orders?order_blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/order_blah', message => 'Malformed query string' } ] );
|
||||
|
||||
subtest 'sorting tests' => sub {
|
||||
|
|
@ -184,7 +186,8 @@ subtest 'list() tests' => sub {
|
|||
my $result =
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/acquisitions/orders?_order_by=+me.order_id&basket_id=" . $basket->id )
|
||||
->status_is( 200, "query successful" )->tx->res->json;
|
||||
->status_is( 200, "query successful" )
|
||||
->tx->res->json;
|
||||
|
||||
is( scalar @$result, 2, 'Two elements returned' );
|
||||
|
||||
|
|
@ -195,7 +198,8 @@ subtest 'list() tests' => sub {
|
|||
$result =
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/acquisitions/orders?_order_by=-me.order_id&basket_id=" . $basket->id )
|
||||
->status_is( 200, "query successful" )->tx->res->json;
|
||||
->status_is( 200, "query successful" )
|
||||
->tx->res->json;
|
||||
|
||||
is( scalar @$result, 2, 'Two elements returned' );
|
||||
|
||||
|
|
@ -255,12 +259,14 @@ subtest 'get() tests' => sub {
|
|||
my $userid = $patron->userid;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )
|
||||
->status_is( 200, 'REST3.2.2' )->json_is( '' => $order->to_api, 'REST3.3.2' );
|
||||
->status_is( 200, 'REST3.2.2' )
|
||||
->json_is( '' => $order->to_api, 'REST3.3.2' );
|
||||
|
||||
my $non_existent_order_id = $order->ordernumber;
|
||||
$order->delete;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders/" . $non_existent_order_id )->status_is(404)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/orders/" . $non_existent_order_id )
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Order not found' );
|
||||
|
||||
# FIXME This does not work on all the OS we support
|
||||
|
|
@ -336,7 +342,8 @@ subtest 'add() tests' => sub {
|
|||
$order_with_invalid_field->{'orderinvalid'} = 'Order invalid';
|
||||
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: orderinvalid.",
|
||||
|
|
@ -347,7 +354,8 @@ subtest 'add() tests' => sub {
|
|||
|
||||
# Authorized attempt to write
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order )
|
||||
->status_is( 201, 'REST3.2.1' )->json_is( '/internal_note' => $order->{internal_note}, 'REST3.3.1' )
|
||||
->status_is( 201, 'REST3.2.1' )
|
||||
->json_is( '/internal_note' => $order->{internal_note}, 'REST3.3.1' )
|
||||
->header_like( Location => qr/\/api\/v1\/acquisitions\/orders\/\d*/, 'REST3.4.1' );
|
||||
|
||||
# save the order_id
|
||||
|
|
@ -356,14 +364,16 @@ subtest 'add() tests' => sub {
|
|||
# Authorized attempt to create with null id
|
||||
$order->{order_id} = undef;
|
||||
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order )->status_is(400)
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order )
|
||||
->status_is(400)
|
||||
->json_has('/errors');
|
||||
|
||||
# Authorized attempt to create with existing id
|
||||
$order->{order_id} = $order_id;
|
||||
|
||||
warning_like {
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order )->status_is(409)
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders" => json => $order )
|
||||
->status_is(409)
|
||||
->json_has( '/error' => "Fails when trying to add an existing order_id" )
|
||||
->json_like( '/conflict' => qr/(aqorders\.)?PRIMARY/ );
|
||||
}
|
||||
|
|
@ -437,14 +447,16 @@ subtest 'update() tests' => sub {
|
|||
$deleted_library->delete;
|
||||
|
||||
$t->put_ok( "//$auth_userid:$password@/api/v1/libraries/$library_id" => json => $library_with_updated_field )
|
||||
->status_is( 200, 'REST3.2.1' )->json_is( '' => $library_with_updated_field, 'REST3.3.3' );
|
||||
->status_is( 200, 'REST3.2.1' )
|
||||
->json_is( '' => $library_with_updated_field, 'REST3.3.3' );
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
my $library_with_invalid_field = {%$library_with_updated_field};
|
||||
$library_with_invalid_field->{'branchinvalid'} = 'Library invalid';
|
||||
|
||||
$t->put_ok( "//$auth_userid:$password@/api/v1/libraries/$library_id" => json => $library_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: branchinvalid.",
|
||||
|
|
@ -494,7 +506,8 @@ subtest 'delete() tests' => sub {
|
|||
$t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )->status_is(409);
|
||||
$order->orderstatus('cancelled')->store;
|
||||
$t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )
|
||||
->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' );
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
$t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/orders/" . $order->ordernumber )->status_is(404);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
|
|
@ -64,13 +64,15 @@ subtest 'list() tests' => sub {
|
|||
)->store;
|
||||
|
||||
# One issue created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues")
|
||||
->status_is(200)
|
||||
->json_is( [ $issue->to_api ] );
|
||||
|
||||
# Embed the AV description
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues" => { 'x-koha-embed' => '+strings' } )
|
||||
->status_is(200)->json_is( [ $issue->to_api( { strings => 1 } ) ] );
|
||||
->status_is(200)
|
||||
->json_is( [ $issue->to_api( { strings => 1 } ) ] );
|
||||
|
||||
$vendor->delete;
|
||||
|
||||
|
|
|
|||
|
|
@ -63,31 +63,39 @@ subtest 'list() and delete() tests | authorized user' => sub {
|
|||
$builder->build_object( { class => 'Koha::Acquisition::Booksellers', value => { name => $vendor_name } } );
|
||||
|
||||
# One vendor created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")
|
||||
->status_is(200)
|
||||
->json_like( '/0/name' => qr/$vendor_name/ );
|
||||
|
||||
my $other_vendor_name = 'Amerindia';
|
||||
my $other_vendor = $builder->build_object(
|
||||
{ class => 'Koha::Acquisition::Booksellers', value => { name => $other_vendor_name } } );
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")->status_is(200)->json_like( '/0/name' => qr/Ruben/ )
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors")
|
||||
->status_is(200)
|
||||
->json_like( '/0/name' => qr/Ruben/ )
|
||||
->json_like( '/1/name' => qr/Amerindia/ );
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors?name=$vendor_name")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors?name=$vendor_name")
|
||||
->status_is(200)
|
||||
->json_like( '/0/name' => qr/Ruben/ );
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors?name=$other_vendor_name")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors?name=$other_vendor_name")
|
||||
->status_is(200)
|
||||
->json_like( '/0/name' => qr/Amerindia/ );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors?accountnumber=" . $vendor->accountnumber )
|
||||
->status_is(200)->json_like( '/0/name' => qr/Ruben/ );
|
||||
->status_is(200)
|
||||
->json_like( '/0/name' => qr/Ruben/ );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors?accountnumber=" . $other_vendor->accountnumber )
|
||||
->status_is(200)->json_like( '/0/name' => qr/Amerindia/ );
|
||||
->status_is(200)
|
||||
->json_like( '/0/name' => qr/Amerindia/ );
|
||||
|
||||
my @aliases = ( { alias => 'alias 1' }, { alias => 'alias 2' } );
|
||||
$vendor->aliases( \@aliases );
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" => { 'x-koha-embed' => 'aliases' } )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" => { 'x-koha-embed' => 'aliases' } )
|
||||
->status_is(200)
|
||||
->json_has( '/0/aliases', 'aliases are embedded' )
|
||||
->json_is( '/0/aliases/0/alias' => 'alias 1', 'alias 1 is embedded' )
|
||||
->json_is( '/0/aliases/1/alias' => 'alias 2', 'alias 2 is embedded' );
|
||||
|
|
@ -104,7 +112,8 @@ subtest 'list() and delete() tests | authorized user' => sub {
|
|||
{ class => 'Koha::Acquisition::Invoices', value => { booksellerid => $vendor->id } } );
|
||||
}
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors" =>
|
||||
{ 'x-koha-embed' => 'subscriptions+count,baskets+count,invoices+count' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'subscriptions+count,baskets+count,invoices+count' } )
|
||||
->status_is(200)
|
||||
->json_is( '/0/subscriptions_count', 2, 'subscriptions_count is 2' )
|
||||
->json_is( '/0/baskets_count', 2, 'baskets_count is 2' )
|
||||
->json_is( '/0/invoices_count', 2, 'invoices_count is 2' );
|
||||
|
|
@ -113,7 +122,8 @@ subtest 'list() and delete() tests | authorized user' => sub {
|
|||
# A vendor deletion should be rejected if it has baskets or subscriptions (or invoices?) linked to it
|
||||
$_->delete for @cleanup;
|
||||
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is( 204, 'REST3.2.4' )
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $other_vendor->id )->status_is(200);
|
||||
|
|
@ -143,22 +153,26 @@ subtest 'get() test' => sub {
|
|||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $userid = $patron->userid;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )
|
||||
->status_is(200)
|
||||
->json_is( $vendor->to_api );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/"
|
||||
. $vendor->id => { 'x-koha-embed' => 'subscriptions+count,baskets+count,invoices+count' } )->status_is(200)
|
||||
. $vendor->id => { 'x-koha-embed' => 'subscriptions+count,baskets+count,invoices+count' } )
|
||||
->status_is(200)
|
||||
->json_has( '/subscriptions_count', 'subscriptions_count is embedded' )
|
||||
->json_has( '/baskets_count', 'baskets_count is embedded' )
|
||||
->json_has( '/invoices_count', 'invoices_count is embedded' );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $non_existent_id )->status_is(404)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $non_existent_id )
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Vendor not found' );
|
||||
|
||||
# remove permissions
|
||||
$patron->set( { flags => 0 } )->store;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is(403)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )
|
||||
->status_is(403)
|
||||
->json_is( '/error', 'Authorization failure. Missing required permission(s).' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -201,7 +215,8 @@ subtest 'add() tests' => sub {
|
|||
};
|
||||
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: address5.",
|
||||
|
|
@ -214,14 +229,16 @@ subtest 'add() tests' => sub {
|
|||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor )
|
||||
->status_is( 201, 'REST3 .2.1' )
|
||||
->header_like( Location => qr|^\/api\/v1\/acquisitions\/vendors/\d*|, 'REST3.4.1' )
|
||||
->json_is( '/name' => $vendor->{name} )->json_is( '/address1' => $vendor->{address1} );
|
||||
->json_is( '/name' => $vendor->{name} )
|
||||
->json_is( '/address1' => $vendor->{address1} );
|
||||
|
||||
# read the response vendor id for later use
|
||||
my $vendor_id = $t->tx->res->json('/id');
|
||||
|
||||
# Authorized attempt to create with null id
|
||||
$vendor->{id} = undef;
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor )->status_is(400)
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor )
|
||||
->status_is(400)
|
||||
->json_has('/errors');
|
||||
|
||||
# Authorized attempt to create with existing id
|
||||
|
|
@ -237,37 +254,53 @@ subtest 'add() tests' => sub {
|
|||
|
||||
subtest 'relationships contracts, interfaces, aliases' => sub {
|
||||
plan tests => 32;
|
||||
my $vendor = { name => 'another vendor', contacts => [], interfaces => [], aliases => [] };
|
||||
my $vendor_id = $t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor )
|
||||
->status_is( 201, 'REST3 .2.1' )->json_is( '/name' => $vendor->{name} )
|
||||
my $vendor = { name => 'another vendor', contacts => [], interfaces => [], aliases => [] };
|
||||
my $vendor_id =
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor )
|
||||
->status_is( 201, 'REST3 .2.1' )
|
||||
->json_is( '/name' => $vendor->{name} )
|
||||
|
||||
# FIXME Maybe we expect instead
|
||||
# ->json_is( '/contacts' => [] )->json_is('/interfaces' => [], '/aliases' => [] );
|
||||
->json_hasnt('/contacts')->json_hasnt('/interfaces')->json_hasnt('/aliases')->tx->res->json->{id};
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor_id )->status_is(200)
|
||||
->json_hasnt('/contacts')->json_hasnt('/interfaces')->json_hasnt('/aliases');
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor_id )
|
||||
->status_is(200)
|
||||
->json_hasnt('/contacts')
|
||||
->json_hasnt('/interfaces')
|
||||
->json_hasnt('/aliases');
|
||||
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/"
|
||||
. $vendor_id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200)
|
||||
->json_is( '/contacts', [] )->json_is( '/interfaces', [] )->json_is( '/aliases', [] );
|
||||
. $vendor_id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )
|
||||
->status_is(200)
|
||||
->json_is( '/contacts', [] )
|
||||
->json_is( '/interfaces', [] )
|
||||
->json_is( '/aliases', [] );
|
||||
|
||||
$vendor = {
|
||||
name => 'yet another vendor', contacts => [ { name => 'contact name' } ],
|
||||
interfaces => [ { name => 'interface name' } ], aliases => [ { alias => 'foo' } ]
|
||||
};
|
||||
$vendor_id = $t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor )
|
||||
->status_is( 201, 'REST3 .2.1' )->json_is( '/name' => $vendor->{name} )
|
||||
$vendor_id =
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors" => json => $vendor )
|
||||
->status_is( 201, 'REST3 .2.1' )
|
||||
->json_is( '/name' => $vendor->{name} )
|
||||
|
||||
# FIXME Maybe we expect instead
|
||||
# ->json_is( '/contacts' => [] )->json_is('/interfaces' => [], '/aliases' => [] );
|
||||
->json_hasnt('/contacts')->json_hasnt('/interfaces')->json_hasnt('/aliases')->tx->res->json->{id};
|
||||
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor_id )->status_is(200)
|
||||
->json_hasnt('/contacts')->json_hasnt('/interfaces')->json_hasnt('/aliases');
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor_id )
|
||||
->status_is(200)
|
||||
->json_hasnt('/contacts')
|
||||
->json_hasnt('/interfaces')
|
||||
->json_hasnt('/aliases');
|
||||
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/"
|
||||
. $vendor_id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200)
|
||||
->json_has('/contacts/0/name')->json_has('/interfaces/0/name')->json_has('/aliases/0/alias');
|
||||
. $vendor_id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )
|
||||
->status_is(200)
|
||||
->json_has('/contacts/0/name')
|
||||
->json_has('/interfaces/0/name')
|
||||
->json_has('/aliases/0/alias');
|
||||
};
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -308,7 +341,8 @@ subtest 'update() tests' => sub {
|
|||
my $vendor_without_mandatory_field = { address1 => 'New address' };
|
||||
|
||||
$t->put_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/"
|
||||
. $vendor->id => json => $vendor_without_mandatory_field )->status_is(400)
|
||||
. $vendor->id => json => $vendor_without_mandatory_field )
|
||||
->status_is(400)
|
||||
->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
|
||||
|
||||
# Full object update on PUT
|
||||
|
|
@ -316,7 +350,8 @@ subtest 'update() tests' => sub {
|
|||
|
||||
$t->put_ok(
|
||||
"//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id => json => $vendor_with_updated_field )
|
||||
->status_is(200)->json_is( '/name' => 'London books' );
|
||||
->status_is(200)
|
||||
->json_is( '/name' => 'London books' );
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
my $vendor_with_invalid_field = {
|
||||
|
|
@ -328,7 +363,8 @@ subtest 'update() tests' => sub {
|
|||
|
||||
$t->put_ok(
|
||||
"//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id => json => $vendor_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
|
@ -357,8 +393,11 @@ subtest 'update() tests' => sub {
|
|||
$vendor->aliases( [] );
|
||||
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/"
|
||||
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200)
|
||||
->json_is( '/contacts', [] )->json_is( '/interfaces', [] )->json_is( '/aliases', [] );
|
||||
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )
|
||||
->status_is(200)
|
||||
->json_is( '/contacts', [] )
|
||||
->json_is( '/interfaces', [] )
|
||||
->json_is( '/aliases', [] );
|
||||
|
||||
my $api_vendor = $vendor->to_api;
|
||||
delete $api_vendor->{id};
|
||||
|
|
@ -368,12 +407,18 @@ subtest 'update() tests' => sub {
|
|||
$api_vendor->{aliases} = [ { alias => 'foo' } ];
|
||||
|
||||
$t->put_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id => json => $api_vendor )
|
||||
->status_is( 200, 'REST3 .2.1' )->json_is( '/name' => $vendor->name )->json_hasnt('/contacts')
|
||||
->json_hasnt('/interfaces')->json_hasnt('/aliases');
|
||||
->status_is( 200, 'REST3 .2.1' )
|
||||
->json_is( '/name' => $vendor->name )
|
||||
->json_hasnt('/contacts')
|
||||
->json_hasnt('/interfaces')
|
||||
->json_hasnt('/aliases');
|
||||
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/"
|
||||
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200)
|
||||
->json_has('/contacts/0/name')->json_has('/interfaces/0/name')->json_has('/aliases/0/alias');
|
||||
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )
|
||||
->status_is(200)
|
||||
->json_has('/contacts/0/name')
|
||||
->json_has('/interfaces/0/name')
|
||||
->json_has('/aliases/0/alias');
|
||||
|
||||
delete $api_vendor->{contacts};
|
||||
delete $api_vendor->{interfaces};
|
||||
|
|
@ -383,8 +428,11 @@ subtest 'update() tests' => sub {
|
|||
->status_is( 200, 'REST3 .2.1' );
|
||||
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/"
|
||||
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200)
|
||||
->json_has('/contacts/0/name')->json_has('/interfaces/0/name')->json_has('/aliases/0/alias');
|
||||
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )
|
||||
->status_is(200)
|
||||
->json_has('/contacts/0/name')
|
||||
->json_has('/interfaces/0/name')
|
||||
->json_has('/aliases/0/alias');
|
||||
|
||||
$api_vendor->{contacts} = [];
|
||||
$api_vendor->{interfaces} = [];
|
||||
|
|
@ -394,8 +442,11 @@ subtest 'update() tests' => sub {
|
|||
->status_is( 200, 'REST3 .2.1' );
|
||||
|
||||
$t->get_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/"
|
||||
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )->status_is(200)
|
||||
->json_is( '/contacts', [] )->json_is( '/interfaces', [] )->json_is( '/aliases', [] );
|
||||
. $vendor->id => { 'x-koha-embed' => 'contacts,interfaces,aliases' } )
|
||||
->status_is(200)
|
||||
->json_is( '/contacts', [] )
|
||||
->json_is( '/interfaces', [] )
|
||||
->json_is( '/aliases', [] );
|
||||
};
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -452,7 +503,8 @@ subtest 'delete() tests' => sub {
|
|||
$invoice->delete;
|
||||
|
||||
$t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )
|
||||
->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' );
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
$t->delete_ok( "//$auth_userid:$password@/api/v1/acquisitions/vendors/" . $vendor->id )->status_is(404);
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ subtest 'anonymous access' => sub {
|
|||
|
||||
my $today = dt_from_string;
|
||||
my $yesterday = dt_from_string->add( days => -1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $tomorrow = dt_from_string->add( days => 1 );
|
||||
my $res;
|
||||
|
||||
$builder->build_object(
|
||||
|
|
@ -104,7 +104,8 @@ subtest 'anonymous access' => sub {
|
|||
|
||||
is( scalar @{$res}, 1, 'There is now one active and public additional content' );
|
||||
|
||||
$t->get_ok( "/api/v1/public/additional_contents" => { 'x-koha-embed' => 'translated_contents' } )->status_is(200)
|
||||
$t->get_ok( "/api/v1/public/additional_contents" => { 'x-koha-embed' => 'translated_contents' } )
|
||||
->status_is(200)
|
||||
->json_is(
|
||||
'/0' => {
|
||||
%{ $public_additional_contents->to_api( { public => 1 } ) },
|
||||
|
|
@ -142,7 +143,7 @@ subtest 'anonymous access' => sub {
|
|||
%{ $public_additional_contents->to_api( { public => 1 } ) },
|
||||
translated_contents => $public_additional_contents->translated_contents->to_api( { public => 1 } )
|
||||
}
|
||||
)->json_hasnt('/1');
|
||||
)->json_hasnt('/1');
|
||||
|
||||
$t->get_ok( "/api/v1/public/additional_contents?q={\"translated_contents.lang\": \"fr-FR\"}" =>
|
||||
{ 'x-koha-embed' => 'translated_contents' } )->status_is(200)->json_is(
|
||||
|
|
@ -150,7 +151,7 @@ subtest 'anonymous access' => sub {
|
|||
%{ $second_public_additional_contents->to_api( { public => 1 } ) },
|
||||
translated_contents => $second_public_additional_contents->translated_contents->to_api( { public => 1 } )
|
||||
}
|
||||
)->json_hasnt('/1');
|
||||
)->json_hasnt('/1');
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
||||
|
|
|
|||
|
|
@ -105,26 +105,34 @@ subtest 'list() tests' => sub {
|
|||
->count - 1;
|
||||
## Authorized user tests
|
||||
# Make sure we are returned with the correct amount of macros
|
||||
$t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros")->status_is( 200, 'REST3.2.2' )
|
||||
->json_has( '/' . $macros_index . '/macro_id' )->json_hasnt( '/' . ( $macros_index + 1 ) . '/macro_id' );
|
||||
$t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros")
|
||||
->status_is( 200, 'REST3.2.2' )
|
||||
->json_has( '/' . $macros_index . '/macro_id' )
|
||||
->json_hasnt( '/' . ( $macros_index + 1 ) . '/macro_id' );
|
||||
|
||||
subtest 'query parameters' => sub {
|
||||
|
||||
plan tests => 15;
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros?name=" . $macro_2->name )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros?name=" . $macro_2->name )
|
||||
->status_is(200)
|
||||
->json_is( [ $macro_2->to_api ] );
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros?name=" . $macro_3->name )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros?name=" . $macro_3->name )
|
||||
->status_is(200)
|
||||
->json_is( [] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?macro_text=delete%20100")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?macro_text=delete%20100")
|
||||
->status_is(200)
|
||||
->json_is( [ $macro_1->to_api, $macro_2->to_api, $macro_4->to_api ] );
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros?patron_id=" . $patron_1->borrowernumber )
|
||||
->status_is(200)->json_is( [ $macro_1->to_api, $macro_2->to_api ] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?shared=1")->status_is(200)
|
||||
->status_is(200)
|
||||
->json_is( [ $macro_1->to_api, $macro_2->to_api ] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?shared=1")
|
||||
->status_is(200)
|
||||
->json_is( [ $macro_2->to_api, $macro_4->to_api ] );
|
||||
};
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?macro_blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/advanced_editor/macros?macro_blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/macro_blah', message => 'Malformed query string' } ] );
|
||||
|
||||
};
|
||||
|
|
@ -174,19 +182,22 @@ subtest 'get() tests' => sub {
|
|||
->json_is( '/error' => 'This macro is shared, you must access it via advanced_editor/macros/shared' );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/shared/" . $macro_1->id )
|
||||
->status_is( 200, 'Can get a shared macro via shared endpoint' )->json_is( $macro_1->to_api );
|
||||
->status_is( 200, 'Can get a shared macro via shared endpoint' )
|
||||
->json_is( $macro_1->to_api );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/" . $macro_2->id )
|
||||
->status_is( 403, 'Cannot access another users macro' )
|
||||
->json_is( '/error' => 'You do not have permission to access this macro' );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/" . $macro_3->id )
|
||||
->status_is( 200, 'Can get your own private macro' )->json_is( $macro_3->to_api );
|
||||
->status_is( 200, 'Can get your own private macro' )
|
||||
->json_is( $macro_3->to_api );
|
||||
|
||||
my $non_existent_code = $macro_1->id;
|
||||
$macro_1->delete;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/" . $non_existent_code )->status_is(404)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/advanced_editor/macros/" . $non_existent_code )
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Macro not found' );
|
||||
|
||||
};
|
||||
|
|
@ -243,7 +254,8 @@ subtest 'add() tests' => sub {
|
|||
$macro_with_invalid_field->{'big_mac_ro'} = 'Mac attack';
|
||||
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: big_mac_ro.",
|
||||
|
|
@ -254,7 +266,8 @@ subtest 'add() tests' => sub {
|
|||
|
||||
# Authorized attempt to write
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_values )
|
||||
->status_is( 201, 'REST3.2.1' )->json_has( '/macro_id', 'We generated a new id' )
|
||||
->status_is( 201, 'REST3.2.1' )
|
||||
->json_has( '/macro_id', 'We generated a new id' )
|
||||
->json_is( '/name' => $macro_values->{name}, 'The name matches what we supplied' )
|
||||
->json_is( '/macro_text' => $macro_values->{macro_text}, 'The text matches what we supplied' )
|
||||
->json_is( '/patron_id' => $macro_values->{patron_id}, 'The borrower matches the borrower who submitted' )
|
||||
|
|
@ -267,7 +280,8 @@ subtest 'add() tests' => sub {
|
|||
# Authorized attempt to create with existing id
|
||||
$macro_values->{macro_id} = $macro_id;
|
||||
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_values )->status_is(400)
|
||||
$t->post_ok( "//$auth_userid:$password@/api/v1/advanced_editor/macros" => json => $macro_values )
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
'/errors' => [
|
||||
{
|
||||
|
|
@ -368,7 +382,8 @@ subtest 'update() tests' => sub {
|
|||
|
||||
$t->put_ok(
|
||||
"//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_id" => json => $macro_with_missing_field )
|
||||
->status_is(400)->json_has( "/errors" => [ { message => "Missing property.", path => "/body/macro_text" } ] );
|
||||
->status_is(400)
|
||||
->json_has( "/errors" => [ { message => "Missing property.", path => "/body/macro_text" } ] );
|
||||
|
||||
my $macro_update = {
|
||||
name => "Macro-update",
|
||||
|
|
@ -422,7 +437,8 @@ subtest 'update() tests' => sub {
|
|||
|
||||
$t->put_ok(
|
||||
"//$auth_userid:$password@/api/v1/advanced_editor/macros/$macro_id" => json => $macro_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: big_mac_ro.",
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ subtest 'cancel() tests' => sub {
|
|||
my $deleted_article_request_id = $deleted_article_request->id;
|
||||
$deleted_article_request->delete;
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/article_requests/$deleted_article_request_id")->status_is(404)
|
||||
$t->delete_ok("//$userid:$password@/api/v1/article_requests/$deleted_article_request_id")
|
||||
->status_is(404)
|
||||
->json_is( '/error_code' => 'not_found' );
|
||||
|
||||
my $article_request = $builder->build_object(
|
||||
|
|
@ -67,7 +68,8 @@ subtest 'cancel() tests' => sub {
|
|||
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/article_requests/"
|
||||
. $article_request->id
|
||||
. "?cancellation_reason=$reason¬es=$notes" )->status_is( 204, 'REST3.2.4' )
|
||||
. "?cancellation_reason=$reason¬es=$notes" )
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( q{}, 'REST3.2.4' );
|
||||
|
||||
# refresh object
|
||||
|
|
@ -109,7 +111,8 @@ subtest 'patron_cancel() tests' => sub {
|
|||
|
||||
# delete non existent article request
|
||||
$t->delete_ok("//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/$deleted_article_request_id")
|
||||
->status_is(404)->json_is( '/error_code' => 'not_found' );
|
||||
->status_is(404)
|
||||
->json_is( '/error_code' => 'not_found' );
|
||||
|
||||
my $another_patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||
my $another_patron_id = $another_patron->id;
|
||||
|
|
@ -119,12 +122,14 @@ subtest 'patron_cancel() tests' => sub {
|
|||
|
||||
# delete another patron's request when unauthorized
|
||||
$t->delete_ok( "/api/v1/public/patrons/$another_patron_id/article_requests/" . $article_request_2->id )
|
||||
->status_is(401)->json_is( '/error' => "Authentication failure." );
|
||||
->status_is(401)
|
||||
->json_is( '/error' => "Authentication failure." );
|
||||
|
||||
# delete another patron's request
|
||||
$t->delete_ok(
|
||||
"//$userid:$password@/api/v1/public/patrons/$another_patron_id/article_requests/" . $article_request_2->id )
|
||||
->status_is(403)->json_is( '/error' => "Unprivileged user cannot access another user's resources" );
|
||||
->status_is(403)
|
||||
->json_is( '/error' => "Unprivileged user cannot access another user's resources" );
|
||||
|
||||
my $another_article_request = $builder->build_object(
|
||||
{
|
||||
|
|
@ -135,7 +140,8 @@ subtest 'patron_cancel() tests' => sub {
|
|||
|
||||
$t->delete_ok(
|
||||
"//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/" . $another_article_request->id )
|
||||
->status_is(404)->json_is( '/error_code' => 'not_found' );
|
||||
->status_is(404)
|
||||
->json_is( '/error_code' => 'not_found' );
|
||||
|
||||
my $article_request = $builder->build_object(
|
||||
{
|
||||
|
|
@ -149,7 +155,8 @@ subtest 'patron_cancel() tests' => sub {
|
|||
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/public/patrons/$patron_id/article_requests/"
|
||||
. $article_request->id
|
||||
. "?cancellation_reason=$reason¬es=$notes" )->status_is( 204, 'REST3.2.4' )
|
||||
. "?cancellation_reason=$reason¬es=$notes" )
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( q{}, 'REST3.2.4' );
|
||||
|
||||
# refresh object
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ subtest 'under() tests' => sub {
|
|||
t::lib::Mocks::mock_preference( 'RESTPublicAPI', 0 );
|
||||
$tx = $t->ua->build_tx( POST => "/api/v1/public/patrons/$borrowernumber/password" );
|
||||
$tx->req->env( { REMOTE_ADDR => $remote_address } );
|
||||
$t->request_ok($tx)->status_is(403)
|
||||
$t->request_ok($tx)
|
||||
->status_is(403)
|
||||
->json_is( '/error', 'Configuration prevents the usage of this endpoint by unprivileged users' );
|
||||
|
||||
# enable the /public namespace
|
||||
|
|
|
|||
|
|
@ -68,8 +68,11 @@ subtest 'token-based tests' => sub {
|
|||
client_id => $api_key->client_id,
|
||||
client_secret => $api_key->plain_text_secret
|
||||
};
|
||||
$t->post_ok( '/api/v1/oauth/token', form => $formData )->status_is(200)->json_is( '/expires_in' => 3600 )
|
||||
->json_is( '/token_type' => 'Bearer' )->json_has('/access_token');
|
||||
$t->post_ok( '/api/v1/oauth/token', form => $formData )
|
||||
->status_is(200)
|
||||
->json_is( '/expires_in' => 3600 )
|
||||
->json_is( '/token_type' => 'Bearer' )
|
||||
->json_has('/access_token');
|
||||
|
||||
my $access_token = $t->tx->res->json->{access_token};
|
||||
|
||||
|
|
@ -167,7 +170,8 @@ subtest 'cookie-based tests' => sub {
|
|||
$tx->req->cookies( { name => 'CGISESSID', value => $session->id } );
|
||||
$tx->req->env( { REMOTE_ADDR => $remote_address } );
|
||||
|
||||
$t->request_ok($tx)->status_is( 401, 'Anonymous session on permission protected resource returns 401' )
|
||||
$t->request_ok($tx)
|
||||
->status_is( 401, 'Anonymous session on permission protected resource returns 401' )
|
||||
->json_is( { error => 'Authentication failure.' } );
|
||||
};
|
||||
|
||||
|
|
@ -259,7 +263,8 @@ subtest 'x-koha-library tests' => sub {
|
|||
is( $userenv->{branch}, $unprivileged->branchcode, 'branch set correctly' );
|
||||
|
||||
$t->get_ok( "//$unprivileged_userid:$password@/api/v1/cities" => { 'x-koha-library' => $library->id } )
|
||||
->status_is(403)->json_is( '/error' => 'Unauthorized attempt to set library to ' . $library->id );
|
||||
->status_is(403)
|
||||
->json_is( '/error' => 'Unauthorized attempt to set library to ' . $library->id );
|
||||
|
||||
$t->get_ok( "//$superlibrarian_userid:$password@/api/v1/cities" => { 'x-koha-library' => $library->id } )
|
||||
->status_is(200);
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ subtest 'success tests' => sub {
|
|||
$patron->flags(undef)->store;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/patrons")
|
||||
->status_is( 403, 'Successful authentication and not enough permissions' )->json_is(
|
||||
->status_is( 403, 'Successful authentication and not enough permissions' )
|
||||
->json_is(
|
||||
'/error' => 'Authorization failure. Missing required permission(s).',
|
||||
'Error message returned'
|
||||
);
|
||||
|
|
@ -103,7 +104,8 @@ subtest 'success tests' => sub {
|
|||
$patron->flags(undef)->store;
|
||||
|
||||
$t->get_ok("//$cardnumber:$password@/api/v1/patrons")
|
||||
->status_is( 403, 'Successful authentication and not enough permissions' )->json_is(
|
||||
->status_is( 403, 'Successful authentication and not enough permissions' )
|
||||
->json_is(
|
||||
'/error' => 'Authorization failure. Missing required permission(s).',
|
||||
'Error message returned'
|
||||
);
|
||||
|
|
@ -133,17 +135,20 @@ subtest 'failure tests' => sub {
|
|||
# expire patron's password
|
||||
$patron->password_expiration_date( dt_from_string->subtract( days => 1 ) )->store;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/patrons")->status_is(403)
|
||||
$t->get_ok("//$userid:$password@/api/v1/patrons")
|
||||
->status_is(403)
|
||||
->json_is( '/error' => 'Password has expired', 'Password expired' );
|
||||
|
||||
$t->get_ok("//@/api/v1/patrons")->status_is( 401, 'No credentials passed' );
|
||||
|
||||
$t->get_ok("//$userid:$bad_password@/api/v1/patrons")->status_is( 403, 'Failed authentication, invalid password' )
|
||||
$t->get_ok("//$userid:$bad_password@/api/v1/patrons")
|
||||
->status_is( 403, 'Failed authentication, invalid password' )
|
||||
->json_is( '/error' => 'Invalid password', 'Error message returned' );
|
||||
|
||||
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 0 );
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/patrons")->status_is( 401, 'Basic authentication is disabled' )
|
||||
$t->get_ok("//$userid:$password@/api/v1/patrons")
|
||||
->status_is( 401, 'Basic authentication is disabled' )
|
||||
->json_is( '/error' => 'Basic authentication disabled', 'Expected error message rendered' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
|
|
@ -63,19 +63,22 @@ subtest 'list_av_from_category() tests' => sub {
|
|||
|
||||
## Authorized user tests
|
||||
# No category, 404 expected
|
||||
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/NON_EXISTS/authorised_values")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/NON_EXISTS/authorised_values")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Category not found' );
|
||||
|
||||
my $av_cat = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } )->category_name;
|
||||
|
||||
# No AVs, so empty array should be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")
|
||||
->status_is(200)
|
||||
->json_is( [] );
|
||||
|
||||
my $av = $builder->build_object( { class => 'Koha::AuthorisedValues', value => { category => $av_cat } } );
|
||||
|
||||
# One av created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/authorised_value_categories/$av_cat/authorised_values")
|
||||
->status_is(200)
|
||||
->json_is( [ $av->to_api ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
@ -88,13 +91,15 @@ subtest 'list_av_from_category() tests' => sub {
|
|||
my $av_cat_3 =
|
||||
$builder->build_object( { class => 'Koha::AuthorisedValueCategories', value => { category_name => 'cat_b' } } );
|
||||
my $query = { "me.category_name" => [ $av_cat_2->category_name, $av_cat_3->category_name ] };
|
||||
$t->get_ok( "//$userid:$password@/api/v1/authorised_value_categories?q=" . encode_json($query) )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/authorised_value_categories?q=" . encode_json($query) )
|
||||
->status_is(200)
|
||||
->json_is( [ $av_cat_2->to_api, $av_cat_3->to_api ] );
|
||||
|
||||
# Test the above but with x-koha-embed: authorised_values
|
||||
my $embedded_query = { "me.category_name" => [ $av_cat_2->category_name, $av_cat_3->category_name ] };
|
||||
$t->get_ok( "//$userid:$password@/api/v1/authorised_value_categories?q="
|
||||
. encode_json($embedded_query) => { 'x-koha-embed' => 'authorised_values' } )->status_is(200)
|
||||
. encode_json($embedded_query) => { 'x-koha-embed' => 'authorised_values' } )
|
||||
->status_is(200)
|
||||
->json_has( '/0/authorised_values', 'authorised_values object correctly embedded' )
|
||||
->json_has( '/1/authorised_values', 'authorised_values object correctly embedded' )
|
||||
->json_hasnt( '/2/', 'authorised_values object correctly embedded' );
|
||||
|
|
|
|||
|
|
@ -84,7 +84,8 @@ subtest 'get() tests' => sub {
|
|||
->status_is(400);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id => { Accept => 'application/json' } )
|
||||
->status_is(200)->json_is( '/authority_id', $authority->id )
|
||||
->status_is(200)
|
||||
->json_is( '/authority_id', $authority->id )
|
||||
->json_is( '/framework_id', $authority->authtypecode );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id => { Accept => 'application/marcxml+xml' } )
|
||||
|
|
@ -98,7 +99,8 @@ subtest 'get() tests' => sub {
|
|||
->status_is(200);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id => { Accept => 'text/plain' } )
|
||||
->status_is(200)->content_is(
|
||||
->status_is(200)
|
||||
->content_is(
|
||||
q|LDR 00079 2200049 4500
|
||||
001 1001
|
||||
110 _9102
|
||||
|
|
@ -107,7 +109,8 @@ subtest 'get() tests' => sub {
|
|||
|
||||
$authority->delete;
|
||||
$t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id => { Accept => 'application/marc' } )
|
||||
->status_is(404)->json_is( '/error', 'Authority record not found' );
|
||||
->status_is(404)
|
||||
->json_is( '/error', 'Authority record not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -149,7 +152,8 @@ subtest 'delete() tests' => sub {
|
|||
|
||||
$patron->flags( 2**14 )->store; # 14 => editauthorities userflag
|
||||
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id )->status_is( 204, 'REST3.2.4' )
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id )
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
$t->delete_ok( "//$userid:$password@/api/v1/authorities/" . $authority->id )->status_is(404);
|
||||
|
|
@ -214,7 +218,8 @@ subtest 'post() tests' => sub {
|
|||
{ 'Content-Type' => 'application/marc-in-json', 'x-authority-type' => 'CORPO_NAME' } => $mij )
|
||||
->status_is(409)
|
||||
->header_exists_not( 'Location', 'Location header is only set when the new resource is created' )
|
||||
->json_like( '/error' => qr/Duplicate record (\d*)/ )->json_is( '/error_code' => q{duplicate} );
|
||||
->json_like( '/error' => qr/Duplicate record (\d*)/ )
|
||||
->json_is( '/error_code' => q{duplicate} );
|
||||
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/authorities" => {
|
||||
|
|
@ -308,7 +313,8 @@ subtest 'put() tests' => sub {
|
|||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/authorities/$authid" =>
|
||||
{ 'Content-Type' => 'application/marcxml+xml', 'x-authority-type' => $authtypecode } => $marcxml )
|
||||
->status_is(200)->json_has('/id');
|
||||
->status_is(200)
|
||||
->json_has('/id');
|
||||
|
||||
$authority = Koha::Authorities->find($authid);
|
||||
$record = $authority->record;
|
||||
|
|
@ -318,7 +324,8 @@ subtest 'put() tests' => sub {
|
|||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/authorities/$authid" =>
|
||||
{ 'Content-Type' => 'application/marc-in-json', 'x-authority-type' => $authtypecode } => $mij )
|
||||
->status_is(200)->json_has('/id');
|
||||
->status_is(200)
|
||||
->json_has('/id');
|
||||
|
||||
$authority = Koha::Authorities->find($authid);
|
||||
$record = $authority->record;
|
||||
|
|
@ -327,7 +334,8 @@ subtest 'put() tests' => sub {
|
|||
is( $subfield_a, 'MIJ' );
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/authorities/$authid" =>
|
||||
{ 'Content-Type' => 'application/marc', 'x-authority-type' => $authtypecode } => $marc )->status_is(200)
|
||||
{ 'Content-Type' => 'application/marc', 'x-authority-type' => $authtypecode } => $marc )
|
||||
->status_is(200)
|
||||
->json_has('/id');
|
||||
|
||||
$authority = Koha::Authorities->find($authid);
|
||||
|
|
|
|||
|
|
@ -81,7 +81,8 @@ subtest 'get() tests' => sub {
|
|||
->status_is(400);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } )
|
||||
->status_is(200)->json_is( '/title', 'The unbearable lightness of being' )
|
||||
->status_is(200)
|
||||
->json_is( '/title', 'The unbearable lightness of being' )
|
||||
->json_is( '/author', 'Milan Kundera' );
|
||||
|
||||
$t->get_ok(
|
||||
|
|
@ -96,18 +97,21 @@ subtest 'get() tests' => sub {
|
|||
->status_is(200);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } )
|
||||
->status_is(200)->content_is( $biblio->metadata->record->as_formatted );
|
||||
->status_is(200)
|
||||
->content_is( $biblio->metadata->record->as_formatted );
|
||||
|
||||
# Simulate a data error situation (BZ35246)
|
||||
$biblio->biblioitem->delete();
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } )
|
||||
->status_is(500)->json_is( '/error_code', 'internal_server_error' )
|
||||
->json_is( '/error', 'Something went wrong, check Koha logs for details.' );
|
||||
->status_is(500)
|
||||
->json_is( '/error_code', 'internal_server_error' )
|
||||
->json_is( '/error', 'Something went wrong, check Koha logs for details.' );
|
||||
|
||||
$biblio->delete;
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } )
|
||||
->status_is(404)->json_is( '/error', 'Bibliographic record not found' );
|
||||
->status_is(404)
|
||||
->json_is( '/error', 'Bibliographic record not found' );
|
||||
|
||||
subtest 'marc-in-json encoding tests' => sub {
|
||||
|
||||
|
|
@ -124,7 +128,8 @@ subtest 'get() tests' => sub {
|
|||
|
||||
my $result = $t->get_ok(
|
||||
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marc-in-json' } )
|
||||
->status_is(200)->tx->res->body;
|
||||
->status_is(200)
|
||||
->tx->res->body;
|
||||
|
||||
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics );
|
||||
|
||||
|
|
@ -153,7 +158,8 @@ subtest 'get() tests' => sub {
|
|||
|
||||
my $result = $t->get_ok(
|
||||
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marcxml+xml' } )
|
||||
->status_is(200)->tx->res->body;
|
||||
->status_is(200)
|
||||
->tx->res->body;
|
||||
|
||||
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics );
|
||||
|
||||
|
|
@ -186,14 +192,16 @@ subtest 'get_items() tests' => sub {
|
|||
|
||||
$patron->flags(4)->store;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items" )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items" )
|
||||
->status_is(200)
|
||||
->json_is( '' => [], 'No items on the biblio' );
|
||||
|
||||
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
|
||||
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items?_order_by=item_id" )
|
||||
->status_is(200)->json_is( '' => [ $item_1->to_api, $item_2->to_api ], 'The items are returned' );
|
||||
->status_is(200)
|
||||
->json_is( '' => [ $item_1->to_api, $item_2->to_api ], 'The items are returned' );
|
||||
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items" => { "x-koha-embed" => "+strings" } )
|
||||
|
|
@ -234,7 +242,8 @@ subtest 'get_items() tests' => sub {
|
|||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/"
|
||||
. $item->biblionumber
|
||||
. "/items" => { "x-koha-embed" => "first_hold+strings" } )->status_is(200)
|
||||
. "/items" => { "x-koha-embed" => "first_hold+strings" } )
|
||||
->status_is(200)
|
||||
->json_is(
|
||||
'/0/first_hold/_strings/pickup_library_id' => { type => 'library', str => $pickup_library->branchname } );
|
||||
};
|
||||
|
|
@ -282,7 +291,8 @@ subtest 'delete() tests' => sub {
|
|||
$item->delete();
|
||||
|
||||
# Bibs with no items can be deleted
|
||||
$t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")->status_is( 204, 'REST3.2.4' )
|
||||
$t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")->status_is(404);
|
||||
|
|
@ -329,7 +339,8 @@ subtest 'get_public() tests' => sub {
|
|||
. $biblio->biblionumber => { Accept => 'application/weird+format' } )->status_is(400);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } )
|
||||
->status_is(200)->content_like(qr{100\s+_aMilan Kundera})
|
||||
->status_is(200)
|
||||
->content_like(qr{100\s+_aMilan Kundera})
|
||||
->content_like(qr{245\s+_aThe unbearable lightness of being});
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/"
|
||||
|
|
@ -343,7 +354,8 @@ subtest 'get_public() tests' => sub {
|
|||
->status_is(200);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } )
|
||||
->status_is(200)->content_is( $biblio->metadata->record->as_formatted );
|
||||
->status_is(200)
|
||||
->content_is( $biblio->metadata->record->as_formatted );
|
||||
|
||||
subtest 'anonymous access' => sub {
|
||||
plan tests => 9;
|
||||
|
|
@ -357,7 +369,8 @@ subtest 'get_public() tests' => sub {
|
|||
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } )
|
||||
->status_is(200);
|
||||
|
||||
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } )->status_is(200)
|
||||
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } )
|
||||
->status_is(200)
|
||||
->content_is( $biblio->metadata->record->as_formatted );
|
||||
};
|
||||
|
||||
|
|
@ -376,7 +389,8 @@ subtest 'get_public() tests' => sub {
|
|||
|
||||
my $result =
|
||||
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc-in-json' } )
|
||||
->status_is(200)->tx->res->body;
|
||||
->status_is(200)
|
||||
->tx->res->body;
|
||||
|
||||
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics );
|
||||
|
||||
|
|
@ -392,7 +406,8 @@ subtest 'get_public() tests' => sub {
|
|||
Koha::Caches->get_instance()->flush_all;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } )
|
||||
->status_is(200)->content_unlike(qr{100\s+_aMilan Kundera})
|
||||
->status_is(200)
|
||||
->content_unlike(qr{100\s+_aMilan Kundera})
|
||||
->content_like(qr{245\s+_aThe unbearable lightness of being});
|
||||
|
||||
subtest 'hidden_in_opac tests' => sub {
|
||||
|
|
@ -456,7 +471,8 @@ subtest 'get_public() tests' => sub {
|
|||
$biblio->delete;
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } )
|
||||
->status_is(404)->json_is( '/error', 'Bibliographic record not found' );
|
||||
->status_is(404)
|
||||
->json_is( '/error', 'Bibliographic record not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -581,7 +597,8 @@ subtest 'pickup_locations() tests' => sub {
|
|||
. "patron_id="
|
||||
. $patron->id
|
||||
. "&_order_by=marc_org_code"
|
||||
. "&_per_page=1" )->json_is( [$library_1_api] )
|
||||
. "&_per_page=1" )
|
||||
->json_is( [$library_1_api] )
|
||||
->header_is( 'X-Total-Count', '4', '4 is the count for libraries with pickup_location=1' )
|
||||
->header_is( 'X-Base-Total-Count', '4', '4 is the count for libraries with pickup_location=1' )
|
||||
->header_unlike( 'Link', qr|rel="prev"| )
|
||||
|
|
@ -612,8 +629,11 @@ subtest 'pickup_locations() tests' => sub {
|
|||
. "patron_id="
|
||||
. $patron->id
|
||||
. "&_order_by=marc_org_code"
|
||||
. "&_per_page=1" )->json_is( [$library_1_api] )->header_is( 'X-Total-Count', '2' )
|
||||
->header_is( 'X-Base-Total-Count', '2' )->header_unlike( 'Link', qr|rel="prev"| )
|
||||
. "&_per_page=1" )
|
||||
->json_is( [$library_1_api] )
|
||||
->header_is( 'X-Total-Count', '2' )
|
||||
->header_is( 'X-Base-Total-Count', '2' )
|
||||
->header_unlike( 'Link', qr|rel="prev"| )
|
||||
->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="next"# )
|
||||
->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# )
|
||||
->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1).*>\; rel="last"# );
|
||||
|
|
@ -633,7 +653,8 @@ subtest 'pickup_locations() tests' => sub {
|
|||
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/biblios/" . $biblio->id . "/pickup_locations?" . "patron_id=" . $patron->id )
|
||||
->status_is(404)->json_is( '/error' => 'Bibliographic record not found' );
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Bibliographic record not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -672,13 +693,15 @@ subtest 'get_items_public() tests' => sub {
|
|||
|
||||
my $biblio = $builder->build_sample_biblio();
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->id . "/items" )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->id . "/items" )
|
||||
->status_is(200)
|
||||
->json_is( '' => [], 'No items on the biblio' );
|
||||
|
||||
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->id } );
|
||||
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->id, withdrawn => 1 } );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )
|
||||
->status_is(200)
|
||||
->json_is(
|
||||
'' => [
|
||||
$item_1->to_api( { public => 1 } ),
|
||||
|
|
@ -689,7 +712,8 @@ subtest 'get_items_public() tests' => sub {
|
|||
|
||||
$rules = { withdrawn => ['1'] };
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )
|
||||
->status_is(200)
|
||||
->json_is(
|
||||
'' => [ $item_1->to_api( { public => 1 } ) ],
|
||||
'The items are returned, hidden one is not returned'
|
||||
|
|
@ -702,7 +726,8 @@ subtest 'get_items_public() tests' => sub {
|
|||
|
||||
$override_hidden_items = 1;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )
|
||||
->status_is(200)
|
||||
->json_is(
|
||||
'' => [
|
||||
$item_1->to_api( { public => 1 } ),
|
||||
|
|
@ -755,7 +780,8 @@ subtest 'get_bookings() tests' => sub {
|
|||
|
||||
$t->get_ok( "//$unauth_userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )->status_is(403);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )
|
||||
->status_is(200)
|
||||
->json_is( '' => [], 'No bookings on the biblio' );
|
||||
|
||||
# One booking
|
||||
|
|
@ -773,7 +799,9 @@ subtest 'get_bookings() tests' => sub {
|
|||
}
|
||||
);
|
||||
|
||||
my $ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )->status_is(200)
|
||||
my $ret =
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )
|
||||
->status_is(200)
|
||||
->tx->res->json;
|
||||
|
||||
is_deeply( $ret, [ $booking_0->to_api ] );
|
||||
|
|
@ -846,7 +874,8 @@ subtest 'get_checkouts() tests' => sub {
|
|||
AddIssue( $patron, $item_2->barcode );
|
||||
|
||||
my $ret =
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts" )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts" )
|
||||
->status_is(200)
|
||||
->tx->res->json;
|
||||
|
||||
my $checkout_1 = Koha::Checkouts->find( { itemnumber => $item_1->id } );
|
||||
|
|
@ -856,13 +885,17 @@ subtest 'get_checkouts() tests' => sub {
|
|||
|
||||
AddReturn( $item_1->barcode );
|
||||
|
||||
$ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts" )->status_is(200)
|
||||
$ret =
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts" )
|
||||
->status_is(200)
|
||||
->tx->res->json;
|
||||
|
||||
is_deeply( $ret, [ $checkout_2->to_api ] );
|
||||
|
||||
$ret = $t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts?checked_in=1" )
|
||||
->status_is(200)->tx->res->json;
|
||||
$ret =
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts?checked_in=1" )
|
||||
->status_is(200)
|
||||
->tx->res->json;
|
||||
|
||||
my $old_checkout_1 = Koha::Old::Checkouts->find( $checkout_1->id );
|
||||
|
||||
|
|
@ -894,12 +927,18 @@ subtest 'set_rating() tests' => sub {
|
|||
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/ratings" => json => { rating => 3 } )
|
||||
->status_is(200)->json_is( '/rating', '3' )->json_is( '/average', '3' )->json_is( '/count', '1' );
|
||||
->status_is(200)
|
||||
->json_is( '/rating', '3' )
|
||||
->json_is( '/average', '3' )
|
||||
->json_is( '/count', '1' );
|
||||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/public/biblios/"
|
||||
. $biblio->biblionumber
|
||||
. "/ratings" => json => { rating => undef } )->status_is(200)->json_is( '/rating', undef )
|
||||
->json_is( '/average', '0' )->json_is( '/count', '0' );
|
||||
. "/ratings" => json => { rating => undef } )
|
||||
->status_is(200)
|
||||
->json_is( '/rating', undef )
|
||||
->json_is( '/average', '0' )
|
||||
->json_is( '/count', '0' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
||||
|
|
@ -1325,7 +1364,8 @@ subtest 'add() tests' => sub {
|
|||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/biblios" =>
|
||||
{ 'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode } => $marcxml )
|
||||
->status_is(200)->json_has('/id')
|
||||
->status_is(200)
|
||||
->json_has('/id')
|
||||
->header_is( 'Location' => "/api/v1/biblios/" . $t->tx->res->json->{id}, "REST3.4.1" );
|
||||
|
||||
$t->post_ok(
|
||||
|
|
@ -1336,7 +1376,8 @@ subtest 'add() tests' => sub {
|
|||
)->status_is(200)->json_has('/id');
|
||||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/biblios" =>
|
||||
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )->status_is(200)
|
||||
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )
|
||||
->status_is(200)
|
||||
->json_has('/id');
|
||||
|
||||
subtest 'x-record-source-id header tests' => sub {
|
||||
|
|
@ -1380,7 +1421,8 @@ subtest 'add() tests' => sub {
|
|||
$mock_biblio->mock( 'AddBiblio', sub { return ( undef, undef ); } );
|
||||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/biblios" =>
|
||||
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )->status_is(400)
|
||||
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
{
|
||||
error => 'Error creating record',
|
||||
|
|
@ -1808,7 +1850,8 @@ subtest 'put() tests' => sub {
|
|||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" =>
|
||||
{ 'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode } => $marcxml )
|
||||
->status_is(200)->json_has('/id');
|
||||
->status_is(200)
|
||||
->json_has('/id');
|
||||
|
||||
$biblio = Koha::Biblios->find($biblionumber);
|
||||
|
||||
|
|
@ -1816,14 +1859,16 @@ subtest 'put() tests' => sub {
|
|||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" =>
|
||||
{ 'Content-Type' => 'application/marc-in-json', 'x-framework-id' => $frameworkcode } => $mij )
|
||||
->status_is(200)->json_has('/id');
|
||||
->status_is(200)
|
||||
->json_has('/id');
|
||||
|
||||
$biblio = Koha::Biblios->find($biblionumber);
|
||||
|
||||
is( $biblio->title, 'Introduction to Attic Greek (Using mij) /' );
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" =>
|
||||
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )->status_is(200)
|
||||
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )
|
||||
->status_is(200)
|
||||
->json_has('/id');
|
||||
|
||||
$biblio = Koha::Biblios->find($biblionumber);
|
||||
|
|
@ -1880,8 +1925,10 @@ subtest 'list() tests' => sub {
|
|||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/json' } )->status_is(200);
|
||||
|
||||
my $result = $t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/marcxml+xml' } )
|
||||
->status_is(200)->tx->res->body;
|
||||
my $result =
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/marcxml+xml' } )
|
||||
->status_is(200)
|
||||
->tx->res->body;
|
||||
|
||||
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics );
|
||||
like( $result, qr/\Q$encoded_title/, "The title is not double encoded" );
|
||||
|
|
@ -1909,7 +1956,8 @@ subtest 'list() tests' => sub {
|
|||
|
||||
$query = encode_json( { biblio_id => $biblio->id } );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/json' } )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/json' } )
|
||||
->status_is(200)
|
||||
->json_is( '/0/timestamp' =>
|
||||
output_pref( { dt => $fixed_date, dateformat => 'rfc3339' }, 'biblio table timestamp takes precedence' ) );
|
||||
|
||||
|
|
@ -2273,7 +2321,8 @@ subtest 'merge() tests' => sub {
|
|||
my $result =
|
||||
$t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id1/merge" =>
|
||||
{ 'Content-Type' => 'application/json', 'Accept' => 'application/marc-in-json' } => $json_input1 )
|
||||
->status_is(200)->tx->res->body;
|
||||
->status_is(200)
|
||||
->tx->res->body;
|
||||
like( $result, qr/$title_1/, "Merged record has the correct title" );
|
||||
unlike( $result, qr/$title_2/, "Merged record doesn't have the wrong title" );
|
||||
|
||||
|
|
@ -2285,7 +2334,8 @@ subtest 'merge() tests' => sub {
|
|||
$result =
|
||||
$t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id1/merge" =>
|
||||
{ 'Content-Type' => 'application/json', 'Accept' => 'application/marc-in-json' } => $json_input2 )
|
||||
->status_is(200)->tx->res->body;
|
||||
->status_is(200)
|
||||
->tx->res->body;
|
||||
like( $result, qr/Using mij/, "Update with Marc-in-json record" );
|
||||
unlike( $result, qr/$title_1/, "Change all record with dat in the 'datarecord' field" );
|
||||
|
||||
|
|
|
|||
|
|
@ -135,11 +135,13 @@ subtest 'list() tests' => sub {
|
|||
|
||||
$api_filter = encode_json(
|
||||
{ 'me.start_date' => { '<=' => output_pref( { dateformat => "rfc3339", dt => dt_from_string } ) } } );
|
||||
$t->get_ok("//$userid:$password@/api/v1/bookings?q=$api_filter")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/bookings?q=$api_filter")
|
||||
->status_is(200)
|
||||
->json_is( '' => [ $booking_0->to_api ], 'filtering to before today also works' );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/bookings?booking_blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/bookings?booking_blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/booking_blah', message => 'Malformed query string' } ] );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -176,14 +178,16 @@ subtest 'get() tests' => sub {
|
|||
$t->get_ok( "//$unauth_userid:$password@/api/v1/bookings/" . $booking->booking_id )->status_is(403);
|
||||
|
||||
# Authorized user tests
|
||||
$t->get_ok( "//$userid:$password@/api/v1/bookings/" . $booking->booking_id )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/bookings/" . $booking->booking_id )
|
||||
->status_is(200)
|
||||
->json_is( $booking->to_api );
|
||||
|
||||
my $booking_to_delete = $builder->build_object( { class => 'Koha::Bookings' } );
|
||||
my $non_existent_id = $booking_to_delete->id;
|
||||
$booking_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/bookings/$non_existent_id")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/bookings/$non_existent_id")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Booking not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -244,7 +248,8 @@ subtest 'add() tests' => sub {
|
|||
# Authorized attempt to write invalid data
|
||||
my $booking_with_invalid_field = { %{$booking}, blah => 'some stuff' };
|
||||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/bookings" => json => $booking_with_invalid_field )->status_is(400)
|
||||
$t->post_ok( "//$userid:$password@/api/v1/bookings" => json => $booking_with_invalid_field )
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
|
|
@ -256,8 +261,10 @@ subtest 'add() tests' => sub {
|
|||
|
||||
# Authorized attempt to write
|
||||
my $booking_id =
|
||||
$t->post_ok( "//$userid:$password@/api/v1/bookings" => json => $booking )->status_is( 201, 'REST3.2.1' )
|
||||
->header_like( Location => qr|^\/api\/v1\/bookings/\d*|, 'REST3.4.1' )->json_is( '/biblio_id' => $biblio->id )
|
||||
$t->post_ok( "//$userid:$password@/api/v1/bookings" => json => $booking )
|
||||
->status_is( 201, 'REST3.2.1' )
|
||||
->header_like( Location => qr|^\/api\/v1\/bookings/\d*|, 'REST3.4.1' )
|
||||
->json_is( '/biblio_id' => $biblio->id )
|
||||
->tx->res->json->{booking_id};
|
||||
|
||||
# Authorized attempt to create with null id
|
||||
|
|
@ -267,7 +274,8 @@ subtest 'add() tests' => sub {
|
|||
# Authorized attempt to create with existing id
|
||||
$booking->{booking_id} = $booking_id;
|
||||
warnings_like {
|
||||
$t->post_ok( "//$userid:$password@/api/v1/bookings" => json => $booking )->status_is(409)
|
||||
$t->post_ok( "//$userid:$password@/api/v1/bookings" => json => $booking )
|
||||
->status_is(409)
|
||||
->json_is( "/error" => "Duplicate booking_id" );
|
||||
}
|
||||
qr/DBD::mysql::st execute failed: Duplicate entry '(.*?)' for key '(.*\.?)PRIMARY'/;
|
||||
|
|
@ -335,7 +343,8 @@ subtest 'update() tests' => sub {
|
|||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_missing_field )
|
||||
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/biblio_id" } ] );
|
||||
->status_is(400)
|
||||
->json_is( "/errors" => [ { message => "Missing property.", path => "/body/biblio_id" } ] );
|
||||
|
||||
# Full object update on PUT
|
||||
my $booking_with_updated_field = {
|
||||
|
|
@ -348,7 +357,8 @@ subtest 'update() tests' => sub {
|
|||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_updated_field )
|
||||
->status_is(200)->json_is( '/biblio_id' => $biblio->id );
|
||||
->status_is(200)
|
||||
->json_is( '/biblio_id' => $biblio->id );
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
my $booking_with_invalid_field = {
|
||||
|
|
@ -362,7 +372,8 @@ subtest 'update() tests' => sub {
|
|||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
|
@ -431,7 +442,8 @@ subtest 'delete() tests' => sub {
|
|||
# Unauthorized attempt to delete
|
||||
$t->delete_ok("//$unauth_userid:$password@/api/v1/bookings/$booking_id")->status_is(403);
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/bookings/$booking_id")->status_is( 204, 'REST3.2.4' )
|
||||
$t->delete_ok("//$userid:$password@/api/v1/bookings/$booking_id")
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/bookings/$booking_id")->status_is(404);
|
||||
|
|
@ -491,7 +503,8 @@ subtest 'patch() tests' => sub {
|
|||
};
|
||||
|
||||
$t->patch_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ subtest 'list() tests' => sub {
|
|||
my $new_register = $builder->build_object( { class => 'Koha::Cash::Registers' } );
|
||||
|
||||
# One more register created, both should be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers")
|
||||
->status_is(200)
|
||||
->json_is( [ $register->to_api, $new_register->to_api, ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ subtest 'list() tests' => sub {
|
|||
my $non_existent_cr_id = $cash_register_to_delete->id;
|
||||
$cash_register_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers/$non_existent_cr_id/cashups")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers/$non_existent_cr_id/cashups")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Register not found' );
|
||||
|
||||
my $register = $builder->build_object( { class => 'Koha::Cash::Registers' } );
|
||||
|
|
@ -89,7 +90,8 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# One cashup created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers/$register_id/cashups")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers/$register_id/cashups")
|
||||
->status_is(200)
|
||||
->json_is( [ $cashup->to_api ] );
|
||||
|
||||
my $another_cashup = $builder->build_object(
|
||||
|
|
@ -104,11 +106,13 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# One more cashup created, both should be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers/$register_id/cashups")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers/$register_id/cashups")
|
||||
->status_is(200)
|
||||
->json_is( [ $another_cashup->to_api, $cashup->to_api, ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers/$register_id/cashups?cashup_blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/cash_registers/$register_id/cashups?cashup_blah=blah")
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
[
|
||||
{
|
||||
|
|
@ -159,7 +163,8 @@ subtest 'get() tests' => sub {
|
|||
my $non_existent_id = $cashup_to_delete->id;
|
||||
$cashup_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/cashups/$non_existent_id")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/cashups/$non_existent_id")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Cashup not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@ subtest 'list_rules() tests' => sub {
|
|||
);
|
||||
|
||||
note("One default rule defined");
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules")
|
||||
->status_is(200)
|
||||
->json_is( '/0/fine' => 2, "Default fine rule is returned as expected" )
|
||||
->json_is( '/0/finedays' => undef, "Rule finedays is undefined as expected" );
|
||||
|
||||
|
|
@ -113,7 +114,8 @@ subtest 'list_rules() tests' => sub {
|
|||
);
|
||||
|
||||
note("Two default rules defined");
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules")
|
||||
->status_is(200)
|
||||
->json_is( '/0/fine' => 2, "Default fine rule is returned as expected" )
|
||||
->json_is( '/0/finedays' => 5, "Default finedays rule is returned as expected" );
|
||||
|
||||
|
|
@ -132,14 +134,16 @@ subtest 'list_rules() tests' => sub {
|
|||
);
|
||||
|
||||
note("Two default rules and one branch rule defined");
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?library_id=$branchcode")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?library_id=$branchcode")
|
||||
->status_is(200)
|
||||
->json_is( '/0/fine' => 4, "Branch specific fine rule is returned when library is added to request query" )
|
||||
->json_is(
|
||||
'/0/finedays' => 5,
|
||||
"Default finedays rule is returned when library is added to request query but no branch specific rule is defined"
|
||||
);
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules")
|
||||
->status_is(200)
|
||||
->json_is( '/0/fine' => 2, "Default fine rule returned when no library is added to request query" )
|
||||
->json_is( '/0/finedays' => 5, "Default finedays rule returned when no library is added to request query" );
|
||||
|
||||
|
|
@ -152,7 +156,8 @@ subtest 'list_rules() tests' => sub {
|
|||
);
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules_blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?rules_blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/rules_blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Make sure we have a non-existent library
|
||||
|
|
@ -161,7 +166,8 @@ subtest 'list_rules() tests' => sub {
|
|||
$library_to_delete->delete;
|
||||
|
||||
# Warn on incorrect query parameter value
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?library_id=$non_existent_library")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?library_id=$non_existent_library")
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
'' => {
|
||||
error => 'Invalid parameter value',
|
||||
|
|
@ -182,7 +188,8 @@ subtest 'list_rules() tests' => sub {
|
|||
|
||||
# Warn on incorrect query parameter value
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?patron_category_id=$non_existent_category")
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
'' => {
|
||||
error => 'Invalid parameter value',
|
||||
error_code => 'invalid_parameter_value',
|
||||
|
|
@ -201,7 +208,8 @@ subtest 'list_rules() tests' => sub {
|
|||
$itemtype_to_delete->delete;
|
||||
|
||||
# Warn on incorrect query parameter value
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?item_type_id=$non_existent_itemtype")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/circulation_rules?item_type_id=$non_existent_itemtype")
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
'' => {
|
||||
error => 'Invalid parameter value',
|
||||
|
|
@ -343,21 +351,24 @@ subtest 'set_rules() tests' => sub {
|
|||
# Invalid item_type_id
|
||||
note("Invalid item_type_id");
|
||||
$rules_to_set->{context}->{item_type_id} = 'invalid_itemtype';
|
||||
$t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )->status_is(400)
|
||||
$t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )
|
||||
->status_is(400)
|
||||
->json_is( '/error_code' => 'invalid_parameter_value', "Handled invalid item_type_id" );
|
||||
|
||||
# Invalid library_id
|
||||
note("Invalid library_id");
|
||||
$rules_to_set->{context}->{item_type_id} = $itemtype;
|
||||
$rules_to_set->{context}->{library_id} = 'invalid_library';
|
||||
$t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )->status_is(400)
|
||||
$t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )
|
||||
->status_is(400)
|
||||
->json_is( '/error_code' => 'invalid_parameter_value', "Handled invalid library_id" );
|
||||
|
||||
# Invalid patron_category_id
|
||||
note("Invalid patron_category_id");
|
||||
$rules_to_set->{context}->{library_id} = $branchcode;
|
||||
$rules_to_set->{context}->{patron_category_id} = 'invalid_category';
|
||||
$t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )->status_is(400)
|
||||
$t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )
|
||||
->status_is(400)
|
||||
->json_is( '/error_code' => 'invalid_parameter_value', "Handled invalid patron_category_id" );
|
||||
|
||||
# Unauthorized user tests
|
||||
|
|
|
|||
|
|
@ -91,11 +91,13 @@ subtest 'list() tests' => sub {
|
|||
]
|
||||
);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/cities?name=" . $city->city_name )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/cities?name=" . $city->city_name )
|
||||
->status_is(200)
|
||||
->json_is( [ $city->to_api ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/cities?city_blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/cities?city_blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/city_blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
@ -139,7 +141,8 @@ subtest 'get() tests' => sub {
|
|||
my $non_existent_id = $city_to_delete->id;
|
||||
$city_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/cities/$non_existent_id")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/cities/$non_existent_id")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'City not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -200,12 +203,16 @@ subtest 'add() tests' => sub {
|
|||
|
||||
# Authorized attempt to write
|
||||
my $city_id =
|
||||
$t->post_ok( "//$userid:$password@/api/v1/cities" => json => $city )->status_is( 201, 'REST3.2.1' )
|
||||
$t->post_ok( "//$userid:$password@/api/v1/cities" => json => $city )
|
||||
->status_is( 201, 'REST3.2.1' )
|
||||
->header_like(
|
||||
Location => qr|^\/api\/v1\/cities/\d*|,
|
||||
'REST3.4.1'
|
||||
)->json_is( '/name' => $city->{name} )->json_is( '/state' => $city->{state} )
|
||||
->json_is( '/postal_code' => $city->{postal_code} )->json_is( '/country' => $city->{country} )
|
||||
)
|
||||
->json_is( '/name' => $city->{name} )
|
||||
->json_is( '/state' => $city->{state} )
|
||||
->json_is( '/postal_code' => $city->{postal_code} )
|
||||
->json_is( '/country' => $city->{country} )
|
||||
->tx->res->json->{city_id};
|
||||
|
||||
# Authorized attempt to create with null id
|
||||
|
|
@ -266,7 +273,8 @@ subtest 'update() tests' => sub {
|
|||
country => 'New country'
|
||||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/cities/$city_id" => json => $city_with_missing_field )->status_is(400)
|
||||
$t->put_ok( "//$userid:$password@/api/v1/cities/$city_id" => json => $city_with_missing_field )
|
||||
->status_is(400)
|
||||
->json_is( "/errors" => [ { message => "Missing property.", path => "/body/postal_code" } ] );
|
||||
|
||||
# Full object update on PUT
|
||||
|
|
@ -277,7 +285,8 @@ subtest 'update() tests' => sub {
|
|||
country => "City Country"
|
||||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/cities/$city_id" => json => $city_with_updated_field )->status_is(200)
|
||||
$t->put_ok( "//$userid:$password@/api/v1/cities/$city_id" => json => $city_with_updated_field )
|
||||
->status_is(200)
|
||||
->json_is( '/name' => 'London' );
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
|
|
@ -288,7 +297,8 @@ subtest 'update() tests' => sub {
|
|||
country => "City Country"
|
||||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/cities/$city_id" => json => $city_with_invalid_field )->status_is(400)
|
||||
$t->put_ok( "//$userid:$password@/api/v1/cities/$city_id" => json => $city_with_invalid_field )
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
|
|
@ -344,7 +354,8 @@ subtest 'delete() tests' => sub {
|
|||
# Unauthorized attempt to delete
|
||||
$t->delete_ok("//$unauth_userid:$password@/api/v1/cities/$city_id")->status_is(403);
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/cities/$city_id")->status_is( 204, 'REST3.2.4' )
|
||||
$t->delete_ok("//$userid:$password@/api/v1/cities/$city_id")
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
$t->delete_ok("//$userid:$password@/api/v1/cities/$city_id")->status_is(404);
|
||||
|
|
|
|||
|
|
@ -134,7 +134,8 @@ subtest 'add() tests' => sub {
|
|||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/clubs/"
|
||||
. $club_with_enrollments->id
|
||||
. "/holds" => json => { pickup_library_id => $non_existent_item_homebranch } )->status_is(400)
|
||||
. "/holds" => json => { pickup_library_id => $non_existent_item_homebranch } )
|
||||
->status_is(400)
|
||||
->json_is( '/error' => 'At least one of biblio_id, item_id should be given' );
|
||||
|
||||
$t->post_ok(
|
||||
|
|
@ -170,12 +171,15 @@ subtest 'add() tests' => sub {
|
|||
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/clubs/" . $club_without_enrollments->id . "/holds" => json => $data )
|
||||
->status_is(409)->json_is( '/error' => "Cannot place a hold on a club without patrons." );
|
||||
->status_is(409)
|
||||
->json_is( '/error' => "Cannot place a hold on a club without patrons." );
|
||||
|
||||
# place a club hold with top level reserveforothers permission - should succeed
|
||||
$t->post_ok( "//$userid:$password@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data )
|
||||
->status_is( 201, 'Created Hold' )->json_has( '/club_hold_id', 'got a club hold id' )
|
||||
->json_is( '/club_id' => $club_with_enrollments->id )->json_is( '/biblio_id' => $item->biblionumber )
|
||||
->status_is( 201, 'Created Hold' )
|
||||
->json_has( '/club_hold_id', 'got a club hold id' )
|
||||
->json_is( '/club_id' => $club_with_enrollments->id )
|
||||
->json_is( '/biblio_id' => $item->biblionumber )
|
||||
->header_is(
|
||||
'Location' => '/api/v1/clubs/'
|
||||
. $club_with_enrollments->id
|
||||
|
|
@ -189,7 +193,8 @@ subtest 'add() tests' => sub {
|
|||
"//$userid_2:$password_2@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data )
|
||||
->status_is( 201, 'Created Hold with specific place_holds permission' )
|
||||
->json_has( '/club_hold_id', 'got a club hold id' )
|
||||
->json_is( '/club_id' => $club_with_enrollments->id )->json_is( '/biblio_id' => $item->biblionumber );
|
||||
->json_is( '/club_id' => $club_with_enrollments->id )
|
||||
->json_is( '/biblio_id' => $item->biblionumber );
|
||||
|
||||
# place a club hold with no reserveforothers or specific permsision - should fail
|
||||
$t->post_ok(
|
||||
|
|
@ -233,12 +238,15 @@ subtest 'add() tests' => sub {
|
|||
|
||||
$t->post_ok(
|
||||
"//$userid:$password@/api/v1/clubs/" . $club_without_enrollments->id . "/holds" => json => $data )
|
||||
->status_is(409)->json_is( '/error' => "Cannot place a hold on a club without patrons." );
|
||||
->status_is(409)
|
||||
->json_is( '/error' => "Cannot place a hold on a club without patrons." );
|
||||
|
||||
# place a club hold with top level reserveforothers permission - should succeed
|
||||
$t->post_ok( "//$userid:$password@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data )
|
||||
->status_is( 201, 'Created Hold' )->json_has( '/club_hold_id', 'got a club hold id' )
|
||||
->json_is( '/club_id' => $club_with_enrollments->id )->json_is( '/biblio_id' => $item->biblionumber )
|
||||
->status_is( 201, 'Created Hold' )
|
||||
->json_has( '/club_hold_id', 'got a club hold id' )
|
||||
->json_is( '/club_id' => $club_with_enrollments->id )
|
||||
->json_is( '/biblio_id' => $item->biblionumber )
|
||||
->header_is(
|
||||
'Location' => '/api/v1/clubs/'
|
||||
. $club_with_enrollments->id
|
||||
|
|
@ -252,7 +260,8 @@ subtest 'add() tests' => sub {
|
|||
"//$userid_2:$password_2@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data )
|
||||
->status_is( 201, 'Created Hold with specific place_holds permission' )
|
||||
->json_has( '/club_hold_id', 'got a club hold id' )
|
||||
->json_is( '/club_id' => $club_with_enrollments->id )->json_is( '/biblio_id' => $item->biblionumber );
|
||||
->json_is( '/club_id' => $club_with_enrollments->id )
|
||||
->json_is( '/biblio_id' => $item->biblionumber );
|
||||
|
||||
# place a club hold with no reserveforothers or specific permsision - should fail
|
||||
$t->post_ok(
|
||||
|
|
@ -348,7 +357,8 @@ sub unauthorized_access_tests {
|
|||
$unauthorized_patron->set_password( { password => $password, skip_validation => 1 } );
|
||||
my $unauth_userid = $unauthorized_patron->userid;
|
||||
|
||||
$t->$verb_ok( "//$unauth_userid:$password\@$endpoint" => json => $json )->status_is(403)
|
||||
$t->$verb_ok( "//$unauth_userid:$password\@$endpoint" => json => $json )
|
||||
->status_is(403)
|
||||
->json_has('/required_permissions');
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,8 @@ subtest 'get() tests' => sub {
|
|||
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } )
|
||||
->status_is(200)->json_is( '/title', 'The unbearable lightness of being' )
|
||||
->status_is(200)
|
||||
->json_is( '/title', 'The unbearable lightness of being' )
|
||||
->json_is( '/author', 'Milan Kundera' );
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/"
|
||||
|
|
@ -100,11 +101,13 @@ subtest 'get() tests' => sub {
|
|||
->status_is(200);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } )
|
||||
->status_is(200)->content_is($formatted);
|
||||
->status_is(200)
|
||||
->content_is($formatted);
|
||||
|
||||
my $biblio_exist = $builder->build_sample_biblio();
|
||||
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/"
|
||||
. $biblio_exist->biblionumber => { Accept => 'application/marc' } )->status_is(404)
|
||||
. $biblio_exist->biblionumber => { Accept => 'application/marc' } )
|
||||
->status_is(404)
|
||||
->json_is( '/error', 'Bibliographic record not found' );
|
||||
|
||||
subtest 'marc-in-json encoding tests' => sub {
|
||||
|
|
@ -217,7 +220,8 @@ subtest 'list() tests' => sub {
|
|||
|
||||
my $result =
|
||||
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marcxml+xml' } )
|
||||
->status_is(200)->tx->res->body;
|
||||
->status_is(200)
|
||||
->tx->res->body;
|
||||
|
||||
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics );
|
||||
like( $result, qr/\Q$encoded_title/, "The title is not double encoded" );
|
||||
|
|
@ -249,7 +253,9 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/json' } )
|
||||
->status_is(200)->json_is( '/0/biblio_id' => $old_biblio_1->id )->json_is( '/1/biblio_id' => undef );
|
||||
->status_is(200)
|
||||
->json_is( '/0/biblio_id' => $old_biblio_1->id )
|
||||
->json_is( '/1/biblio_id' => undef );
|
||||
|
||||
# DELETE any biblio with ISBN = TOMAS
|
||||
Koha::Biblios->search( { 'biblioitem.isbn' => 'TOMAS' }, { join => ['biblioitem'] } )->delete;
|
||||
|
|
|
|||
|
|
@ -102,12 +102,14 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
$api_filter = encode_json( { 'me.filename' => $file->filename } );
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?q=$api_filter")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?q=$api_filter")
|
||||
->status_is(200)
|
||||
->json_is( [ $file->to_api ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$api_filter = encode_json( { 'me.file_blah' => 'blah' } );
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?file_blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/acquisitions/edifiles?file_blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/file_blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
|
|||
|
|
@ -101,14 +101,16 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# Filtering works, two agreements sharing vendor_id
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/agreements?vendor_id=" . $vendor_1->id )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/agreements?vendor_id=" . $vendor_1->id )
|
||||
->status_is(200)
|
||||
->json_is( [ $agreement->to_api, $another_agreement->to_api ] );
|
||||
|
||||
# Attempt to search by name like 'ko'
|
||||
$agreement->delete;
|
||||
$another_agreement->delete;
|
||||
$agreement_with_another_vendor_id->delete;
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/agreements?q=[{"me.name":{"like":"%ko%"}}]~)->status_is(200)
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/agreements?q=[{"me.name":{"like":"%ko%"}}]~)
|
||||
->status_is(200)
|
||||
->json_is( [] );
|
||||
|
||||
my $agreement_to_search = $builder->build_object(
|
||||
|
|
@ -121,7 +123,8 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# Search works, searching for name like 'ko'
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/agreements?q=[{"me.name":{"like":"%ko%"}}]~)->status_is(200)
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/agreements?q=[{"me.name":{"like":"%ko%"}}]~)
|
||||
->status_is(200)
|
||||
->json_is( [ $agreement_to_search->to_api ] );
|
||||
|
||||
# Warn on incorrect filter date format
|
||||
|
|
@ -135,7 +138,8 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# Attempt to filter by expired on 2021-03-19
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/agreements?max_expiration_date=2021-03-19")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/agreements?max_expiration_date=2021-03-19")
|
||||
->status_is(200)
|
||||
->json_is( [] );
|
||||
|
||||
my $agreement_to_filter = $builder->build_object( { class => 'Koha::ERM::Agreements' } );
|
||||
|
|
@ -149,11 +153,13 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# Filter by expired on 2021-03-19
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/agreements?max_expiration_date=2021-03-19")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/agreements?max_expiration_date=2021-03-19")
|
||||
->status_is(200)
|
||||
->json_is( [ $agreement_to_filter->to_api ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/agreements?blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/agreements?blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
@ -190,7 +196,8 @@ subtest 'get() tests' => sub {
|
|||
my $unauth_userid = $patron->userid;
|
||||
|
||||
# This agreement exists, should get returned
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/agreements/" . $agreement->agreement_id )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/agreements/" . $agreement->agreement_id )
|
||||
->status_is(200)
|
||||
->json_is( $agreement->to_api );
|
||||
|
||||
# Return one agreement with some embeds
|
||||
|
|
@ -214,7 +221,8 @@ subtest 'get() tests' => sub {
|
|||
my $non_existent_id = $agreement_to_delete->agreement_id;
|
||||
$agreement_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/agreements/$non_existent_id")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/agreements/$non_existent_id")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Agreement not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -273,7 +281,8 @@ subtest 'add() tests' => sub {
|
|||
};
|
||||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/agreements" => json => $agreement_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
|
@ -285,19 +294,25 @@ subtest 'add() tests' => sub {
|
|||
# Authorized attempt to write
|
||||
my $agreement_id =
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/agreements" => json => $agreement )
|
||||
->status_is( 201, 'REST3.2.1' )->header_like(
|
||||
->status_is( 201, 'REST3.2.1' )
|
||||
->header_like(
|
||||
Location => qr|^/api/v1/erm/agreements/\d*|,
|
||||
'REST3.4.1'
|
||||
)->json_is( '/vendor_id' => $agreement->{vendor_id} )->json_is( '/name' => $agreement->{name} )
|
||||
->json_is( '/description' => $agreement->{description} )->json_is( '/status' => $agreement->{status} )
|
||||
)
|
||||
->json_is( '/vendor_id' => $agreement->{vendor_id} )
|
||||
->json_is( '/name' => $agreement->{name} )
|
||||
->json_is( '/description' => $agreement->{description} )
|
||||
->json_is( '/status' => $agreement->{status} )
|
||||
->json_is( '/closure_reason' => $agreement->{closure_reason} )
|
||||
->json_is( '/is_perpetual' => $agreement->{is_perpetual} )
|
||||
->json_is( '/renewal_priority' => $agreement->{renewal_priority} )
|
||||
->json_is( '/license_info' => $agreement->{license_info} )->tx->res->json->{agreement_id};
|
||||
->json_is( '/license_info' => $agreement->{license_info} )
|
||||
->tx->res->json->{agreement_id};
|
||||
|
||||
# Authorized attempt to create with null id
|
||||
$agreement->{agreement_id} = undef;
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/agreements" => json => $agreement )->status_is(400)
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/agreements" => json => $agreement )
|
||||
->status_is(400)
|
||||
->json_has('/errors');
|
||||
|
||||
# Authorized attempt to create with existing id
|
||||
|
|
@ -357,7 +372,8 @@ subtest 'update() tests' => sub {
|
|||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/erm/agreements/$agreement_id" => json => $agreement_with_missing_field )
|
||||
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
|
||||
->status_is(400)
|
||||
->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
|
||||
|
||||
# Full object update on PUT
|
||||
my $agreement_with_updated_field = {
|
||||
|
|
@ -372,7 +388,8 @@ subtest 'update() tests' => sub {
|
|||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/erm/agreements/$agreement_id" => json => $agreement_with_updated_field )
|
||||
->status_is(200)->json_is( '/name' => 'New name' );
|
||||
->status_is(200)
|
||||
->json_is( '/name' => 'New name' );
|
||||
|
||||
# Authorized attempt to write invalid data
|
||||
my $agreement_with_invalid_field = {
|
||||
|
|
@ -387,7 +404,8 @@ subtest 'update() tests' => sub {
|
|||
};
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/erm/agreements/$agreement_id" => json => $agreement_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
|
@ -445,7 +463,8 @@ subtest 'delete() tests' => sub {
|
|||
$t->delete_ok("//$unauth_userid:$password@/api/v1/erm/agreements/$agreement_id")->status_is(403);
|
||||
|
||||
# Delete existing agreement
|
||||
$t->delete_ok("//$userid:$password@/api/v1/erm/agreements/$agreement_id")->status_is( 204, 'REST3.2.4' )
|
||||
$t->delete_ok("//$userid:$password@/api/v1/erm/agreements/$agreement_id")
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
# Attempt to delete non-existent agreement
|
||||
|
|
@ -510,7 +529,8 @@ subtest 'extended_attributes() tests' => sub {
|
|||
# Test with list endpoint
|
||||
$response =
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/agreements" => { 'x-koha-embed' => 'extended_attributes' } )
|
||||
->status_is(200)->tx->res->json;
|
||||
->status_is(200)
|
||||
->tx->res->json;
|
||||
|
||||
# Verify record_table is still not present in list endpoint
|
||||
my $found = 0;
|
||||
|
|
|
|||
|
|
@ -79,13 +79,15 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# Two counter_files created, they should both be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files")
|
||||
->status_is(200)
|
||||
->json_is( [ $counter_file->to_api, $another_counter_file->to_api, ] );
|
||||
|
||||
# Attempt to search by type like 'ko'
|
||||
$counter_file->delete;
|
||||
$another_counter_file->delete;
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]~)->status_is(200)
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]~)
|
||||
->status_is(200)
|
||||
->json_is( [] );
|
||||
|
||||
my $counter_file_to_search = $builder->build_object(
|
||||
|
|
@ -98,11 +100,13 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# Search works, searching for type like 'ko'
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]~)->status_is(200)
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]~)
|
||||
->status_is(200)
|
||||
->json_is( [ $counter_file_to_search->to_api ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files?blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files?blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
@ -153,7 +157,8 @@ subtest 'get() tests' => sub {
|
|||
my $non_existent_id = $counter_file_to_delete->erm_counter_files_id;
|
||||
$counter_file_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files/$non_existent_id/file/content")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files/$non_existent_id/file/content")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'COUNTER file not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -192,7 +197,8 @@ subtest 'delete() tests' => sub {
|
|||
$t->delete_ok("//$unauth_userid:$password@/api/v1/erm/counter_files/$counter_file_id")->status_is(403);
|
||||
|
||||
# Delete existing counter_file
|
||||
$t->delete_ok("//$userid:$password@/api/v1/erm/counter_files/$counter_file_id")->status_is( 204, 'REST3.2.4' )
|
||||
$t->delete_ok("//$userid:$password@/api/v1/erm/counter_files/$counter_file_id")
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
# Attempt to delete non-existent counter_file
|
||||
|
|
|
|||
|
|
@ -79,11 +79,13 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# Two counter_logs created, they should both be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_logs")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_logs")
|
||||
->status_is(200)
|
||||
->json_is( [ $counter_log->to_api, $another_counter_log->to_api, ] );
|
||||
|
||||
# Return 2 counter logs with patron embedded
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/counter_logs/" => { 'x-koha-embed' => 'patron' } )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/counter_logs/" => { 'x-koha-embed' => 'patron' } )
|
||||
->status_is(200)
|
||||
->json_is(
|
||||
[
|
||||
{ %{ $counter_log->to_api }, patron => $counter_log->patron->to_api( { user => $librarian } ) },
|
||||
|
|
@ -95,7 +97,8 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_logs?blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_logs?blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
|
|||
|
|
@ -113,7 +113,8 @@ subtest "monthly_report" => sub {
|
|||
my $expected_results1 = 2; # One title, with one row for each metric type
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/monthly_report/title?$query_string" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results1 - 2 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results1 - 1 ) . '/title_id' )
|
||||
->json_hasnt( '/' . ($expected_results1) . '/title_id' );
|
||||
|
|
@ -135,7 +136,8 @@ subtest "monthly_report" => sub {
|
|||
my $expected_results2 = 4; # Two titles this time
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/monthly_report/title?$query_string_with_multiple_years" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results2 - 4 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 3 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 2 ) . '/title_id' )
|
||||
|
|
@ -210,7 +212,8 @@ subtest "yearly_report" => sub {
|
|||
my $expected_results1 = 2; # One title, with one row for each metric type
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/yearly_report/title?$query_string" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_yuses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_yuses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results1 - 2 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results1 - 1 ) . '/title_id' )
|
||||
->json_hasnt( '/' . ($expected_results1) . '/title_id' );
|
||||
|
|
@ -225,7 +228,8 @@ subtest "yearly_report" => sub {
|
|||
my $expected_results2 = 4; # Two titles this time
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/yearly_report/title?$query_string_with_multiple_years" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_yuses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_yuses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results2 - 4 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 3 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 2 ) . '/title_id' )
|
||||
|
|
@ -302,7 +306,8 @@ subtest "metric_types_report" => sub {
|
|||
my $expected_results1 = 1; # One title
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/metric_types_report/title?$query_string" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results1 - 1 ) . '/title_id' )
|
||||
->json_hasnt( '/' . ($expected_results1) . '/title_id' );
|
||||
|
||||
|
|
@ -323,7 +328,8 @@ subtest "metric_types_report" => sub {
|
|||
my $expected_results2 = 2; # Two titles this time
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/metric_types_report/title?$query_string_with_multiple_years" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results2 - 2 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 1 ) . '/title_id' )
|
||||
->json_hasnt( '/' . ($expected_results2) . '/title_id' );
|
||||
|
|
@ -398,7 +404,8 @@ subtest "provider_rollup_report" => sub {
|
|||
my $expected_results1 = 2; # One provider repeated once for each metric type
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/provider_rollup_report/title?$query_string" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_titles.erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_titles.erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_is( '/' . ( $expected_results1 - 2 ) . '/provider_rollup_total' => 2, 'Total is correct' )
|
||||
->json_is( '/' . ( $expected_results1 - 1 ) . '/provider_rollup_total' => 1, 'Total is correct' );
|
||||
|
||||
|
|
@ -476,7 +483,8 @@ subtest "5.1 monthly_report" => sub {
|
|||
my $expected_results1 = 2; # One title, with one row for each metric type
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/monthly_report/title?$query_string" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results1 - 2 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results1 - 1 ) . '/title_id' )
|
||||
->json_hasnt( '/' . ($expected_results1) . '/title_id' );
|
||||
|
|
@ -498,7 +506,8 @@ subtest "5.1 monthly_report" => sub {
|
|||
my $expected_results2 = 4; # Two titles this time
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/monthly_report/title?$query_string_with_multiple_years" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results2 - 4 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 3 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 2 ) . '/title_id' )
|
||||
|
|
@ -573,7 +582,8 @@ subtest "5.1 yearly_report" => sub {
|
|||
my $expected_results1 = 4; # Two titles, with one row for each metric type
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/yearly_report/title?$query_string" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_yuses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_yuses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results1 - 2 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results1 - 1 ) . '/title_id' )
|
||||
->json_hasnt( '/' . ($expected_results1) . '/title_id' );
|
||||
|
|
@ -588,7 +598,8 @@ subtest "5.1 yearly_report" => sub {
|
|||
my $expected_results2 = 4; # Two titles this time
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/yearly_report/title?$query_string_with_multiple_years" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_yuses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_yuses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results2 - 4 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 3 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 2 ) . '/title_id' )
|
||||
|
|
@ -665,7 +676,8 @@ subtest "5.1 metric_types_report" => sub {
|
|||
my $expected_results1 = 1; # One title
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/metric_types_report/title?$query_string" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results1 - 1 ) . '/title_id' )
|
||||
->json_hasnt( '/' . ($expected_results1) . '/title_id' );
|
||||
|
||||
|
|
@ -686,7 +698,8 @@ subtest "5.1 metric_types_report" => sub {
|
|||
my $expected_results2 = 2; # Two titles this time
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/metric_types_report/title?$query_string_with_multiple_years" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_has( '/' . ( $expected_results2 - 2 ) . '/title_id' )
|
||||
->json_has( '/' . ( $expected_results2 - 1 ) . '/title_id' )
|
||||
->json_hasnt( '/' . ($expected_results2) . '/title_id' );
|
||||
|
|
@ -761,7 +774,8 @@ subtest "5.1 provider_rollup_report" => sub {
|
|||
my $expected_results1 = 2; # One provider repeated once for each metric type
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eUsage/provider_rollup_report/title?$query_string" =>
|
||||
{ 'x-koha-embed' => 'erm_usage_titles.erm_usage_muses' } )->status_is(200)
|
||||
{ 'x-koha-embed' => 'erm_usage_titles.erm_usage_muses' } )
|
||||
->status_is(200)
|
||||
->json_is( '/' . ( $expected_results1 - 2 ) . '/provider_rollup_total' => 528, 'Total is correct' )
|
||||
->json_is( '/' . ( $expected_results1 - 1 ) . '/provider_rollup_total' => 228, 'Total is correct' );
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@ subtest 'get() tests' => sub {
|
|||
|
||||
# This document exists, should get returned
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/documents/" . $document->document_id . "/file/content" )
|
||||
->status_is(200)->json_is('123');
|
||||
->status_is(200)
|
||||
->json_is('123');
|
||||
|
||||
# Create a document through a license, gets returned
|
||||
my $license = $builder->build_object( { class => 'Koha::ERM::Licenses' } );
|
||||
|
|
@ -94,7 +95,8 @@ subtest 'get() tests' => sub {
|
|||
my @documents = $license->documents->as_list;
|
||||
my $license_document_id = $documents[0]->document_id;
|
||||
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/documents/" . $license_document_id . "/file/content" )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/documents/" . $license_document_id . "/file/content" )
|
||||
->status_is(200)
|
||||
->content_is( decode_base64('321') );
|
||||
|
||||
# Delete a document through a license, no longer exists
|
||||
|
|
@ -122,7 +124,8 @@ subtest 'get() tests' => sub {
|
|||
my $non_existent_id = $document_to_delete->id;
|
||||
$document_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/documents/$non_existent_id/file/content")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/documents/$non_existent_id/file/content")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Document not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
# One EHoldings package created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/packages")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/packages")
|
||||
->status_is(200)
|
||||
->json_is( [ $ehpackage->to_api ] );
|
||||
|
||||
my $another_ehpackage = $builder->build_object(
|
||||
|
|
@ -103,14 +104,16 @@ subtest 'list() tests' => sub {
|
|||
|
||||
# Filtering works, two EHoldings packages sharing package_type
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages?package_type=" . $ehpackage->package_type )
|
||||
->status_is(200)->json_is( [ $ehpackage->to_api, $another_ehpackage->to_api ] );
|
||||
->status_is(200)
|
||||
->json_is( [ $ehpackage->to_api, $another_ehpackage->to_api ] );
|
||||
|
||||
# Attempt to search by name like 'ko'
|
||||
$ehpackage->delete;
|
||||
$another_ehpackage->delete;
|
||||
$ehpackage_with_another_package_type->delete;
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/eholdings/local/packages?q=[{"me.name":{"like":"%ko%"}}]~)
|
||||
->status_is(200)->json_is( [] );
|
||||
->status_is(200)
|
||||
->json_is( [] );
|
||||
|
||||
my $ehpackage_to_search = $builder->build_object(
|
||||
{
|
||||
|
|
@ -124,10 +127,12 @@ subtest 'list() tests' => sub {
|
|||
|
||||
# Search works, searching for name like 'ko'
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/eholdings/local/packages?q=[{"me.name":{"like":"%ko%"}}]~)
|
||||
->status_is(200)->json_is( [ $ehpackage_to_search->to_api ] );
|
||||
->status_is(200)
|
||||
->json_is( [ $ehpackage_to_search->to_api ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/packages?blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/packages?blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
@ -164,12 +169,14 @@ subtest 'get() tests' => sub {
|
|||
my $unauth_userid = $patron->userid;
|
||||
|
||||
# This EHoldings package exists, should get returned
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages/" . $ehpackage->package_id )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages/" . $ehpackage->package_id )
|
||||
->status_is(200)
|
||||
->json_is( $ehpackage->to_api );
|
||||
|
||||
# Return one EHoldings package with embed
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages/"
|
||||
. $ehpackage->package_id => { 'x-koha-embed' => 'resources+count' } )->status_is(200)
|
||||
. $ehpackage->package_id => { 'x-koha-embed' => 'resources+count' } )
|
||||
->status_is(200)
|
||||
->json_is( { %{ $ehpackage->to_api }, resources_count => 0 } );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
@ -181,7 +188,8 @@ subtest 'get() tests' => sub {
|
|||
my $non_existent_id = $ehpackage_to_delete->package_id;
|
||||
$ehpackage_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/packages/$non_existent_id")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/packages/$non_existent_id")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'Package not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
@ -231,7 +239,8 @@ subtest 'add() tests' => sub {
|
|||
};
|
||||
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages" => json => $ehpackage_with_invalid_field )
|
||||
->status_is(400)->json_is(
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
message => "Properties not allowed: blah.",
|
||||
|
|
@ -243,21 +252,27 @@ subtest 'add() tests' => sub {
|
|||
# Authorized attempt to write
|
||||
my $ehpackage_id =
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages" => json => $ehpackage )
|
||||
->status_is( 201, 'REST3.2.1' )->header_like(
|
||||
->status_is( 201, 'REST3.2.1' )
|
||||
->header_like(
|
||||
Location => qr|^/api/v1/erm/eholdings/local/packages/\d*|,
|
||||
'REST3.4.1'
|
||||
)->json_is( '/name' => $ehpackage->{name} )->json_is( '/print_identifier' => $ehpackage->{print_identifier} )
|
||||
->json_is( '/notes' => $ehpackage->{notes} )->json_is( '/publisher_name' => $ehpackage->{publisher_name} )
|
||||
)
|
||||
->json_is( '/name' => $ehpackage->{name} )
|
||||
->json_is( '/print_identifier' => $ehpackage->{print_identifier} )
|
||||
->json_is( '/notes' => $ehpackage->{notes} )
|
||||
->json_is( '/publisher_name' => $ehpackage->{publisher_name} )
|
||||
->tx->res->json->{package_id};
|
||||
|
||||
# Authorized attempt to create with null id
|
||||
$ehpackage->{package_id} = undef;
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages" => json => $ehpackage )->status_is(400)
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages" => json => $ehpackage )
|
||||
->status_is(400)
|
||||
->json_has('/errors');
|
||||
|
||||
# Authorized attempt to create with existing id
|
||||
$ehpackage->{package_id} = $ehpackage_id;
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages" => json => $ehpackage )->status_is(400)
|
||||
$t->post_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages" => json => $ehpackage )
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
"/errors" => [
|
||||
{
|
||||
|
|
@ -306,7 +321,8 @@ subtest 'update() tests' => sub {
|
|||
my $ehpackage_with_missing_field = { package_type => "Package type", };
|
||||
|
||||
$t->put_ok( "//$userid:$password@/api/v1/erm/eholdings/local/packages/$ehpackage_id" => json =>
|
||||
$ehpackage_with_missing_field )->status_is(400)
|
||||
$ehpackage_with_missing_field )
|
||||
->status_is(400)
|
||||
->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
|
||||
|
||||
# Full object update on PUT
|
||||
|
|
@ -386,7 +402,8 @@ subtest 'delete() tests' => sub {
|
|||
|
||||
# Delete existing EHolding package
|
||||
$t->delete_ok("//$userid:$password@/api/v1/erm/eholdings/local/packages/$ehpackage_id")
|
||||
->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' );
|
||||
->status_is( 204, 'REST3.2.4' )
|
||||
->content_is( '', 'REST3.3.4' );
|
||||
|
||||
# Attempt to delete non-existent EHolding package
|
||||
$t->delete_ok("//$userid:$password@/api/v1/erm/eholdings/local/packages/$ehpackage_id")->status_is(404);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ subtest 'list() tests' => sub {
|
|||
my $resource = $builder->build_object( { class => 'Koha::ERM::EHoldings::Resources' } );
|
||||
|
||||
# One resource created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/resources")->status_is(200)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/resources")
|
||||
->status_is(200)
|
||||
->json_is( [ $resource->to_api ] );
|
||||
|
||||
my $another_resource = $builder->build_object(
|
||||
|
|
@ -90,10 +91,12 @@ subtest 'list() tests' => sub {
|
|||
|
||||
# Filtering works, two resources sharing vendor_id
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eholdings/local/resources?vendor_id=" . $resource->vendor_id )
|
||||
->status_is(200)->json_is( [ $resource->to_api, $another_resource->to_api ] );
|
||||
->status_is(200)
|
||||
->json_is( [ $resource->to_api, $another_resource->to_api ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/resources?blah=blah")->status_is(400)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/resources?blah=blah")
|
||||
->status_is(400)
|
||||
->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
@ -130,7 +133,8 @@ subtest 'get() tests' => sub {
|
|||
my $unauth_userid = $patron->userid;
|
||||
|
||||
# This resource exists, should get returned
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eholdings/local/resources/" . $resource->resource_id )->status_is(200)
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/eholdings/local/resources/" . $resource->resource_id )
|
||||
->status_is(200)
|
||||
->json_is( $resource->to_api );
|
||||
|
||||
# Unauthorized access
|
||||
|
|
@ -142,7 +146,8 @@ subtest 'get() tests' => sub {
|
|||
my $non_existent_id = $resource_to_delete->resource_id;
|
||||
$resource_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/resources/$non_existent_id")->status_is(404)
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/eholdings/local/resources/$non_existent_id")
|
||||
->status_is(404)
|
||||
->json_is( '/error' => 'eHolding resource not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue