Lines 18-24
Link Here
|
18 |
|
18 |
|
19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
20 |
|
20 |
|
21 |
use Test::More tests => 1; |
21 |
use Test::More tests => 2; |
22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
Lines 26-35
use t::lib::TestBuilder;
Link Here
|
26 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
27 |
|
27 |
|
28 |
use C4::Auth; |
28 |
use C4::Auth; |
|
|
29 |
use C4::Context; |
29 |
use Koha::Database; |
30 |
use Koha::Database; |
|
|
31 |
use Koha::Holds; |
32 |
use Koha::Patrons; |
33 |
use JSON qw( decode_json ); |
30 |
|
34 |
|
31 |
my $schema = Koha::Database->new->schema; |
35 |
my $schema = Koha::Database->new->schema; |
32 |
my $builder = t::lib::TestBuilder->new; |
36 |
my $builder = t::lib::TestBuilder->new; |
|
|
37 |
my $dbh = C4::Context->dbh; |
33 |
|
38 |
|
34 |
# FIXME: sessionStorage defaults to mysql, but it seems to break transaction handling |
39 |
# FIXME: sessionStorage defaults to mysql, but it seems to break transaction handling |
35 |
# this affects the other REST api tests |
40 |
# this affects the other REST api tests |
Lines 82-87
subtest 'add() tests' => sub {
Link Here
|
82 |
}; |
87 |
}; |
83 |
}; |
88 |
}; |
84 |
|
89 |
|
|
|
90 |
subtest "default patron home" => sub { |
91 |
plan tests => 8; |
92 |
|
93 |
$schema->storage->txn_begin; |
94 |
|
95 |
my ($club_with_enrollments, $club_without_enrollments, $item, @enrollments) = create_test_data(); |
96 |
|
97 |
my ( undef, $session_id ) = create_user_and_session({ authorized => 1 }); |
98 |
my $data = { |
99 |
biblio_id => $item->biblionumber, |
100 |
pickup_library_id => $item->home_branch->branchcode, |
101 |
default_patron_home => 1 |
102 |
}; |
103 |
|
104 |
my $tx = $t->ua->build_tx(POST => "/api/v1/clubs/".$club_with_enrollments->id."/holds" => json => $data); |
105 |
$tx->req->cookies({ name => 'CGISESSID', value => $session_id }); |
106 |
$t->request_ok($tx) |
107 |
->status_is(201, 'Created Hold'); |
108 |
|
109 |
my $json_response = decode_json $t->tx->res->content->get_body_chunk; |
110 |
|
111 |
my $sth = $dbh->prepare( |
112 |
"select patron_id, hold_id from club_holds_to_patron_holds where club_hold_id = ?" |
113 |
); |
114 |
$sth->execute($json_response->{club_hold_id}); |
115 |
while (my $test = $sth->fetchrow_hashref()) { |
116 |
my $hold = Koha::Holds->find($test->{hold_id}); |
117 |
my $patron = Koha::Patrons->find($test->{patron_id}); |
118 |
is($hold->branchcode, $patron->branchcode, 'Pickup location should be patrons home branch'); |
119 |
} |
120 |
$schema->storage->txn_rollback; |
121 |
}; |
122 |
|
85 |
sub unauthorized_access_tests { |
123 |
sub unauthorized_access_tests { |
86 |
my ($verb, $endpoint, $club_hold_id, $json) = @_; |
124 |
my ($verb, $endpoint, $club_hold_id, $json) = @_; |
87 |
|
125 |
|
Lines 138-149
sub create_user_and_session {
Link Here
|
138 |
sub create_test_data { |
176 |
sub create_test_data { |
139 |
my $club_with_enrollments = $builder->build_object( { class => 'Koha::Clubs' } ); |
177 |
my $club_with_enrollments = $builder->build_object( { class => 'Koha::Clubs' } ); |
140 |
my $club_without_enrollments = $builder->build_object( { class => 'Koha::Clubs' } ); |
178 |
my $club_without_enrollments = $builder->build_object( { class => 'Koha::Clubs' } ); |
141 |
my $enrollment1 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef } } ); |
179 |
my $lib = $builder->build_object({ class => 'Koha::Libraries', value => {pickup_location => 1}}); |
142 |
my $enrollment2 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef } } ); |
180 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib->branchcode}}); |
143 |
my $enrollment3 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef } } ); |
181 |
my $enrollment1 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef, borrowernumber => $patron->borrowernumber } } ); |
144 |
my $enrollment4 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef } } ); |
182 |
$lib = $builder->build_object({ class => 'Koha::Libraries', value => {pickup_location => 1}}); |
145 |
my $enrollment5 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef } } ); |
183 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib->branchcode}}); |
146 |
my $enrollment6 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef } } ); |
184 |
my $enrollment2 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef, borrowernumber => $patron->borrowernumber } } ); |
147 |
my $item = $builder->build_sample_item(); |
185 |
$lib = $builder->build_object({ class => 'Koha::Libraries', value => {pickup_location => 1}}); |
|
|
186 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib->branchcode}}); |
187 |
my $enrollment3 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef, borrowernumber => $patron->borrowernumber } } ); |
188 |
$lib = $builder->build_object({ class => 'Koha::Libraries', value => {pickup_location => 1}}); |
189 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib->branchcode}}); |
190 |
my $enrollment4 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef, borrowernumber => $patron->borrowernumber } } ); |
191 |
$lib = $builder->build_object({ class => 'Koha::Libraries', value => {pickup_location => 1}}); |
192 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib->branchcode}}); |
193 |
my $enrollment5 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef, borrowernumber => $patron->borrowernumber } } ); |
194 |
$lib = $builder->build_object({ class => 'Koha::Libraries', value => {pickup_location => 1}}); |
195 |
$patron = $builder->build_object({ class => 'Koha::Patrons', value => {branchcode => $lib->branchcode}}); |
196 |
my $enrollment6 = $builder->build_object( { class => 'Koha::Club::Enrollments', value => { club_id => $club_with_enrollments->id, date_canceled => undef, borrowernumber => $patron->borrowernumber } } ); |
197 |
$lib = $builder->build_object({ class => 'Koha::Libraries', value => {pickup_location => 1}}); |
198 |
my $item = $builder->build_sample_item({homebranch => $lib->branchcode}); |
148 |
return ( $club_with_enrollments, $club_without_enrollments, $item, [ $enrollment1, $enrollment2, $enrollment3, $enrollment4, $enrollment5, $enrollment6 ] ); |
199 |
return ( $club_with_enrollments, $club_without_enrollments, $item, [ $enrollment1, $enrollment2, $enrollment3, $enrollment4, $enrollment5, $enrollment6 ] ); |
149 |
} |
200 |
} |
150 |
- |
|
|