File: error.t

package info (click to toggle)
libtwitter-api-perl 1.0006-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 424 kB
  • sloc: perl: 2,868; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,289 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!perl
use 5.14.1;
use warnings;
use HTTP::Response;
use Test::Spec;
use Twitter::API::Context;
use Twitter::API::Error;

sub construct_error {
    my ( $http_status_code, $twitter_error_code, $twitter_error_text ) = @_;

    my $http_response = HTTP::Response->new($http_status_code);
    my $result = {
        errors => [
            { code => $twitter_error_code, message => $twitter_error_text },
        ]
    } if defined $twitter_error_code;
    my $context = Twitter::API::Context->new(
        http_response => $http_response,
        $result ? ( result => $result ) : (),
    );
    return Twitter::API::Error->new(context => $context);
}

describe 'Twitter::API::Error' => sub {
    it 'is always true' => sub {
        ok !!construct_error(0);
    };

    describe is_token_error => sub {
        for my $code ( 32, 64, 88, 89, 99, 135, 136, 215, 226, 326 ) {
            it "recognizes $code as a token error" => sub {
                ok construct_error(400, $code)->is_token_error;
            };
        }
    };

    describe is_token_error => sub {
        for my $code ( 34, 50, 63, 144 ) {
            it "does not recognize $code as a token error" => sub {
                ok !construct_error(400, $code)->is_token_error;
            };
        }
    };
};

runtests;