|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 11; |
20 |
use Test::More tests => 12; |
| 21 |
use Test::Exception; |
21 |
use Test::Exception; |
| 22 |
use Test::Warn; |
22 |
use Test::Warn; |
| 23 |
use DateTime; |
23 |
use DateTime; |
|
Lines 213-218
subtest 'TO_JSON tests' => sub {
Link Here
|
| 213 |
$schema->storage->txn_rollback; |
213 |
$schema->storage->txn_rollback; |
| 214 |
}; |
214 |
}; |
| 215 |
|
215 |
|
|
|
216 |
subtest "to_api() tests" => sub { |
| 217 |
|
| 218 |
plan tests => 11; |
| 219 |
|
| 220 |
$schema->storage->txn_begin; |
| 221 |
|
| 222 |
my $city = $builder->build_object({ class => 'Koha::Cities' }); |
| 223 |
|
| 224 |
# THE mapping |
| 225 |
# cityid => 'city_id', |
| 226 |
# city_country => 'country', |
| 227 |
# city_name => 'name', |
| 228 |
# city_state => 'state', |
| 229 |
# city_zipcode => 'postal_code' |
| 230 |
|
| 231 |
my $api_city = $city->to_api; |
| 232 |
|
| 233 |
is( $api_city->{city_id}, $city->cityid, 'Attribute translated correctly' ); |
| 234 |
is( $api_city->{country}, $city->city_country, 'Attribute translated correctly' ); |
| 235 |
is( $api_city->{name}, $city->city_name, 'Attribute translated correctly' ); |
| 236 |
is( $api_city->{state}, $city->city_state, 'Attribute translated correctly' ); |
| 237 |
is( $api_city->{postal_code}, $city->city_zipcode, 'Attribute translated correctly' ); |
| 238 |
|
| 239 |
# Lets emulate an undef |
| 240 |
my $city_class = Test::MockModule->new('Koha::City'); |
| 241 |
$city_class->mock( 'to_api_mapping', |
| 242 |
sub { |
| 243 |
return { |
| 244 |
cityid => 'city_id', |
| 245 |
city_country => 'country', |
| 246 |
city_name => 'name', |
| 247 |
city_state => 'state', |
| 248 |
city_zipcode => undef |
| 249 |
}; |
| 250 |
} |
| 251 |
); |
| 252 |
|
| 253 |
$api_city = $city->to_api; |
| 254 |
|
| 255 |
is( $api_city->{city_id}, $city->cityid, 'Attribute translated correctly' ); |
| 256 |
is( $api_city->{country}, $city->city_country, 'Attribute translated correctly' ); |
| 257 |
is( $api_city->{name}, $city->city_name, 'Attribute translated correctly' ); |
| 258 |
is( $api_city->{state}, $city->city_state, 'Attribute translated correctly' ); |
| 259 |
ok( !exists $api_city->{postal_code}, 'Attribute removed' ); |
| 260 |
|
| 261 |
# Pick a class that won't have a mapping for the API |
| 262 |
my $illrequest = $builder->build_object({ class => 'Koha::Illrequests' }); |
| 263 |
is_deeply( $illrequest->to_api, $illrequest->TO_JSON, 'If no to_api_method present, return TO_JSON' ); |
| 264 |
|
| 265 |
$schema->storage->txn_rollback; |
| 266 |
}; |
| 267 |
|
| 216 |
subtest "Test update method" => sub { |
268 |
subtest "Test update method" => sub { |
| 217 |
plan tests => 6; |
269 |
plan tests => 6; |
| 218 |
|
270 |
|