Update 02_store_api.t

This commit is contained in:
dvz5 2015-11-01 23:14:22 +01:00
parent 2e03ecc4b8
commit 08f424824c

View File

@ -1,4 +1,4 @@
use Test::More tests => 22;
use Test::More tests => 42;
use Test::Exception;
use lib 'lib';
@ -12,6 +12,8 @@ use_ok('WWW::SwaggerClient::ApiClient');
use_ok('WWW::SwaggerClient::Object::Pet');
use_ok('WWW::SwaggerClient::Object::Tag');
use_ok('WWW::SwaggerClient::Object::Category');
use_ok('WWW::SwaggerClient::Object::User');
my $api_client = WWW::SwaggerClient::ApiClient->new();
my $store_api = WWW::SwaggerClient::StoreApi->new('api_client' => $api_client);
@ -53,6 +55,7 @@ is $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{category}->{
is ref $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{category}, "WWW::SwaggerClient::Object::Category", "get the Category the Pet object";
is ref $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{tags}[0], "WWW::SwaggerClient::Object::Tag", "get the Tag of the Pet object";
is $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{tags}[0]->{name}, "tag string", "get the Tag name of the Pet object";
is $api_client->deserialize("HASH[string,Pet]", $pet_json)->{pet}->{photo_urls}->[0], "string", "get the photoUrl from the Pet object";
my $array_json = <<JSON;
[
@ -84,5 +87,59 @@ is $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{category}->{name},
is ref $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{category}, "WWW::SwaggerClient::Object::Category", "get the Category the Pet object";
is ref $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{tags}->[0], "WWW::SwaggerClient::Object::Tag", "get the Tag[0] the Pet object";
is $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{tags}->[0]->{name}, "tag string", "get the tag name the Pet object";
is $api_client->deserialize("ARRAY[Pet]", $array_json)->[0]->{photo_urls}->[0], "string", "get the photoUrl from the Pet object";
my $pet_json_nopet = <<JSON;
{
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "tag string"
}
],
"status": "available"
}
JSON
is ref(decode_json $pet_json_nopet), "HASH", "the decoded json string is a hash";
is ref $api_client->deserialize("Pet", $pet_json_nopet), "WWW::SwaggerClient::Object::Pet", "get Pet object via from_hash()";
is $api_client->deserialize("Pet", $pet_json_nopet)->{name}, "doggie", "get the name of the Pet object";
is $api_client->deserialize("Pet", $pet_json_nopet)->{category}->{name}, "string", "get the category name of the Pet object";
is ref $api_client->deserialize("Pet", $pet_json_nopet)->{category}, "WWW::SwaggerClient::Object::Category", "get the Category the Pet object";
is ref $api_client->deserialize("Pet", $pet_json_nopet)->{tags}->[0], "WWW::SwaggerClient::Object::Tag", "get the Tag[0] the Pet object";
is $api_client->deserialize("Pet", $pet_json_nopet)->{tags}->[0]->{name}, "tag string", "get the tag name the Pet object";
is $api_client->deserialize("Pet", $pet_json_nopet)->{photo_urls}->[0], "string", "get the photoUrl from the Pet object";
my %userdata = (
id => 4000,
username => "tony",
firstName => "Tony",
lastName => "Tiger",
email => 'tony@fail.com',
password => "XXXXXXXXXXX",
phone => "408-867-5309",
userStatus => 1,
);
my $user = WWW::SwaggerClient::Object::User->new->from_hash(\%userdata);
is ref $user, 'WWW::SwaggerClient::Object::User', "built a User object via from_hash()";
is $user->{id}, $userdata{id}, "got the id of the User object";
is $user->{username}, $userdata{username}, "got the username of the User object";
is $user->{first_name}, $userdata{firstName}, "got the firstName of the User object";
is $user->{last_name}, $userdata{lastName}, "got the lastName of the User object";
is $user->{email}, $userdata{email}, "got the email of the User object";
is $user->{password}, $userdata{password}, "got the password of the User object";
is $user->{phone}, $userdata{phone}, "got the phone of the User object";
is $user->{user_status}, $userdata{userStatus}, "got the userStatus of the User object";