Lines 61-73
subtest 'add() tests' => sub {
Link Here
|
61 |
|
61 |
|
62 |
subtest 'librarian access tests' => sub { |
62 |
subtest 'librarian access tests' => sub { |
63 |
|
63 |
|
64 |
plan tests => 21; |
64 |
plan tests => 29; |
65 |
|
65 |
|
66 |
$schema->storage->txn_begin; |
66 |
$schema->storage->txn_begin; |
67 |
|
67 |
|
68 |
my ( $club_with_enrollments, $club_without_enrollments, $item, @enrollments ) = create_test_data(); |
68 |
my ( $club_with_enrollments, $club_without_enrollments, $item, @enrollments ) = create_test_data(); |
69 |
my $club_with_enrollments_id = $club_with_enrollments->id; |
69 |
my $club_with_enrollments_id = $club_with_enrollments->id; |
70 |
|
70 |
|
|
|
71 |
#staff with top level reserveforothers permissions |
71 |
my $librarian = $builder->build_object( |
72 |
my $librarian = $builder->build_object( |
72 |
{ |
73 |
{ |
73 |
class => 'Koha::Patrons', |
74 |
class => 'Koha::Patrons', |
Lines 78-83
subtest 'add() tests' => sub {
Link Here
|
78 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
79 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
79 |
my $userid = $librarian->userid; |
80 |
my $userid = $librarian->userid; |
80 |
|
81 |
|
|
|
82 |
#staff with only the specific place_holds permission |
83 |
my $librarian_2 = $builder->build_object( |
84 |
{ |
85 |
class => 'Koha::Patrons', |
86 |
value => { userid => 'lukeg', flags => 0 } |
87 |
} |
88 |
); |
89 |
$builder->build( |
90 |
{ |
91 |
source => 'UserPermission', |
92 |
value => { |
93 |
borrowernumber => $librarian_2->borrowernumber, |
94 |
module_bit => 6, |
95 |
code => 'place_holds', |
96 |
}, |
97 |
} |
98 |
); |
99 |
my $password_2 = 'AbcdEFG123'; |
100 |
$librarian_2->set_password( { password => $password_2, skip_validation => 1 } ); |
101 |
my $userid_2 = $librarian_2->userid; |
102 |
|
103 |
# staff with no reserveforothers permissions |
104 |
my $librarian_3 = $builder->build_object( |
105 |
{ |
106 |
class => 'Koha::Patrons', |
107 |
value => { userid => 'no_club_for_you', flags => 0 } |
108 |
} |
109 |
); |
110 |
my $password_3 = 'noholdsforyou123'; |
111 |
$librarian_3->set_password( { password => $password_3, skip_validation => 1 } ); |
112 |
my $userid_3 = $librarian_3->userid; |
113 |
|
81 |
my $non_existent_item = $builder->build_sample_item; |
114 |
my $non_existent_item = $builder->build_sample_item; |
82 |
my $non_existent_biblio = $non_existent_item->biblio; |
115 |
my $non_existent_biblio = $non_existent_item->biblio; |
83 |
|
116 |
|
Lines 125-130
subtest 'add() tests' => sub {
Link Here
|
125 |
$t->post_ok( "//$userid:$password@/api/v1/clubs/" . $club_without_enrollments->id . "/holds" => json => $data ) |
158 |
$t->post_ok( "//$userid:$password@/api/v1/clubs/" . $club_without_enrollments->id . "/holds" => json => $data ) |
126 |
->status_is(409)->json_is( '/error' => "Cannot place a hold on a club without patrons." ); |
159 |
->status_is(409)->json_is( '/error' => "Cannot place a hold on a club without patrons." ); |
127 |
|
160 |
|
|
|
161 |
# place a club hold with top level reserveforothers permission - should succeed |
128 |
$t->post_ok( "//$userid:$password@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data ) |
162 |
$t->post_ok( "//$userid:$password@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data ) |
129 |
->status_is( 201, 'Created Hold' )->json_has( '/club_hold_id', 'got a club hold id' ) |
163 |
->status_is( 201, 'Created Hold' )->json_has( '/club_hold_id', 'got a club hold id' ) |
130 |
->json_is( '/club_id' => $club_with_enrollments->id )->json_is( '/biblio_id' => $item->biblionumber ) |
164 |
->json_is( '/club_id' => $club_with_enrollments->id )->json_is( '/biblio_id' => $item->biblionumber ) |
Lines 133-138
subtest 'add() tests' => sub {
Link Here
|
133 |
'REST3.4.1' |
167 |
'REST3.4.1' |
134 |
); |
168 |
); |
135 |
|
169 |
|
|
|
170 |
# place a club hold with the place_hold specific permsision - should succeed |
171 |
$t->post_ok( "//$userid_2:$password_2@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data ) |
172 |
->status_is( 201, 'Created Hold with specific place_holds permission' ) |
173 |
->json_has( '/club_hold_id', 'got a club hold id' )->json_is( '/club_id' => $club_with_enrollments->id ) |
174 |
->json_is( '/biblio_id' => $item->biblionumber ); |
175 |
|
176 |
# place a club hold with no reserveforothers or specific permsision - should fail |
177 |
$t->post_ok( "//$userid_3:$password_3@/api/v1/clubs/" . $club_with_enrollments->id . "/holds" => json => $data ) |
178 |
->status_is( 403, 'User with no relevant permissions cannot place club holds' ) |
179 |
->json_is( '/error' => 'Authorization failure. Missing required permission(s).' ); |
180 |
|
136 |
$schema->storage->txn_rollback; |
181 |
$schema->storage->txn_rollback; |
137 |
}; |
182 |
}; |
138 |
}; |
183 |
}; |
139 |
- |
|
|