Bugzilla – Attachment 168927 Details for
Bug 36641
Add an endpoint to list circulation rules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36641: Add unit tests for /circulation_rules
Bug-36641-Add-unit-tests-for-circulationrules.patch (text/plain), 6.15 KB, created by
Martin Renvoize (ashimema)
on 2024-07-13 12:14:20 UTC
(
hide
)
Description:
Bug 36641: Add unit tests for /circulation_rules
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-07-13 12:14:20 UTC
Size:
6.15 KB
patch
obsolete
>From 95379de9fde200657c998a9fba4ced2e420638e1 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 24 Jun 2024 16:29:44 +0100 >Subject: [PATCH] Bug 36641: Add unit tests for /circulation_rules > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > t/db_dependent/api/v1/circulation_rules.t | 161 ++++++++++++++++++++++ > 1 file changed, 161 insertions(+) > create mode 100755 t/db_dependent/api/v1/circulation_rules.t > >diff --git a/t/db_dependent/api/v1/circulation_rules.t b/t/db_dependent/api/v1/circulation_rules.t >new file mode 100755 >index 00000000000..bf35d24ba44 >--- /dev/null >+++ b/t/db_dependent/api/v1/circulation_rules.t >@@ -0,0 +1,161 @@ >+#!/usr/bin/env perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use Koha::CirculationRules; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+my $t = Test::Mojo->new('Koha::REST::V1'); >+t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+subtest 'list_effective_rules() tests' => sub { >+ >+ plan tests => 26; >+ >+ $schema->storage->txn_begin; >+ >+ my $categorycode = $builder->build( { source => 'Category' } )->{'categorycode'}; >+ my $itemtype = $builder->build( { source => 'Itemtype' } )->{'itemtype'}; >+ my $branchcode = $builder->build( { source => 'Branch' } )->{'branchcode'}; >+ Koha::CirculationRules->delete; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2 } # circulate >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ ## Authorized user tests >+ # No circulation_rules, so empty hash should be returned >+ $t->get_ok("//$userid:$password@/api/v1/circulation_rules")->status_is(200)->json_is( {} ); >+ >+ # One rule created, should get returned >+ ok( >+ Koha::CirculationRule->new( >+ { >+ branchcode => undef, >+ categorycode => undef, >+ itemtype => undef, >+ rule_name => 'fine', >+ rule_value => 2, >+ } >+ )->store, >+ 'Given I added an issuing rule branchcode => undef,' . ' categorycode => undef, itemtype => undef,' >+ ); >+ >+ $t->get_ok("//$userid:$password@/api/v1/circulation_rules")->status_is(200) >+ ->json_is( '' => { 'fine' => 2 }, "Our single rule is returned" ); >+ >+ # Two circulation_rules created, they should both be returned >+ ok( >+ Koha::CirculationRule->new( >+ { >+ branchcode => undef, >+ categorycode => undef, >+ itemtype => undef, >+ rule_name => 'finedays', >+ rule_value => 5, >+ } >+ )->store, >+ 'Given I added another issuing rule branchcode => undef,' . ' categorycode => undef, itemtype => undef,' >+ ); >+ >+ $t->get_ok("//$userid:$password@/api/v1/circulation_rules")->status_is(200)->json_is( >+ '' => { >+ fine => 2, >+ finedays => 5, >+ }, >+ "Two default rules are returned" >+ ); >+ >+ # Specificity works, three circulation_rules stored, one branchcode specific >+ ok( >+ Koha::CirculationRule->new( >+ { >+ branchcode => $branchcode, >+ categorycode => undef, >+ itemtype => undef, >+ rule_name => 'fine', >+ rule_value => 4, >+ } >+ )->store, >+ "Given I added an issuing rule branchcode => $branchcode," . ' categorycode => undef, itemtype => undef,' >+ ); >+ >+ $t->get_ok("//$userid:$password@/api/v1/circulation_rules?library=$branchcode")->status_is(200)->json_is( >+ '' => { >+ fine => 4, >+ finedays => 5, >+ }, >+ "Branch specific rule is returned when library is added to request query" >+ ); >+ >+ $t->get_ok("//$userid:$password@/api/v1/circulation_rules")->status_is(200)->json_is( >+ '' => { >+ fine => 2, >+ finedays => 5, >+ }, >+ "Default rules are returned when no library is added to request query" >+ ); >+ >+ # Warn on unsupported query parameter >+ $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' } ] ); >+ >+ # Warn on incorrect query parameter value >+ $t->get_ok("//$userid:$password@/api/v1/circulation_rules?library=SMITH")->status_is(400)->json_is( >+ '' => { >+ error => 'Invalid parameter value', >+ error_code => 'invalid_parameter_value', >+ path => '/query/library', >+ values => { >+ uri => '/api/v1/libraries', >+ field => 'library_id' >+ } >+ }, >+ "Invalid parameter value handled correctly" >+ ); >+ >+ # Unauthorized access >+ $t->get_ok("//$unauth_userid:$password@/api/v1/circulation_rules")->status_is(403); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.45.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36641
:
165086
|
167937
|
167938
|
167946
|
167947
|
168018
|
168019
|
168020
|
168023
|
168024
|
168025
|
168365
|
168366
|
168367
|
168368
|
168369
|
168370
|
168378
|
168379
|
168395
|
168396
|
168397
|
168398
|
168399
|
168400
|
168401
|
168841
|
168874
|
168875
|
168876
|
168877
|
168878
|
168879
|
168880
|
168881
|
168882
|
168883
|
168884
|
168905
|
168906
|
168907
|
168908
|
168909
|
168910
|
168911
|
168912
|
168913
|
168914
|
168915
|
168916
|
168926
|
168927
|
168928
|
168929
|
168930
|
168931
|
168932
|
168933
|
168934
|
168935
|
168936
|
168937
|
168938
|
168940
|
169013
|
169014
|
169015
|
169016
|
169017
|
169018
|
169019
|
169020
|
169021
|
169022
|
169023
|
169024
|
169025
|
169026