Bugzilla – Attachment 185919 Details for
Bug 36536
Make REST API's validateUserAndPassword update borrowers.lastseen
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36536: Unit tests
Bug-36536-Unit-tests.patch (text/plain), 3.53 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-08-29 13:24:09 UTC
(
hide
)
Description:
Bug 36536: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-08-29 13:24:09 UTC
Size:
3.53 KB
patch
obsolete
>From 3892da6e8ee9533c3c5d972b516e13f61f1b3644 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 29 Aug 2025 09:57:49 -0300 >Subject: [PATCH] Bug 36536: Unit tests > >This patch introduces tests for the feature enabling patron's `lastseen` >attribute be updated when a successful password validation happens >through the API. > >To test: >1. Apply this patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/api/v1/password_validation.t >=> FAIL: Tests fail! The feature is not implemented! > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/api/v1/password_validation.t | 51 ++++++++++++++++++++- > 1 file changed, 50 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/password_validation.t b/t/db_dependent/api/v1/password_validation.t >index 6e59d52a51c..84c056161a1 100755 >--- a/t/db_dependent/api/v1/password_validation.t >+++ b/t/db_dependent/api/v1/password_validation.t >@@ -129,7 +129,7 @@ subtest 'password validation - unauthenticated user' => sub { > > subtest 'Password validation - authorized requests tests' => sub { > >- plan tests => 24; >+ plan tests => 25; > > $schema->storage->txn_begin; > >@@ -216,6 +216,55 @@ subtest 'Password validation - authorized requests tests' => sub { > ->status_is( 400, 'Passing both parameters forbidden' ) > ->json_is( { error => 'Bad request. Only one identifier attribute can be passed.' } ); > >+ subtest 'TrackLastPatronActivityTriggers tests' => sub { >+ >+ plan tests => 9; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { lastseen => undef } } ); >+ my $patron_password = 'thePassword123'; >+ $patron->set_password( { password => $patron_password, skip_validation => 1 } ); >+ >+ # to avoid interference >+ t::lib::Mocks::mock_preference( 'FailedLoginAttempts', 99 ); >+ >+ # api_verify disabled >+ t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login' ); >+ >+ $patron->lastseen(undef)->store(); >+ $t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => >+ { identifier => $patron->userid, password => $patron_password } )->status_is( 201, 'Validation works' ); >+ >+ # read patron from the DB >+ $patron->discard_changes(); >+ is( >+ $patron->lastseen, undef, >+ "'lastseen' flag untouched if no 'api_verify' in TrackLastPatronActivityTriggers" >+ ); >+ >+ # good scenario >+ t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'api_verify' ); >+ >+ $patron->lastseen(undef)->store(); >+ $t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => >+ { identifier => $patron->userid, password => 'wrong password :-D' } ) >+ ->status_is( 400, 'Validation failed due to bad password' ); >+ >+ # read patron from the DB >+ $patron->discard_changes(); >+ is( $patron->lastseen, undef, "'lastseen' flag not updated as validation failed" ); >+ >+ $patron->lastseen(undef)->store(); >+ $t->post_ok( "//$userid:$password@/api/v1/auth/password/validation" => json => >+ { identifier => $patron->userid, password => $patron_password } )->status_is( 201, 'Validation works' ); >+ >+ # read patron from the DB >+ $patron->discard_changes(); >+ ok( >+ $patron->lastseen, >+ "'lastseen' flag updated TrackLastPatronActivityTriggers includes 'api_verify'" >+ ); >+ }; >+ > $schema->storage->txn_rollback; > }; > >-- >2.51.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 36536
:
185532
|
185534
|
185582
|
185906
|
185917
|
185918
| 185919 |
185920