File: Insights.t

package info (click to toggle)
libgeoip2-perl 2.006002-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,156 kB
  • sloc: perl: 2,275; makefile: 10
file content (111 lines) | stat: -rw-r--r-- 3,156 bytes parent folder | download | duplicates (3)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use strict;
use warnings;

use lib 't/lib';

use Test::GeoIP2 qw(
    test_model_class
    test_model_class_with_empty_record
    test_model_class_with_unknown_keys
);
use Test::More 0.88;

use GeoIP2::Model::Insights;

{
    my %raw = (
        city => {
            confidence => 76,
            geoname_id => 9876,
            names      => { en => 'Minneapolis' },
        },
        continent => {
            code       => 'NA',
            geoname_id => 42,
            names      => { en => 'North America' },
        },
        country => {
            confidence => 99,
            geoname_id => 1,
            iso_code   => 'US',
            names      => {
                'de'    => 'Nordamerika',
                'en'    => 'North America',
                'es'    => 'América del Norte',
                'fr'    => 'Amérique du Nord',
                'ja'    => '北アメリカ',
                'pt-BR' => 'América do Norte',
                'ru'    => 'Северная Америка',
                'zh-CN' => '北美洲',
            },
        },
        location => {
            average_income     => 12345,
            accuracy_radius    => 1500,
            latitude           => 44.98,
            longitude          => 93.2636,
            metro_code         => 765,
            population_density => 45678,
            time_zone          => 'America/Chicago',
        },
        maxmind => {
            queries_remaining => 42,
        },
        postal => {
            code       => '12345',
            confidence => 57,
        },
        registered_country => {
            geoname_id => 2,
            iso_code   => 'CA',
            names      => { en => 'Canada' },
        },
        represented_country => {
            geoname_id => 3,
            iso_code   => 'GB',
            names      => { en => 'United Kingdom' },
        },
        subdivisions => [
            {
                confidence => 88,
                geoname_id => 574635,
                iso_code   => 'MN',
                names      => { en => 'Minnesota' },
            },
        ],
        traits => {
            autonomous_system_number       => 1234,
            autonomous_system_organization => 'AS Organization',
            domain                         => 'example.com',
            ip_address                     => '1.2.3.4',
            is_satellite_provider          => 1,
            isp                            => 'Comcast',
            organization                   => 'Blorg',
            user_type                      => 'college',
        },
    );

    test_model_class(
        'GeoIP2::Model::Insights',
        \%raw,
        sub {
            my $model = shift;

            is(
                $model->location->average_income, 12345,
                'check average_income',
            );
            is(
                $model->location->population_density, 45678,
                'check population_density',
            );
        },
    );
}

{
    test_model_class_with_empty_record('GeoIP2::Model::Insights');
    test_model_class_with_unknown_keys('GeoIP2::Model::Insights');
}

done_testing();