pricecharts

track prices of consumer electronics
Log | Files | Refs | README

london_drugs.t (1692B)


      1 use strict;
      2 use PS::UserAgent;
      3 use PS::LondonDrugs;
      4 use Log::Log4perl qw(:easy);
      5 use Test;
      6 
      7 BEGIN { plan tests => 14 }
      8 
      9 Log::Log4perl->easy_init($INFO);
     10 
     11 my $ua = PS::UserAgent->new();
     12 my $ld = PS::LondonDrugs->new();
     13 
     14 #
     15 # Search for a Samsung television I know they have
     16 my $search_url = $ld->create_search("Samsung", "UN55JS9000");
     17 my $resp = $ua->get_dom($search_url);
     18 ok($resp->is_success);
     19 
     20 # Check that the object is working
     21 my ($obj_resp) = $ld->find_product_page($resp);
     22 ok($obj_resp->base, $resp->base);
     23 
     24 # Make sure the part number we scrape is correct
     25 my $part_num = $ld->scrape_part_num($resp);
     26 ok($part_num, "UN55JS9000");
     27 
     28 # Make sure the price we scrape is at least close to correct
     29 my ($price, @others) = $ld->scrape_price($resp);
     30 ok($price);
     31 ok(@others == 0);
     32 ok($price > 2000.0);
     33 ok($price < 3000.0);
     34 
     35 my $descr = $ld->scrape_description($resp);
     36 ok($descr, "Samsung 55\" JS9000 Series SUHD 4K Curved Smart TV");
     37 
     38 #
     39 # Search for something that returns multiple results
     40 my $search_url = $ld->create_search("Samsung", "UN55");
     41 my $resp = $ua->get_dom($search_url);
     42 ok($resp->is_success);
     43 
     44 # Searching for the above product yields multiple results.
     45 my ($obj_resp, @others) = $ld->find_product_page($resp);
     46 ok(@others, 6);
     47 ok($obj_resp->is_success);
     48 
     49 #
     50 # Search for something non existent
     51 my $search_url = $ld->create_search("", "some product that for sure doesnot exist");
     52 $resp = $ua->get_dom($search_url);
     53 ok($resp->is_success);
     54 
     55 #ok($resp->base =~ /.*\/Search\/.*/);
     56 
     57 my ($obj_resp) = $ld->find_product_page($resp);
     58 ok( !defined $obj_resp );
     59 
     60 # Check we get the no results found error
     61 ok( $resp->decoded_content,
     62     "/We're sorry, no products were found for your search/");