Bugzilla – Attachment 172881 Details for
Bug 38175
Improve bookings behavior with new status field
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38175: Add tests
Bug-38175-Add-tests.patch (text/plain), 8.35 KB, created by
Martin Renvoize (ashimema)
on 2024-10-17 14:10:01 UTC
(
hide
)
Description:
Bug 38175: Add tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-10-17 14:10:01 UTC
Size:
8.35 KB
patch
obsolete
>From e2e0d974a53c48f312139a74e39ba25806a6b6ab Mon Sep 17 00:00:00 2001 >From: Thibaud Guillot <thibaud.guillot@biblibre.com> >Date: Tue, 15 Oct 2024 12:38:40 +0000 >Subject: [PATCH] Bug 38175: Add tests > >Sponsored by: BibLibre >Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > t/db_dependent/Koha/Booking.t | 130 ++++++++++++++++++++++++++++++- > t/db_dependent/api/v1/bookings.t | 67 +++++++++++++++- > 2 files changed, 193 insertions(+), 4 deletions(-) > >diff --git a/t/db_dependent/Koha/Booking.t b/t/db_dependent/Koha/Booking.t >index 80b7983cf1f..7350d0c24e4 100755 >--- a/t/db_dependent/Koha/Booking.t >+++ b/t/db_dependent/Koha/Booking.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > use utf8; > >-use Test::More tests => 3; >+use Test::More tests => 6; > > use Test::Exception; > >@@ -460,7 +460,7 @@ subtest 'store() tests' => sub { > }; > > subtest 'delete() tests' => sub { >- plan tests => 3; >+ plan tests => 2; > > $schema->storage->txn_begin; > >@@ -500,6 +500,77 @@ subtest 'delete() tests' => sub { > 'Koha::Booking->delete should have deleted the booking' > ); > >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'edit() tests' => sub { >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $biblio = $builder->build_sample_biblio; >+ my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); >+ my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); >+ my $end_0 = $start_0->clone->add( days => 6 ); >+ >+ $item_1->bookable(1)->store; >+ >+ my $booking = Koha::Booking->new( >+ { >+ patron_id => $patron->borrowernumber, >+ biblio_id => $biblio->biblionumber, >+ item_id => $item_1->itemnumber, >+ pickup_library_id => $item_1->homebranch, >+ start_date => $start_0, >+ end_date => $end_0, >+ } >+ )->store; >+ >+ my $booking_to_edit = Koha::Bookings->find( $booking->booking_id ); >+ $booking_to_edit->edit( { status => 'completed' } ); >+ >+ is( >+ $booking_to_edit->unblessed->{status}, 'completed', >+ 'Koha::Booking->edit should edit booking with passed params' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'cancel() tests' => sub { >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $biblio = $builder->build_sample_biblio; >+ my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); >+ my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); >+ my $end_0 = $start_0->clone->add( days => 6 ); >+ my $original_notices_count = Koha::Notice::Messages->search( >+ { >+ letter_code => 'BOOKING_CANCELLATION', >+ borrowernumber => $patron->borrowernumber, >+ } >+ )->count; >+ >+ $item_1->bookable(1)->store; >+ >+ my $booking = Koha::Booking->new( >+ { >+ patron_id => $patron->borrowernumber, >+ biblio_id => $biblio->biblionumber, >+ item_id => $item_1->itemnumber, >+ pickup_library_id => $item_1->homebranch, >+ start_date => $start_0, >+ end_date => $end_0, >+ } >+ )->store; >+ >+ my $booking_to_cancel = Koha::Bookings->find( $booking->booking_id ); >+ $booking_to_cancel->cancel( { send_letter => 1 } ); >+ > subtest 'notice trigger' => sub { > plan tests => 1; > >@@ -512,9 +583,62 @@ subtest 'delete() tests' => sub { > is( > $post_notices_count, > $original_notices_count + 1, >- 'Koha::Booking->delete should have enqueued a BOOKING_CANCELLATION email' >+ 'Koha::Booking->cancel should have enqueued a BOOKING_CANCELLATION email' > ); > }; > > $schema->storage->txn_rollback; > }; >+ >+subtest 'set_status() tests' => sub { >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $biblio = $builder->build_sample_biblio; >+ my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); >+ my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); >+ my $end_0 = $start_0->clone->add( days => 6 ); >+ >+ $item_1->bookable(1)->store; >+ >+ my $booking = Koha::Booking->new( >+ { >+ patron_id => $patron->borrowernumber, >+ biblio_id => $biblio->biblionumber, >+ item_id => $item_1->itemnumber, >+ pickup_library_id => $item_1->homebranch, >+ start_date => $start_0, >+ end_date => $end_0, >+ status => 'new', >+ } >+ )->store; >+ >+ my $booking_with_old_status = Koha::Bookings->find( $booking->booking_id ); >+ $booking_with_old_status->set_status('completed'); >+ is( $booking_with_old_status->unblessed->{status}, 'completed', 'Booking status is now "completed"' ); >+ >+ $booking_with_old_status->set_status('cancelled'); >+ is( $booking_with_old_status->unblessed->{status}, 'cancelled', 'Booking status is now "cancelled"' ); >+ >+ subtest 'unauthorized status' => sub { >+ plan tests => 2; >+ >+ eval { $booking_with_old_status->set_status('blah'); }; >+ >+ if ($@) { >+ like( >+ $@, qr/Invalid status: blah/, >+ 'An error is raised for unauthorized status' >+ ); >+ } else { >+ fail('Expected an error but none was raised'); >+ } >+ >+ # Status unchanged >+ is( $booking_with_old_status->unblessed->{status}, 'cancelled', 'Booking status is still "cancelled"' ); >+ }; >+ >+ $schema->storage->txn_rollback; >+}; >diff --git a/t/db_dependent/api/v1/bookings.t b/t/db_dependent/api/v1/bookings.t >index 27a11a67c80..44329537020 100755 >--- a/t/db_dependent/api/v1/bookings.t >+++ b/t/db_dependent/api/v1/bookings.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > use Test::Mojo; > use Test::Warn; > >@@ -437,3 +437,68 @@ subtest 'delete() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'patch() tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } # no additional permissions >+ } >+ ); >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $librarian->borrowernumber, >+ module_bit => 1, >+ code => 'manage_bookings', >+ }, >+ } >+ ); >+ 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; >+ >+ my $booking_id = $builder->build_object( { class => 'Koha::Bookings' } )->id; >+ >+ # Unauthorized attempt to partial update via PATCH >+ $t->patch_ok( >+ "//$unauth_userid:$password@/api/v1/bookings/$booking_id" => json => { status => 'cancelled' } >+ )->status_is(403); >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $item = $builder->build_sample_item( { bookable => 1, biblionumber => $biblio->id } ); >+ my $pickup_library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ >+ # Authorized attempt to write invalid data >+ my $booking_with_invalid_field = { >+ blah => "Booking Blah", >+ }; >+ >+ $t->patch_ok( "//$userid:$password@/api/v1/bookings/$booking_id" => json => $booking_with_invalid_field ) >+ ->status_is(400)->json_is( >+ "/errors" => [ >+ { >+ message => "Properties not allowed: blah.", >+ path => "/body" >+ } >+ ] >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.47.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 38175
:
172770
|
172771
|
172772
|
172773
|
172814
|
172815
|
172816
|
172817
|
172880
|
172881
|
172882
|
172883
|
172884
|
173172
|
173173
|
173174
|
173175
|
173176
|
173177
|
173178
|
173201
|
173202
|
173203
|
173346
|
173915