getLedgerEntityId: tests showing basic API & docs

These tests show the basic API for the getLedgerEntityId() method.

Documentation for the method also included.
This commit is contained in:
Bradley M. Kuhn 2015-12-30 11:30:22 -08:00
parent 2e9938738f
commit 0ca9d394e2
3 changed files with 49 additions and 2 deletions

View file

@ -5,7 +5,7 @@ use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Supporters',
VERSION_FROM => 'lib/Supporters.pm', # finds $VERSION, requires EU::MM from perl >= 5.5
PREREQ_PM => { DBI => 1.6, 'Test::Exception' => 0.35, 'Mail::RFC822::Address' => 0.3 },
PREREQ_PM => { DBI => 1.6, 'Sub::Override' => 0.09, 'Test::Exception' => 0.35, 'Mail::RFC822::Address' => 0.3 },
ABSTRACT_FROM => 'lib/Supporters.pm', # retrieve abstract from module
AUTHOR => 'Bradley M. Kuhn <bkuhn@ebb.org>',
LICENSE => 'agpl_3',

View file

@ -359,6 +359,28 @@ sub getPreferredEmailAddress($$) {
return $emailAddress;
}
}
######################################################################
=begin getLedgerEntityId
Arguments:
=over
=item $donorId
Valid donor id number currently in the database. die() will occur if
the id number is not in the database already as a donor id.
=back
Returns the ledger_entity_id of the donor. Since the method die()s for an
invalid donor id, undef should never be returned and callers need not test
for it.
=cut
######################################################################
=begin addPostalAddress

View file

@ -8,8 +8,9 @@
use strict;
use warnings;
use Test::More tests => 189;
use Test::More tests => 193;
use Test::Exception;
use Sub::Override;
use Scalar::Util qw(looks_like_number reftype);
use POSIX qw(strftime);
@ -105,6 +106,26 @@ ok((defined $val and defined $val->{$olsonId}{email_address_id} and $val->{$olso
my $olsonFirstEmailId = $val->{$olsonId}{email_address_id};
=item getLedgerEntityId
=cut
dies_ok { my $ledgerId = $sp->getLedgerEntityId(0); }
"getLedgerEntityId: fails when rows are not returned but _verifyId() somehow passed";
# Replace _verifyId() to always return true
my $overrideSub = Sub::Override->new( 'Supporters::_verifyId' => sub ($$) { return 1;} );
dies_ok { my $ledgerId = $sp->getLedgerEntityId(0); }
"getLedgerEntityId: fails when rows are not returned but _verifyId() somehow passed";
$overrideSub->restore;
my $olsonLedgerEntity;
lives_ok { $olsonLedgerEntity = $sp->getLedgerEntityId($olsonId); }
"getLedgerEntityId: lives when valid id is given...";
is($olsonLedgerEntity, "Olson-Margaret", "getLedgerEntityId: ...and return value is correct.");
=item addEmailAddress
=cut
@ -736,6 +757,7 @@ dies_ok { $tempSP->addSupporter({ display_name => "Roger Sterling",
email_address_type => 'home' }) }
"addSupporter: dies when email_address table does not exist & email adress given";
$tempDBH->disconnect; $tempDBH = reopen_test_dbh();
$val = $tempDBH->selectall_hashref("SELECT id FROM donor;", 'id');
@ -743,6 +765,9 @@ $val = $tempDBH->selectall_hashref("SELECT id FROM donor;", 'id');
ok( (defined $val and reftype $val eq "HASH" and keys(%{$val}) == 0),
"addSupporter: fails if email_address given but email cannot be inserted");
$tempDBH->disconnect; $tempDBH = reopen_test_dbh();
=back