From 39faafcab6e0f36030e501f3c28c4c14ef2ddfd5 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Wed, 30 Dec 2015 21:26:48 -0800 Subject: [PATCH] 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. --- Supporters/lib/Supporters.pm | 2 +- Supporters/t/Supporters.t | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 27392f0..8aafc07 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -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) { diff --git a/Supporters/t/Supporters.t b/Supporters/t/Supporters.t index 2eefad3..0b5dd99 100644 --- a/Supporters/t/Supporters.t +++ b/Supporters/t/Supporters.t @@ -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...";