Finance-Bank-SentinelBenefits-Csv401kConverter

 view release on metacpan or  search on metacpan

t/lineparser.t  view on Meta::CPAN

use Test::More tests => 83;
use lib './lib';
use DateTime;
use Modern::Perl;

diag( 'Loading line parser' );
use_ok( 'Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser' );

my %symbol_hash = (
    'Micro-organism Investment Value Fund' => 'ALGAE',
    'Blue Bank Fund - Class A' => 'BLUEF',
    'Green Bank Intl Equity' => 'GREEN',
    'Red Bank Bond Fund' => 'REDFU',
    'Purple Bank LLC Fund' => 'GOPIP',
    'GNU Privacy Fund' => 'GNUPG',
    'Bank of Perl Stock Fund' => 'IAAEA',
    'Jam and Jelly Commodity Fund Class A' => 'GRAPE',
    'Legal Industry ETF' => 'IANAL',
    );

my $symbol_map = Finance::Bank::SentinelBenefits::Csv401kConverter::SymbolMap->new( symbol_map => \%symbol_hash );

####
#Sample data
####
my $header_line = 'Date & Source of Money,Status,Details,Units,Price,Dollars,Redemption Fee';
my $date_line = '11/02/09';
my $symbol_line = 'Employer Matching Contribution,Settled,Match of $8.13 to Foobar Dividend Portfolio - ALGAEMicro-organism Investment Value Fund.,2.67,4.17,11.1339,0';
my $no_symbol_line = 'Employer Matching Contribution,Settled,Match of $16.67 to Blue Bank Fund - Class A.,1.65,6.53,10.7745,0';
my $deferral_line = 'Employee 401k Contribution,Settled,Deferral of $10.83 to Foobar Dividend Portfolio - GOPIPPurple Bank LLC Fund.,2.21,1.46,3.2266,0';
my $buy_line = 'Employee 401k Contribution,Settled,Buy Foobar Portfolio - GOPIPPurple Bank LLC Fund.(Dollar certain),2.21,1.46,3.2266,0';
my $sell_line = 'Employer Matching Contribution,Settled,Sell Foobar Portfolio - GOPIPPurple Bank LLC Fund.(Unit certain),-2.21,1.46,-$3.2266,0';
my $div_line = 'Employee 401k Contribution,Settled,Gain/Loss of of $0.11 to Foobar Portfolio - GOPIPPurple Bank LLC Fund.,0.001,133.49,0.11,0';
my $div_match_line = 'Employer Matching Contribution,Settled,Gain/Loss of of $0.17 to Foobar Portfolio - GOPIPPurple Bank LLC Fund.,0.006,28.04,0.17,0';
my $div_line_true = 'Employee 401k Contribution,Settled,Dividend of of $0.11 to Foobar Portfolio - GOPIPPurple Bank LLC Fund.,0.001,133.49,0.11,0';
my $div_match_line_true = 'Employer Matching Contribution,Settled,Dividend of of $0.17 to Foobar Portfolio - GOPIPPurple Bank LLC Fund.,0.006,28.04,0.17,0';

my $line_parser = Finance::Bank::SentinelBenefits::Csv401kConverter::LineParser->new( symbol_map => $symbol_map );

my $date = DateTime->new( year   => 1964,
                          month  => 10,
                          day    => 16,
    );

diag( 'testing invalid lines' );

is( $line_parser->parse_line($header_line, $date), undef, 'Header line should return undef');

is( $line_parser->parse_line($date_line, $date), undef, 'Date line should return undef');

diag( 'testing valid lines - matching contribution, without symbol' );

{
    my $line = $line_parser->parse_line($no_symbol_line, $date);
    is( $line->date()->subtract_datetime( $date )->seconds, 0, 'Datetime on line should match input datetime' );
    is( $line->symbol(), 'BLUEF', 'Symbol should be picked up from the map' );
    is( $line->memo(), 'Match of $16.67 to Blue Bank Fund - Class A.' );
    is( $line->quantity(), 1.65 );
    is( $line->price(), 6.53 );
    is( $line->total(), 10.7745 );
    is( $line->source(), 'Match', 'This should be picked up as a match transaction' );
    is( $line->side(), 'Buy', 'We are buying here' );
}



( run in 0.841 second using v1.01-cache-2.11-cpan-364913b4093 )