Bugzilla – Attachment 170336 Details for
Bug 37256
Add an endpoint to allow setting circulation rule sets
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37256: Unit tests for set_rules
Bug-37256-Unit-tests-for-setrules.patch (text/plain), 5.80 KB, created by
Martin Renvoize (ashimema)
on 2024-08-15 07:52:04 UTC
(
hide
)
Description:
Bug 37256: Unit tests for set_rules
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-08-15 07:52:04 UTC
Size:
5.80 KB
patch
obsolete
>From 60d8326982d1a232eb7d27b1101fff2334f49d61 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 7 Aug 2024 11:18:13 +0100 >Subject: [PATCH] Bug 37256: Unit tests for set_rules > >This patch adds unit tests for the to be introduced set_rules endpoint >for setting circualtion rule sets. >--- > t/db_dependent/api/v1/circulation_rules.t | 111 +++++++++++++++++++++- > 1 file changed, 108 insertions(+), 3 deletions(-) > >diff --git a/t/db_dependent/api/v1/circulation_rules.t b/t/db_dependent/api/v1/circulation_rules.t >index f69ca251cee..d83e7af48ef 100755 >--- a/t/db_dependent/api/v1/circulation_rules.t >+++ b/t/db_dependent/api/v1/circulation_rules.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 1; >+use Test::More tests => 2; > use Test::Mojo; > > use t::lib::TestBuilder; >@@ -269,9 +269,12 @@ subtest 'list_rules() tests' => sub { > > # First (and only) rule set should match branchcode, default, default. > if ( $index == 0 ) { >- ok( $pointer->get('/context/library_id') eq $branchcode >+ ok( >+ $pointer->get('/context/library_id') eq $branchcode > && $pointer->get('/context/item_type_id') eq '*' >- && $pointer->get('/context/patron_category_id') eq '*', "Branchcode rule set returned when filtered" ); >+ && $pointer->get('/context/patron_category_id') eq '*', >+ "Branchcode rule set returned when filtered" >+ ); > } > > # Iterate over the list of expected keys for each hash >@@ -285,3 +288,105 @@ subtest 'list_rules() tests' => sub { > }; > $schema->storage->txn_rollback; > }; >+ >+subtest 'set_rules() tests' => sub { >+ plan tests => 23; >+ >+ $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 >+ note("Authorized user setting rules"); >+ >+ my $rules_to_set = { >+ context => { >+ library_id => $branchcode, >+ patron_category_id => $categorycode, >+ item_type_id => $itemtype, >+ }, >+ fine => 5, >+ finedays => 7, >+ }; >+ >+ $t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )->status_is(200); >+ >+ # Verify the rules were set >+ my $json = $t->tx->res->json; >+ is( $json->{fine}, 5, "Fine rule set correctly" ); >+ is( $json->{finedays}, 7, "Finedays rule set correctly" ); >+ >+ # 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) >+ ->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) >+ ->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) >+ ->json_is( '/error_code' => 'invalid_parameter_value', "Handled invalid patron_category_id" ); >+ >+ # Unauthorized user tests >+ note("Unauthorized user trying to set rules"); >+ $t->put_ok( "//$unauth_userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )->status_is(403); >+ >+ # Reset to valid context >+ $rules_to_set->{context}->{patron_category_id} = $categorycode; >+ >+ # Updating existing rules >+ note("Updating existing rules"); >+ $rules_to_set->{fine} = 10; >+ $t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )->status_is(200); >+ >+ # Verify the rules were updated >+ $json = $t->tx->res->json; >+ is( $json->{fine}, 10, "Fine rule updated correctly" ); >+ is( $json->{finedays}, 7, "Finedays rule remains the same" ); >+ >+ # Setting rules with '*' context >+ note("Setting rules with '*' context"); >+ $rules_to_set->{context}->{library_id} = '*'; >+ $rules_to_set->{context}->{patron_category_id} = '*'; >+ $rules_to_set->{context}->{item_type_id} = '*'; >+ $t->put_ok( "//$userid:$password@/api/v1/circulation_rules" => json => $rules_to_set )->status_is(200); >+ >+ # Verify the rules were set for wildcard context >+ $json = $t->tx->res->json; >+ is( $json->{fine}, 10, "Fine rule set correctly for wildcard context" ); >+ is( $json->{finedays}, 7, "Finedays rule set correctly for wildcard context" ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.46.0
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 37256
:
170000
|
170001
|
170128
|
170129
|
170130
|
170152
|
170153
|
170154
|
170335
|
170336
|
170337
|
170338
|
171719
|
171720
|
171721
|
171722
|
171723
|
171724
|
171725
|
171726