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