Bugzilla – Attachment 165143 Details for
Bug 33363
More specific permissions for purchase suggestions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33363: Add unit tests
Bug-33363-Add-unit-tests.patch (text/plain), 3.31 KB, created by
Kyle M Hall
on 2024-04-18 18:10:49 UTC
(
hide
)
Description:
Bug 33363: Add unit tests
Filename:
MIME Type:
Creator:
Kyle M Hall
Created:
2024-04-18 18:10:49 UTC
Size:
3.31 KB
patch
obsolete
>From fa3ceda4aa9884057c4ca3cc0411fa531638412e Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 11 Jan 2024 08:58:29 -0500 >Subject: [PATCH] Bug 33363: Add unit tests > >--- > t/db_dependent/api/v1/suggestions.t | 88 ++++++++++++++++++++++++++++- > 1 file changed, 87 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/suggestions.t b/t/db_dependent/api/v1/suggestions.t >index b7b06935277..90649bb34b9 100755 >--- a/t/db_dependent/api/v1/suggestions.t >+++ b/t/db_dependent/api/v1/suggestions.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > use Test::Mojo; > > use t::lib::TestBuilder; >@@ -420,3 +420,89 @@ subtest 'delete() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'Permissions tests' => sub { >+ plan tests => 11; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**4 } # 4 = catalogue >+ } >+ ); >+ >+ 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 } >+ } >+ ); >+ my $patron_id = $patron->id; >+ >+ my $suggestion = $builder->build_object( >+ { >+ class => 'Koha::Suggestions', >+ value => { suggestedby => $patron_id, STATUS => 'ASKED' } >+ } >+ ); >+ my $suggestion_data = $suggestion->to_api; >+ delete $suggestion_data->{suggestion_id}; >+ $suggestion->delete; >+ >+ # Unauthorized attempt to write >+ $t->post_ok( >+ "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) >+ ->status_is( 403, 'SWAGGER3.2.1' ); >+ >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $librarian->id, >+ module_bit => 12, # 12 = suggestions >+ code => 'suggestions_create', >+ }, >+ } >+ ); >+ >+ # Authorized attempt to write >+ my $generated_suggestion = >+ $t->post_ok( >+ "//$userid:$password@/api/v1/suggestions" => json => $suggestion_data ) >+ ->status_is( 201, 'SWAGGER3.2.1' )->header_like( >+ Location => qr|^\/api\/v1\/suggestions\/\d*|, >+ 'SWAGGER3.4.1' >+ )->tx->res->json; >+ >+ my $suggestion_id = $generated_suggestion->{suggestion_id}; >+ is_deeply( >+ $generated_suggestion, >+ Koha::Suggestions->find($suggestion_id)->to_api, >+ 'The object is returned' >+ ); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/suggestions/$suggestion_id") >+ ->status_is(403); >+ >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $librarian->id, >+ module_bit => 12, # 12 = suggestions >+ code => 'suggestions_delete', >+ }, >+ } >+ ); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/suggestions/$suggestion_id") >+ ->status_is( 204, 'SWAGGER3.2.4' )->content_is( q{}, 'SWAGGER3.3.4' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.30.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 33363
:
150247
|
150450
|
153177
|
160846
|
160847
|
160902
|
160903
|
165142
|
165143
|
168052
|
168053
|
168055
|
168056
|
168356
|
168357
|
168358
|
168359
|
168803
|
168804
|
168805
|
168806
|
168807
|
168808
|
168865
|
168866
|
168867
|
168868
|
168869