| 1 | #!/usr/bin/perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | use Test::RequiresInternet ('a.4cdn.org' => 443, '8ch.net' => 443); |
| 6 | use Test::More tests => 17; |
| 7 | |
| 8 | BEGIN { use_ok('WebService::Vichan', ':all') }; |
| 9 | |
| 10 | my @URLS = (API_4CHAN, API_8CHAN); |
| 11 | |
| 12 | for my $url (@URLS) { |
| 13 | note "Now testing $url"; |
| 14 | my $chan = WebService::Vichan->new($url); |
| 15 | |
| 16 | my @boards = $chan->boards; |
| 17 | ok @boards > 0, 'has boards'; |
| 18 | |
| 19 | my $board = $boards[0]; |
| 20 | my $boardcode = $board->board; |
| 21 | |
| 22 | my @threads = $chan->threads($board); |
| 23 | my @threads_flat = $chan->threads_flat($board); |
| 24 | ok @threads > 0, "board $boardcode has threads"; |
| 25 | |
| 26 | SKIP: { |
| 27 | skip 'race condition', 1 unless $ENV{RELEASE_TESTING}; |
| 28 | my $thread3a = $threads[0]->threads->[2]; |
| 29 | my $thread3b = $threads_flat[2]; |
| 30 | is $thread3a->no, $thread3b->no, 'same 3rd thread in threads and threads_flat'; |
| 31 | } |
| 32 | |
| 33 | my @catalog = $chan->catalog($board); |
| 34 | my @catalog_flat = $chan->catalog_flat($board); |
| 35 | ok @catalog > 0, "catalog of board $boardcode is not empty"; |
| 36 | |
| 37 | SKIP: { |
| 38 | skip 'race condition', 1 unless $ENV{RELEASE_TESTING}; |
| 39 | my $catalog3a = $catalog[0]->threads->[2]; |
| 40 | my $catalog3b = $catalog_flat[2]; |
| 41 | is $catalog3a->no, $catalog3b->no, 'same 3rd thread in catalog and catalog_flat'; |
| 42 | } |
| 43 | |
| 44 | my $catalog3 = $catalog_flat[2]; |
| 45 | my $catalog3no = $catalog3->no; |
| 46 | ok defined $catalog3->com, 'catalog entry has content'; |
| 47 | |
| 48 | my @posts = $chan->thread($board, $catalog3); |
| 49 | ok @posts > 0, "thread $catalog3no has posts"; |
| 50 | |
| 51 | is $catalog3->id, $posts[0]->id, 'catalog entry has same ID as first post'; |
| 52 | } |