Lines 53-100
subtest 'list() tests' => sub {
Link Here
|
53 |
my $tx = $t->ua->build_tx( GET => '/api/v1/cities' ); |
53 |
my $tx = $t->ua->build_tx( GET => '/api/v1/cities' ); |
54 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
54 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
55 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
55 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
56 |
$t->request_ok($tx)->status_is(200)->json_is( [] ); |
56 |
$t->request_ok($tx) |
|
|
57 |
->status_is(200) |
58 |
->json_is( [] ); |
57 |
|
59 |
|
58 |
my $city_country = 'France'; |
60 |
my $city = $builder->build_object({ class => 'Koha::Cities' }); |
59 |
my $city = $builder->build( |
|
|
60 |
{ source => 'City', value => { city_country => $city_country } } ); |
61 |
|
61 |
|
62 |
# One city created, should get returned |
62 |
# One city created, should get returned |
63 |
$tx = $t->ua->build_tx( GET => '/api/v1/cities' ); |
63 |
$tx = $t->ua->build_tx( GET => '/api/v1/cities' ); |
64 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
64 |
$tx->req->cookies({ name => 'CGISESSID', value => $session_id }); |
65 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
65 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
66 |
$t->request_ok($tx)->status_is(200)->json_is( [$city] ); |
66 |
$t->request_ok($tx) |
|
|
67 |
->status_is(200) |
68 |
->json_is( [Koha::REST::V1::Cities::_to_api( $city->TO_JSON )] ); |
67 |
|
69 |
|
68 |
my $another_city = $builder->build( |
70 |
my $another_city = $builder->build_object( |
69 |
{ source => 'City', value => { city_country => $city_country } } ); |
71 |
{ class => 'Koha::Cities', value => { city_country => $city->city_country } } ); |
70 |
my $city_with_another_country = $builder->build( { source => 'City' } ); |
72 |
my $city_with_another_country = $builder->build_object({ class => 'Koha::Cities' }); |
71 |
|
73 |
|
72 |
# Two cities created, they should both be returned |
74 |
# Two cities created, they should both be returned |
73 |
$tx = $t->ua->build_tx( GET => '/api/v1/cities' ); |
75 |
$tx = $t->ua->build_tx( GET => '/api/v1/cities' ); |
74 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
76 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
75 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
77 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
76 |
$t->request_ok($tx)->status_is(200) |
78 |
$t->request_ok($tx)->status_is(200) |
77 |
->json_is( [ $city, $another_city, $city_with_another_country ] ); |
79 |
->json_is([Koha::REST::V1::Cities::_to_api($city->TO_JSON), |
|
|
80 |
Koha::REST::V1::Cities::_to_api($another_city->TO_JSON), |
81 |
Koha::REST::V1::Cities::_to_api($city_with_another_country->TO_JSON) |
82 |
] ); |
78 |
|
83 |
|
79 |
# Filtering works, two cities sharing city_country |
84 |
# Filtering works, two cities sharing city_country |
80 |
$tx = |
85 |
$tx = $t->ua->build_tx( GET => "/api/v1/cities?country=" . $city->city_country ); |
81 |
$t->ua->build_tx( GET => "/api/v1/cities?city_country=" . $city_country ); |
86 |
$tx->req->cookies({ name => 'CGISESSID', value => $session_id }); |
82 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
87 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
83 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
88 |
$t->request_ok($tx) |
84 |
my $result = |
89 |
->status_is(200) |
85 |
$t->request_ok($tx)->status_is(200)->json_is( [ $city, $another_city ] ); |
90 |
->json_is([ Koha::REST::V1::Cities::_to_api($city->TO_JSON), |
86 |
|
91 |
Koha::REST::V1::Cities::_to_api($another_city->TO_JSON) |
87 |
$tx = $t->ua->build_tx( |
92 |
]); |
88 |
GET => "/api/v1/cities?city_name=" . $city->{city_name} ); |
93 |
|
89 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
94 |
$tx = $t->ua->build_tx( GET => "/api/v1/cities?name=" . $city->city_name ); |
90 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
95 |
$tx->req->cookies({ name => 'CGISESSID', value => $session_id }); |
91 |
$t->request_ok($tx)->status_is(200)->json_is( [$city] ); |
96 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
|
|
97 |
$t->request_ok($tx) |
98 |
->status_is(200) |
99 |
->json_is( [Koha::REST::V1::Cities::_to_api($city->TO_JSON)] ); |
92 |
|
100 |
|
93 |
# Warn on unsupported query parameter |
101 |
# Warn on unsupported query parameter |
94 |
$tx = $t->ua->build_tx( GET => '/api/v1/cities?city_blah=blah' ); |
102 |
$tx = $t->ua->build_tx( GET => '/api/v1/cities?city_blah=blah' ); |
95 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
103 |
$tx->req->cookies({ name => 'CGISESSID', value => $session_id }); |
96 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
104 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
97 |
$t->request_ok($tx)->status_is(400) |
105 |
$t->request_ok($tx) |
|
|
106 |
->status_is(400) |
98 |
->json_is( [{ path => '/query/city_blah', message => 'Malformed query string'}] ); |
107 |
->json_is( [{ path => '/query/city_blah', message => 'Malformed query string'}] ); |
99 |
|
108 |
|
100 |
$schema->storage->txn_rollback; |
109 |
$schema->storage->txn_rollback; |
Lines 106-125
subtest 'get() tests' => sub {
Link Here
|
106 |
|
115 |
|
107 |
$schema->storage->txn_begin; |
116 |
$schema->storage->txn_begin; |
108 |
|
117 |
|
109 |
my $city = $builder->build( { source => 'City' } ); |
118 |
my $city = $builder->build_object({ class => 'Koha::Cities' }); |
110 |
my ( $borrowernumber, $session_id ) = |
119 |
my ( $borrowernumber, $session_id ) = create_user_and_session({ authorized => 0 }); |
111 |
create_user_and_session( { authorized => 0 } ); |
|
|
112 |
|
120 |
|
113 |
my $tx = $t->ua->build_tx( GET => "/api/v1/cities/" . $city->{cityid} ); |
121 |
my $tx = $t->ua->build_tx( GET => "/api/v1/cities/" . $city->id ); |
114 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
122 |
$tx->req->cookies({ name => 'CGISESSID', value => $session_id }); |
115 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
123 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
116 |
$t->request_ok($tx)->status_is(200)->json_is($city); |
124 |
$t->request_ok($tx) |
|
|
125 |
->status_is(200) |
126 |
->json_is(Koha::REST::V1::Cities::_to_api($city->TO_JSON)); |
127 |
|
128 |
my $city_to_delete = $builder->build_object({ class => 'Koha::Cities' }); |
129 |
my $non_existent_id = $city_to_delete->id; |
130 |
$city_to_delete->delete; |
117 |
|
131 |
|
118 |
my $non_existent_id = $city->{cityid} + 1; |
|
|
119 |
$tx = $t->ua->build_tx( GET => "/api/v1/cities/" . $non_existent_id ); |
132 |
$tx = $t->ua->build_tx( GET => "/api/v1/cities/" . $non_existent_id ); |
120 |
$tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); |
133 |
$tx->req->cookies({ name => 'CGISESSID', value => $session_id }); |
121 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
134 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
122 |
$t->request_ok($tx)->status_is(404) |
135 |
$t->request_ok($tx) |
|
|
136 |
->status_is(404) |
123 |
->json_is( '/error' => 'City not found' ); |
137 |
->json_is( '/error' => 'City not found' ); |
124 |
|
138 |
|
125 |
$schema->storage->txn_rollback; |
139 |
$schema->storage->txn_rollback; |
Lines 136-209
subtest 'add() tests' => sub {
Link Here
|
136 |
my ( $authorized_borrowernumber, $authorized_session_id ) = |
150 |
my ( $authorized_borrowernumber, $authorized_session_id ) = |
137 |
create_user_and_session( { authorized => 1 } ); |
151 |
create_user_and_session( { authorized => 1 } ); |
138 |
my $city = { |
152 |
my $city = { |
139 |
city_name => "City Name", |
153 |
name => "City Name", |
140 |
city_state => "City State", |
154 |
state => "City State", |
141 |
city_zipcode => "City Zipcode", |
155 |
postal_code => "City Zipcode", |
142 |
city_country => "City Country" |
156 |
country => "City Country" |
143 |
}; |
157 |
}; |
144 |
|
158 |
|
145 |
# Unauthorized attempt to write |
159 |
# Unauthorized attempt to write |
146 |
my $tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city ); |
160 |
my $tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city ); |
147 |
$tx->req->cookies( |
161 |
$tx->req->cookies({ name => 'CGISESSID', value => $unauthorized_session_id }); |
148 |
{ name => 'CGISESSID', value => $unauthorized_session_id } ); |
162 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
149 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
163 |
$t->request_ok($tx) |
150 |
$t->request_ok($tx)->status_is(403); |
164 |
->status_is(403); |
151 |
|
165 |
|
152 |
# Authorized attempt to write invalid data |
166 |
# Authorized attempt to write invalid data |
153 |
my $city_with_invalid_field = { |
167 |
my $city_with_invalid_field = { |
154 |
city_blah => "City Blah", |
168 |
blah => "City Blah", |
155 |
city_state => "City State", |
169 |
state => "City State", |
156 |
city_zipcode => "City Zipcode", |
170 |
postal_code => "City Zipcode", |
157 |
city_country => "City Country" |
171 |
country => "City Country" |
158 |
}; |
172 |
}; |
159 |
|
173 |
|
160 |
$tx = $t->ua->build_tx( |
174 |
$tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city_with_invalid_field ); |
161 |
POST => "/api/v1/cities/" => json => $city_with_invalid_field ); |
175 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
162 |
$tx->req->cookies( |
|
|
163 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
164 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
176 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
165 |
$t->request_ok($tx)->status_is(400)->json_is( |
177 |
$t->request_ok($tx) |
|
|
178 |
->status_is(400) |
179 |
->json_is( |
166 |
"/errors" => [ |
180 |
"/errors" => [ |
167 |
{ |
181 |
{ |
168 |
message => "Properties not allowed: city_blah.", |
182 |
message => "Properties not allowed: blah.", |
169 |
path => "/body" |
183 |
path => "/body" |
170 |
} |
184 |
} |
171 |
] |
185 |
] |
172 |
); |
186 |
); |
173 |
|
187 |
|
174 |
# Authorized attempt to write |
188 |
# Authorized attempt to write |
175 |
$tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city ); |
189 |
$tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city ); |
176 |
$tx->req->cookies( |
190 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
177 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
191 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
178 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
192 |
my $city_id = |
179 |
my $cityid = $t->request_ok($tx)->status_is(200) |
193 |
$t->request_ok($tx) |
180 |
->json_is( '/city_name' => $city->{city_name} ) |
194 |
->status_is(200) |
181 |
->json_is( '/city_state' => $city->{city_state} ) |
195 |
->json_is( '/name' => $city->{name} ) |
182 |
->json_is( '/city_zipcode' => $city->{city_zipcode} ) |
196 |
->json_is( '/state' => $city->{state} ) |
183 |
->json_is( '/city_country' => $city->{city_country} ) |
197 |
->json_is( '/postal_code' => $city->{postal_code} ) |
184 |
->tx->res->json->{cityid}; |
198 |
->json_is( '/country' => $city->{country} ) |
|
|
199 |
->tx->res->json->{city_id}; |
185 |
|
200 |
|
186 |
# Authorized attempt to create with null id |
201 |
# Authorized attempt to create with null id |
187 |
$city->{cityid} = undef; |
202 |
$city->{city_id} = undef; |
188 |
$tx = $t->ua->build_tx( |
203 |
$tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city ); |
189 |
POST => "/api/v1/cities/" => json => $city ); |
204 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
190 |
$tx->req->cookies( |
205 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
191 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
206 |
$t->request_ok($tx) |
192 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
207 |
->status_is(400) |
193 |
$t->request_ok($tx)->status_is(400)->json_has('/errors'); |
208 |
->json_has('/errors'); |
194 |
|
209 |
|
195 |
# Authorized attempt to create with existing id |
210 |
# Authorized attempt to create with existing id |
196 |
$city->{cityid} = $cityid; |
211 |
$city->{city_id} = $city_id; |
197 |
$tx = $t->ua->build_tx( |
212 |
$tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city ); |
198 |
POST => "/api/v1/cities/" => json => $city ); |
213 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
199 |
$tx->req->cookies( |
214 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
200 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
215 |
$t->request_ok($tx) |
201 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
216 |
->status_is(400) |
202 |
$t->request_ok($tx)->status_is(400)->json_is( |
217 |
->json_is( |
203 |
"/errors" => [ |
218 |
"/errors" => [ |
204 |
{ |
219 |
{ |
205 |
message => "Read-only.", |
220 |
message => "Read-only.", |
206 |
path => "/body/cityid" |
221 |
path => "/body/city_id" |
207 |
} |
222 |
} |
208 |
] |
223 |
] |
209 |
); |
224 |
); |
Lines 222-311
subtest 'update() tests' => sub {
Link Here
|
222 |
my ( $authorized_borrowernumber, $authorized_session_id ) = |
237 |
my ( $authorized_borrowernumber, $authorized_session_id ) = |
223 |
create_user_and_session( { authorized => 1 } ); |
238 |
create_user_and_session( { authorized => 1 } ); |
224 |
|
239 |
|
225 |
my $city_id = $builder->build( { source => 'City' } )->{cityid}; |
240 |
my $city_id = $builder->build_object({ class => 'Koha::Cities' } )->id; |
226 |
|
241 |
|
227 |
# Unauthorized attempt to update |
242 |
# Unauthorized attempt to update |
228 |
my $tx = $t->ua->build_tx( PUT => "/api/v1/cities/$city_id" => json => |
243 |
my $tx = $t->ua->build_tx( PUT => "/api/v1/cities/$city_id" => json => |
229 |
{ city_name => 'New unauthorized name change' } ); |
244 |
{ name => 'New unauthorized name change' } ); |
230 |
$tx->req->cookies( |
245 |
$tx->req->cookies({ name => 'CGISESSID', value => $unauthorized_session_id }); |
231 |
{ name => 'CGISESSID', value => $unauthorized_session_id } ); |
246 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
232 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
247 |
$t->request_ok($tx) |
233 |
$t->request_ok($tx)->status_is(403); |
248 |
->status_is(403); |
234 |
|
249 |
|
235 |
# Attempt partial update on a PUT |
250 |
# Attempt partial update on a PUT |
236 |
my $city_with_missing_field = { |
251 |
my $city_with_missing_field = { |
237 |
city_name => 'New name', |
252 |
name => 'New name', |
238 |
city_state => 'New state', |
253 |
state => 'New state', |
239 |
city_country => 'New country' |
254 |
country => 'New country' |
240 |
}; |
255 |
}; |
241 |
|
256 |
|
242 |
$tx = $t->ua->build_tx( |
257 |
$tx = $t->ua->build_tx( |
243 |
PUT => "/api/v1/cities/$city_id" => json => $city_with_missing_field ); |
258 |
PUT => "/api/v1/cities/$city_id" => json => $city_with_missing_field ); |
244 |
$tx->req->cookies( |
259 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
245 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
260 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
246 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
|
|
247 |
$t->request_ok($tx)->status_is(400) |
261 |
$t->request_ok($tx)->status_is(400) |
248 |
->json_is( "/errors" => |
262 |
->json_is( "/errors" => |
249 |
[ { message => "Missing property.", path => "/body/city_zipcode" } ] |
263 |
[ { message => "Missing property.", path => "/body/postal_code" } ] |
250 |
); |
264 |
); |
251 |
|
265 |
|
252 |
# Full object update on PUT |
266 |
# Full object update on PUT |
253 |
my $city_with_updated_field = { |
267 |
my $city_with_updated_field = { |
254 |
city_name => "London", |
268 |
name => "London", |
255 |
city_state => "City State", |
269 |
state => "City State", |
256 |
city_zipcode => "City Zipcode", |
270 |
postal_code => "City Zipcode", |
257 |
city_country => "City Country" |
271 |
country => "City Country" |
258 |
}; |
272 |
}; |
259 |
|
273 |
|
260 |
$tx = $t->ua->build_tx( |
274 |
$tx = $t->ua->build_tx( PUT => "/api/v1/cities/$city_id" => json => $city_with_updated_field ); |
261 |
PUT => "/api/v1/cities/$city_id" => json => $city_with_updated_field ); |
275 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
262 |
$tx->req->cookies( |
276 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
263 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
277 |
$t->request_ok($tx) |
264 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
278 |
->status_is(200) |
265 |
$t->request_ok($tx)->status_is(200)->json_is( '/city_name' => 'London' ); |
279 |
->json_is( '/name' => 'London' ); |
266 |
|
280 |
|
267 |
# Authorized attempt to write invalid data |
281 |
# Authorized attempt to write invalid data |
268 |
my $city_with_invalid_field = { |
282 |
my $city_with_invalid_field = { |
269 |
city_blah => "City Blah", |
283 |
blah => "City Blah", |
270 |
city_state => "City State", |
284 |
state => "City State", |
271 |
city_zipcode => "City Zipcode", |
285 |
postal_code => "City Zipcode", |
272 |
city_country => "City Country" |
286 |
country => "City Country" |
273 |
}; |
287 |
}; |
274 |
|
288 |
|
275 |
$tx = $t->ua->build_tx( |
289 |
$tx = $t->ua->build_tx( PUT => "/api/v1/cities/$city_id" => json => $city_with_invalid_field ); |
276 |
PUT => "/api/v1/cities/$city_id" => json => $city_with_invalid_field ); |
290 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
277 |
$tx->req->cookies( |
291 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
278 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
292 |
$t->request_ok($tx) |
279 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
293 |
->status_is(400) |
280 |
$t->request_ok($tx)->status_is(400)->json_is( |
294 |
->json_is( |
281 |
"/errors" => [ |
295 |
"/errors" => [ |
282 |
{ |
296 |
{ |
283 |
message => "Properties not allowed: city_blah.", |
297 |
message => "Properties not allowed: blah.", |
284 |
path => "/body" |
298 |
path => "/body" |
285 |
} |
299 |
} |
286 |
] |
300 |
] |
287 |
); |
301 |
); |
288 |
|
302 |
|
289 |
my $non_existent_id = $city_id + 1; |
303 |
my $city_to_delete = $builder->build_object({ class => 'Koha::Cities' }); |
290 |
$tx = |
304 |
my $non_existent_id = $city_to_delete->id; |
291 |
$t->ua->build_tx( PUT => "/api/v1/cities/$non_existent_id" => json => |
305 |
$city_to_delete->delete; |
|
|
306 |
|
307 |
$tx = $t->ua->build_tx( PUT => "/api/v1/cities/$non_existent_id" => json => |
292 |
$city_with_updated_field ); |
308 |
$city_with_updated_field ); |
293 |
$tx->req->cookies( |
309 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
294 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
310 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
295 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
311 |
$t->request_ok($tx) |
296 |
$t->request_ok($tx)->status_is(404); |
312 |
->status_is(404); |
297 |
|
313 |
|
298 |
$schema->storage->txn_rollback; |
314 |
$schema->storage->txn_rollback; |
299 |
|
315 |
|
300 |
# Wrong mathod (POST) |
316 |
# Wrong method (POST) |
301 |
$city_with_updated_field->{cityid} = 2; |
317 |
$city_with_updated_field->{city_id} = 2; |
302 |
|
318 |
|
303 |
$tx = $t->ua->build_tx( |
319 |
$tx = $t->ua->build_tx( |
304 |
POST => "/api/v1/cities/$city_id" => json => $city_with_updated_field ); |
320 |
POST => "/api/v1/cities/$city_id" => json => $city_with_updated_field ); |
305 |
$tx->req->cookies( |
321 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
306 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
322 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
307 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
323 |
$t->request_ok($tx) |
308 |
$t->request_ok($tx)->status_is(404); |
324 |
->status_is(404); |
309 |
}; |
325 |
}; |
310 |
|
326 |
|
311 |
subtest 'delete() tests' => sub { |
327 |
subtest 'delete() tests' => sub { |
Lines 319-344
subtest 'delete() tests' => sub {
Link Here
|
319 |
my ( $authorized_borrowernumber, $authorized_session_id ) = |
335 |
my ( $authorized_borrowernumber, $authorized_session_id ) = |
320 |
create_user_and_session( { authorized => 1 } ); |
336 |
create_user_and_session( { authorized => 1 } ); |
321 |
|
337 |
|
322 |
my $city_id = $builder->build( { source => 'City' } )->{cityid}; |
338 |
my $city_id = $builder->build_object({ class => 'Koha::Cities' })->id; |
323 |
|
339 |
|
324 |
# Unauthorized attempt to update |
340 |
# Unauthorized attempt to delete |
325 |
my $tx = $t->ua->build_tx( DELETE => "/api/v1/cities/$city_id" ); |
341 |
my $tx = $t->ua->build_tx( DELETE => "/api/v1/cities/$city_id" ); |
326 |
$tx->req->cookies( |
342 |
$tx->req->cookies({ name => 'CGISESSID', value => $unauthorized_session_id }); |
327 |
{ name => 'CGISESSID', value => $unauthorized_session_id } ); |
343 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
328 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
344 |
$t->request_ok($tx) |
329 |
$t->request_ok($tx)->status_is(403); |
345 |
->status_is(403); |
330 |
|
346 |
|
331 |
$tx = $t->ua->build_tx( DELETE => "/api/v1/cities/$city_id" ); |
347 |
$tx = $t->ua->build_tx( DELETE => "/api/v1/cities/$city_id" ); |
332 |
$tx->req->cookies( |
348 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
333 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
349 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
334 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
350 |
$t->request_ok($tx) |
335 |
$t->request_ok($tx)->status_is(200)->content_is('""'); |
351 |
->status_is(200) |
|
|
352 |
->content_is('""'); |
336 |
|
353 |
|
337 |
$tx = $t->ua->build_tx( DELETE => "/api/v1/cities/$city_id" ); |
354 |
$tx = $t->ua->build_tx( DELETE => "/api/v1/cities/$city_id" ); |
338 |
$tx->req->cookies( |
355 |
$tx->req->cookies({ name => 'CGISESSID', value => $authorized_session_id }); |
339 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
356 |
$tx->req->env({ REMOTE_ADDR => $remote_address }); |
340 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
357 |
$t->request_ok($tx) |
341 |
$t->request_ok($tx)->status_is(404); |
358 |
->status_is(404); |
342 |
|
359 |
|
343 |
$schema->storage->txn_rollback; |
360 |
$schema->storage->txn_rollback; |
344 |
}; |
361 |
}; |
345 |
- |
|
|