supporterExpirationDate: fix reverse sort bug.

These two new tests:
  ok 222 - supporterExpirationDate(): same donation amount in year...
  ok 223 - supporterExpirationDate(): ...returns the latter date.

did not pass without this change.  The list for annuals in
supporterExpirationDate() was sorted in the wrong order, producing
erroneous results.
This commit is contained in:
Bradley M. Kuhn 2015-12-30 21:26:48 -08:00
parent dbeb98d0f2
commit 39faafcab6
2 changed files with 17 additions and 3 deletions

View file

@ -1286,7 +1286,7 @@ sub supporterExpirationDate($$) {
} elsif ($type eq 'Annual') {
my($earliest, $total) = (undef, 0.00);
foreach my $date (sort { $a cmp $ b} keys %{$self->{ledgerData}{$entityId}{donations}}) {
foreach my $date (sort { $b cmp $a} keys %{$self->{ledgerData}{$entityId}{donations}}) {
next if $date =~ /^__/;
$total += $self->{ledgerData}{$entityId}{donations}{$date};
unless ($total < 120.00) {

View file

@ -8,7 +8,7 @@
use strict;
use warnings;
use Test::More tests => 260;
use Test::More tests => 264;
use Test::Exception;
use Sub::Override;
use File::Temp qw/tempfile/;
@ -46,10 +46,12 @@ Supporters:Annual 2015-05-04 Whitman-Dick \$-5.00
Supporters:Monthly 2015-05-25 Olson-Margaret \$-10.00
Supporters:Monthly 2015-01-15 Olson-Margaret \$-10.00
Supporters:Monthly 2015-03-17 Olson-Margaret \$-10.00
Supporters:Annual 2015-12-04 Harris-Joan \$-120.00
Supporters:Monthly 2015-04-20 Olson-Margaret \$-10.00
Supporters:Match Pledge 2015-02-26 Whitman-Dick \$-300.00
Supporters:Monthly 2015-02-16 Olson-Margaret \$-10.00
Supporters:Monthly 2015-06-30 Olson-Margaret \$-10.00
Supporters:Annual 2015-03-04 Harris-Joan \$-120.00
FAKE_LEDGER_TEST_DATA_END
=item Public-facing methods of the module, as follows:
@ -146,6 +148,14 @@ lives_ok { $sterlingId = $sp->addSupporter({ display_name => "Roger Sterling",
ok( (looks_like_number($sterlingId) and $sterlingId > $olsonId),
"addSupporter: ... and return value is sane.");
my $harrisId;
lives_ok { $harrisId = $sp->addSupporter({ ledger_entity_id => 'Harris-Joan' }) }
"addSupporter: set up one more in db (use this one for future test types on addSupporter)...";
ok( (looks_like_number($harrisId) and $harrisId > $sterlingId),
"addSupporter: ... and return value is sane.");
=item getPublicAck
=cut
@ -698,7 +708,7 @@ lives_ok { @lookupDonorIds = $sp->findDonor({}); }
my(%vals);
@vals{@lookupDonorIds} = @lookupDonorIds;
is_deeply(\%vals, { $campbellId => $campbellId, $sterlingId => $sterlingId,
is_deeply(\%vals, { $campbellId => $campbellId, $sterlingId => $sterlingId, $harrisId => $harrisId,
$olsonId => $olsonId, $drapperId => $drapperId },
"findDonor: ... and returns all donorIds.");
@ -802,6 +812,10 @@ lives_ok { $date = $sp->supporterExpirationDate($sterlingId) } "supporterExpirat
is($date, undef, "supporterExpirationDate(): ...and returned undef.");
lives_ok { $date = $sp->supporterExpirationDate($harrisId) } "supporterExpirationDate(): same donation amount in year...";
is($date, '2016-12-04', "supporterExpirationDate(): ...returns the latter date.");
$dbh->do("UPDATE donor SET is_supporter = 0 WHERE id = " . $sp->dbh->quote($campbellId));
lives_ok { $date = $sp->supporterExpirationDate($campbellId) } "supporterExpirationDate(): check for no supporter success...";