Lines 129-135
subtest 'get() tests' => sub {
Link Here
|
129 |
|
129 |
|
130 |
subtest 'add() tests' => sub { |
130 |
subtest 'add() tests' => sub { |
131 |
|
131 |
|
132 |
plan tests => 11; |
132 |
plan tests => 17; |
133 |
|
133 |
|
134 |
$schema->storage->txn_begin; |
134 |
$schema->storage->txn_begin; |
135 |
|
135 |
|
Lines 151-167
subtest 'add() tests' => sub {
Link Here
|
151 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
151 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
152 |
$t->request_ok($tx)->status_is(403); |
152 |
$t->request_ok($tx)->status_is(403); |
153 |
|
153 |
|
154 |
# Authorized attempt to write |
|
|
155 |
$tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city ); |
156 |
$tx->req->cookies( |
157 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
158 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
159 |
$t->request_ok($tx)->status_is(200) |
160 |
->json_is( '/city_name' => $city->{city_name} ) |
161 |
->json_is( '/city_state' => $city->{city_state} ) |
162 |
->json_is( '/city_zipcode' => $city->{city_zipcode} ) |
163 |
->json_is( '/city_country' => $city->{city_country} ); |
164 |
|
165 |
# Authorized attempt to write invalid data |
154 |
# Authorized attempt to write invalid data |
166 |
my $city_with_invalid_field = { |
155 |
my $city_with_invalid_field = { |
167 |
city_blah => "City Blah", |
156 |
city_blah => "City Blah", |
Lines 184-195
subtest 'add() tests' => sub {
Link Here
|
184 |
] |
173 |
] |
185 |
); |
174 |
); |
186 |
|
175 |
|
|
|
176 |
# Authorized attempt to write |
177 |
$tx = $t->ua->build_tx( POST => "/api/v1/cities/" => json => $city ); |
178 |
$tx->req->cookies( |
179 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
180 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
181 |
my $cityid = $t->request_ok($tx)->status_is(200) |
182 |
->json_is( '/city_name' => $city->{city_name} ) |
183 |
->json_is( '/city_state' => $city->{city_state} ) |
184 |
->json_is( '/city_zipcode' => $city->{city_zipcode} ) |
185 |
->json_is( '/city_country' => $city->{city_country} ) |
186 |
->tx->res->json->{cityid}; |
187 |
|
188 |
# Authorized attempt to create with null id |
189 |
$city->{cityid} = undef; |
190 |
$tx = $t->ua->build_tx( |
191 |
POST => "/api/v1/cities/" => json => $city ); |
192 |
$tx->req->cookies( |
193 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
194 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
195 |
$t->request_ok($tx)->status_is(400)->json_is( |
196 |
"/errors" => [ |
197 |
{ |
198 |
message => "Read-only.", |
199 |
path => "/body/cityid" |
200 |
} |
201 |
] |
202 |
); |
203 |
|
204 |
# Authorized attempt to create with existing id |
205 |
$city->{cityid} = $cityid; |
206 |
$tx = $t->ua->build_tx( |
207 |
POST => "/api/v1/cities/" => json => $city ); |
208 |
$tx->req->cookies( |
209 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
210 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
211 |
$t->request_ok($tx)->status_is(400)->json_is( |
212 |
"/errors" => [ |
213 |
{ |
214 |
message => "Read-only.", |
215 |
path => "/body/cityid" |
216 |
} |
217 |
] |
218 |
); |
219 |
|
187 |
$schema->storage->txn_rollback; |
220 |
$schema->storage->txn_rollback; |
188 |
}; |
221 |
}; |
189 |
|
222 |
|
190 |
subtest 'update() tests' => sub { |
223 |
subtest 'update() tests' => sub { |
191 |
|
224 |
|
192 |
plan tests => 13; |
225 |
plan tests => 15; |
193 |
|
226 |
|
194 |
$schema->storage->txn_begin; |
227 |
$schema->storage->txn_begin; |
195 |
|
228 |
|
Lines 272-277
subtest 'update() tests' => sub {
Link Here
|
272 |
$t->request_ok($tx)->status_is(404); |
305 |
$t->request_ok($tx)->status_is(404); |
273 |
|
306 |
|
274 |
$schema->storage->txn_rollback; |
307 |
$schema->storage->txn_rollback; |
|
|
308 |
|
309 |
# Wrong mathod (POST) |
310 |
$city_with_updated_field->{cityid} = 2; |
311 |
|
312 |
$tx = $t->ua->build_tx( |
313 |
POST => "/api/v1/cities/$city_id" => json => $city_with_updated_field ); |
314 |
$tx->req->cookies( |
315 |
{ name => 'CGISESSID', value => $authorized_session_id } ); |
316 |
$tx->req->env( { REMOTE_ADDR => $remote_address } ); |
317 |
$t->request_ok($tx)->status_is(404); |
275 |
}; |
318 |
}; |
276 |
|
319 |
|
277 |
subtest 'delete() tests' => sub { |
320 |
subtest 'delete() tests' => sub { |
278 |
- |
|
|