1#!/usr/bin/perl -w
2use strict;
3use Test::More;
4use Finance::Quote;
5
6use constant DEBUG => $ENV{DEBUG};
7use if DEBUG, 'Smart::Comments';
8
9if (not $ENV{ONLINE_TEST}) {
10    plan skip_all => 'Set $ENV{ONLINE_TEST} to run this test';
11}
12
13plan tests => 25;
14
15# Test Fidelity functions.
16
17my $q      = Finance::Quote->new();
18my @funds = qw/FGRIX FNMIX FASGX/;
19my $year = (localtime())[5] + 1900;
20my $lastyear = $year - 1;
21
22my %quotes = $q->fidelity_direct(@funds);
23ok(%quotes);
24
25### quotes : %quotes
26
27# Check that the name and nav are defined for all of the funds.
28foreach my $fund (@funds) {
29    ok($quotes{$fund,"nav"} > 0);
30    ok(length($quotes{$fund,"name"}));
31    ok($quotes{$fund,"success"});
32    ok($quotes{$fund, "currency"} eq "USD");
33    ok(substr($quotes{$fund,"isodate"},0,4) == $year ||
34           substr($quotes{$fund,"isodate"},0,4) == $lastyear);
35    ok(substr($quotes{$fund,"date"},6,4) == $year ||
36           substr($quotes{$fund,"date"},6,4) == $lastyear);
37}
38
39# Some funds have yields instead of navs.  Check one of them too.
40%quotes = $q->fidelity_direct("FEQTX");
41ok(%quotes);
42ok(length($quotes{"FEQTX","name"}));
43ok($quotes{"FEQTX","yield"} > 0);
44ok($quotes{"FEQTX","success"});
45ok($quotes{"FEQTX", "currency"} eq "USD");
46
47# Check that a bogus fund returns no-success.
48%quotes = $q->fidelity_direct("BOGUS");
49ok(! $quotes{"BOGUS","success"});
50
51