Lines 17-24
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 30; |
20 |
use Test::More tests => 43; |
21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
|
|
22 |
use t::lib::TestBuilder; |
22 |
|
23 |
|
23 |
use DateTime; |
24 |
use DateTime; |
24 |
|
25 |
|
Lines 34-43
my $dbh = C4::Context->dbh;
Link Here
|
34 |
$dbh->{AutoCommit} = 0; |
35 |
$dbh->{AutoCommit} = 0; |
35 |
$dbh->{RaiseError} = 1; |
36 |
$dbh->{RaiseError} = 1; |
36 |
|
37 |
|
|
|
38 |
my $builder = t::lib::TestBuilder->new(); |
37 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
39 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
38 |
|
40 |
|
39 |
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); |
41 |
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; |
40 |
my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); |
42 |
my $categorycode2 = $builder->build({ source => 'Category' })->{ categorycode }; |
|
|
43 |
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; |
41 |
|
44 |
|
42 |
my $borrower = Koha::Patron->new; |
45 |
my $borrower = Koha::Patron->new; |
43 |
$borrower->categorycode( $categorycode ); |
46 |
$borrower->categorycode( $categorycode ); |
Lines 47-53
$borrower->store;
Link Here
|
47 |
my $borrowernumber = $borrower->borrowernumber; |
50 |
my $borrowernumber = $borrower->borrowernumber; |
48 |
|
51 |
|
49 |
my $borrower2 = Koha::Patron->new; |
52 |
my $borrower2 = Koha::Patron->new; |
50 |
$borrower2->categorycode( $categorycode ); |
53 |
$borrower2->categorycode( $categorycode2 ); |
51 |
$borrower2->branchcode( $branchcode ); |
54 |
$borrower2->branchcode( $branchcode ); |
52 |
$borrower2->surname("Test Surname 2"); |
55 |
$borrower2->surname("Test Surname 2"); |
53 |
$borrower2->store; |
56 |
$borrower2->store; |
Lines 55-60
my $borrowernumber2 = $borrower2->borrowernumber;
Link Here
|
55 |
|
58 |
|
56 |
my $biblionumber = create_biblio('RESTful Web APIs'); |
59 |
my $biblionumber = create_biblio('RESTful Web APIs'); |
57 |
my $itemnumber = create_item($biblionumber, 'TEST000001'); |
60 |
my $itemnumber = create_item($biblionumber, 'TEST000001'); |
|
|
61 |
my $itemnumber2 = create_item($biblionumber, 'TEST000002'); |
62 |
|
63 |
my $biblionumber2 = create_biblio('Calamity'); |
64 |
my $itemnumber3 = create_item($biblionumber2, 'TEST000003'); |
65 |
my $itemnumber4 = create_item($biblionumber2, 'TEST000004'); |
66 |
my $itemnumber5 = create_item($biblionumber2, 'TEST000005'); |
58 |
|
67 |
|
59 |
my $reserve_id = C4::Reserves::AddReserve($branchcode, $borrowernumber, |
68 |
my $reserve_id = C4::Reserves::AddReserve($branchcode, $borrowernumber, |
60 |
$biblionumber, undef, 1, undef, undef, undef, '', $itemnumber); |
69 |
$biblionumber, undef, 1, undef, undef, undef, '', $itemnumber); |
Lines 99-119
$dbh->do('DELETE FROM issuingrules');
Link Here
|
99 |
$dbh->do(q{ |
108 |
$dbh->do(q{ |
100 |
INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
109 |
INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
101 |
VALUES (?, ?, ?, ?) |
110 |
VALUES (?, ?, ?, ?) |
102 |
}, {}, '*', '*', '*', 1); |
111 |
}, {}, $categorycode, '*', '*', 1); |
|
|
112 |
|
113 |
$dbh->do(q{ |
114 |
INSERT INTO issuingrules (categorycode, branchcode, itemtype, holds_per_record, reservesallowed) |
115 |
VALUES (?, ?, ?, ?, ?) |
116 |
}, {}, $categorycode2, '*', '*', '3', 5); |
103 |
|
117 |
|
104 |
my $expirationdate = DateTime->now->add(days => 10)->ymd; |
118 |
my $expirationdate = DateTime->now->add(days => 10)->ymd; |
105 |
my $post_data = { |
119 |
my $post_data = [{ |
106 |
borrowernumber => int($borrowernumber), |
120 |
borrowernumber => int($borrowernumber), |
107 |
biblionumber => int($biblionumber), |
121 |
biblionumber => int($biblionumber), |
108 |
itemnumber => int($itemnumber), |
122 |
itemnumber => int($itemnumber), |
109 |
branchcode => $branchcode, |
123 |
branchcode => $branchcode, |
110 |
expirationdate => $expirationdate, |
124 |
expirationdate => $expirationdate, |
111 |
}; |
125 |
}]; |
112 |
$t->post_ok("/api/v1/reserves" => json => $post_data) |
126 |
$t->post_ok("/api/v1/reserves" => json => $post_data) |
113 |
->status_is(201) |
127 |
->status_is(201) |
114 |
->json_has('/reserve_id'); |
128 |
->json_has('/0/reserve_id'); |
115 |
|
129 |
|
116 |
$reserve_id = $t->tx->res->json->{reserve_id}; |
130 |
$reserve_id = $t->tx->res->json->[0]->{reserve_id}; |
117 |
|
131 |
|
118 |
$t->get_ok("/api/v1/reserves?borrowernumber=$borrowernumber") |
132 |
$t->get_ok("/api/v1/reserves?borrowernumber=$borrowernumber") |
119 |
->status_is(200) |
133 |
->status_is(200) |
Lines 121-130
$t->get_ok("/api/v1/reserves?borrowernumber=$borrowernumber")
Link Here
|
121 |
->json_is('/0/expirationdate', $expirationdate) |
135 |
->json_is('/0/expirationdate', $expirationdate) |
122 |
->json_is('/0/branchcode', $branchcode); |
136 |
->json_is('/0/branchcode', $branchcode); |
123 |
|
137 |
|
|
|
138 |
$post_data->[0]->{biblionumber} = int($biblionumber2); |
139 |
$post_data->[0]->{itemnumber} = int($itemnumber3); |
124 |
$t->post_ok("/api/v1/reserves" => json => $post_data) |
140 |
$t->post_ok("/api/v1/reserves" => json => $post_data) |
125 |
->status_is(403) |
141 |
->status_is(403) |
126 |
->json_like('/error', qr/tooManyReserves/); |
142 |
->json_like('/error', qr/tooManyReserves/); |
127 |
|
143 |
|
|
|
144 |
$post_data = [ |
145 |
{ |
146 |
borrowernumber => int($borrowernumber2), |
147 |
biblionumber => int($biblionumber2), |
148 |
itemnumber => int($itemnumber3), |
149 |
branchcode => $branchcode, |
150 |
}, |
151 |
{ |
152 |
borrowernumber => int($borrowernumber2), |
153 |
biblionumber => int($biblionumber2), |
154 |
branchcode => $branchcode, |
155 |
}, |
156 |
]; |
157 |
|
158 |
$t->post_ok("/api/v1/reserves" => json => $post_data) |
159 |
->status_is(400) |
160 |
->json_like('/error', qr/Differents holds level/); |
161 |
|
162 |
delete $post_data->[0]->{itemnumber}; |
163 |
$t->post_ok("/api/v1/reserves" => json => $post_data) |
164 |
->status_is(201) |
165 |
->json_has('/0/reserve_id') |
166 |
->json_has('/1/reserve_id'); |
167 |
|
168 |
$t->post_ok("/api/v1/reserves" => json => $post_data) |
169 |
->status_is(400) |
170 |
->json_like('/error', qr/Too many holds/); |
171 |
|
172 |
delete $post_data->[1]; |
173 |
$post_data->[0]->{itemnumber} = int($itemnumber3); |
174 |
$t->post_ok("/api/v1/reserves" => json => $post_data) |
175 |
->status_is(400) |
176 |
->json_like('/error', qr/Differents holds level/); |
177 |
|
128 |
|
178 |
|
129 |
$dbh->rollback; |
179 |
$dbh->rollback; |
130 |
|
180 |
|
131 |
- |
|
|