best_buy.t (1514B)
1 use strict; 2 use PS::BestBuy; 3 use Log::Log4perl qw(:easy); 4 use Test; 5 6 BEGIN { plan tests => 13 } 7 8 Log::Log4perl->easy_init($INFO); 9 10 my $ua = PS::UserAgent->new(); 11 my $bb = PS::BestBuy->new(); 12 13 # 14 # Search for a Samsung television I know they have 15 my $search_url = $bb->create_search("Samsung", "UN55JS8500FXZC"); 16 my $resp = $ua->get_dom($search_url); 17 ok($resp->is_success); 18 19 # Check that the object is working 20 my ($obj_resp) = $bb->find_product_page($resp); 21 ok($obj_resp->base, $resp->base); 22 23 # Make sure the part number we scrape is correct 24 my $part_num = $bb->scrape_part_num($resp); 25 ok($part_num, "UN55JS8500FXZC"); 26 27 # Make sure the price we scrape is at least close to correct 28 my $price = $bb->scrape_price($resp); 29 ok($price); 30 ok($price > 2000.0); 31 ok($price < 2400.0); 32 33 my $descr = $bb->scrape_description($resp); 34 ok($descr, "Samsung 55\" 4K Ultra HD 3D LED Tizen Smart OS TV"); 35 36 # 37 # Search for something that returns multiple results 38 my $search_url = $bb->create_search("Samsung", "UN55"); 39 $resp = $ua->get_dom($search_url); 40 ok($resp->is_success); 41 42 my ($obj_resp, @others) = $bb->find_product_page($resp); 43 ok(@others, 10); 44 ok($obj_resp->is_success); 45 46 # 47 # Search for something non existent 48 my $search_url = $bb->create_search("", "some non-existent product name"); 49 $resp = $ua->get_dom($search_url); 50 ok($resp->is_success); 51 52 my ($obj_resp) = $bb->find_product_page($resp); 53 ok( !defined $obj_resp ); 54 55 # Check we get the no results found error 56 ok( $resp->decoded_content, "/Sorry, we couldn.t find any results./");