res.t (2452B)
1 use strict; 2 use Test::More; 3 use JSON; 4 5 BEGIN { 6 use_ok('Rarbg::torrentapi::Res'); 7 } 8 9 # Testing Rarbg::torrentapi::Res methods and attributes 10 can_ok( 'Rarbg::torrentapi::Res', ('new') ); 11 can_ok( 'Rarbg::torrentapi::Res', 12 qw( category download info_page pubdate title) ); 13 can_ok( 'Rarbg::torrentapi::Res', qw( seeders leechers ranked size) ); 14 can_ok( 'Rarbg::torrentapi::Res', ('episode_info') ); 15 my $res_msg = <<RES; 16 { 17 "category": "TV Episodes", 18 "download": "magnet:?xt=urn:btih:edbd27c890411a5e5659e9ae0daf631edc2d8ab7&dn=Star.Wars.Rebels.S01E13.HDTV.x264-BATV%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce", 19 "episode_info": { 20 "airdate": "2015-03-02", 21 "epnum": "13", 22 "imdb": "tt2930604", 23 "seasonnum": "1", 24 "title": "Fire Across the Galaxy", 25 "tvdb": "283468", 26 "tvrage": "35995" 27 }, 28 "info_page": "https://torrentapi.org/redirect_to_info.php?token=d6fpv3lrij&p=8_0_4_9_2_2__edbd27c890", 29 "leechers": 0, 30 "pubdate": "2015-03-03 02:33:40 +0000", 31 "ranked": 1, 32 "seeders": 0, 33 "size": 188491315, 34 "title": "Star.Wars.Rebels.S01E13.HDTV.x264-BATV[rartv]" 35 } 36 RES 37 my $res_res = decode_json($res_msg); 38 my $res = Rarbg::torrentapi::Res->new($res_res); 39 40 ok( $res->size == 188491315, 'Response int value test' ); 41 is( 42 $res->title, 43 'Star.Wars.Rebels.S01E13.HDTV.x264-BATV[rartv]', 44 'Response String value test' 45 ); 46 isa_ok( $res->episode_info, 'HASH' ); 47 is( $res->episode_info->{imdb}, 'tt2930604', 'Episode info hash test' ); 48 49 # sometimes episode_info and title can be null 50 $res_msg = <<RES; 51 { 52 "title": null, 53 "category": "TV HD Episodes", 54 "download": "magnet-link-here", 55 "seeders": 10, 56 "leechers": 0, 57 "size": 1061306416, 58 "pubdate": "2015-07-31 14:01:18 +0000", 59 "episode_info": null, 60 "ranked": 0, 61 "info_page": "https://torrentapi.org/redirect_to_info.php?token=tok&p=foo" 62 } 63 RES 64 $res_res = decode_json($res_msg); 65 $res = Rarbg::torrentapi::Res->new($res_res); 66 67 is( $res->title, undef, 'Title info undef' ); 68 is( $res->episode_info, undef, 'Episode info undef' ); 69 70 done_testing;