diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 983eea6..27392f0 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -1081,6 +1081,8 @@ Arguments: A hash reference, the following keys are considered, and are "anded" together -- in that the donor sought must have all these criteria to be found. +If no criteria are given, all donors are returned. + =over =item emailAddress @@ -1104,8 +1106,11 @@ Returns a list of donorIds that meets the criteria, or none if not found. sub findDonor($$) { my($self, $params) = @_; - die "findDonor: no search criteria given" - unless defined $params->{ledgerEntityId} or defined $params->{emailAddress}; + + unless (defined $params->{ledgerEntityId} or defined $params->{emailAddress}) { + my $rr = $self->dbh()->selectall_hashref("SELECT id FROM donor", 'id'); + return keys %$rr; + } my @donorIds; if (not defined $params->{emailAddress}) { diff --git a/Supporters/t/Supporters.t b/Supporters/t/Supporters.t index 78ecc27..2eefad3 100644 --- a/Supporters/t/Supporters.t +++ b/Supporters/t/Supporters.t @@ -8,7 +8,7 @@ use strict; use warnings; -use Test::More tests => 259; +use Test::More tests => 260; use Test::Exception; use Sub::Override; use File::Temp qw/tempfile/; @@ -692,8 +692,15 @@ is($ret, 'drapper@example.org', "getPreferredEmailAddress: ....and returns the c my @lookupDonorIds; -dies_ok { @lookupDonorIds = $sp->findDonor({}); } - "findDonor: no search criteria dies"; +lives_ok { @lookupDonorIds = $sp->findDonor({}); } + "findDonor: no search criteria succeeds and..."; + +my(%vals); +@vals{@lookupDonorIds} = @lookupDonorIds; + +is_deeply(\%vals, { $campbellId => $campbellId, $sterlingId => $sterlingId, + $olsonId => $olsonId, $drapperId => $drapperId }, + "findDonor: ... and returns all donorIds."); lives_ok { @lookupDonorIds = $sp->findDonor({ledgerEntityId => "NotFound" }); } "findDonor: 1 lookup of known missing succeeds ..."; @@ -733,7 +740,7 @@ is_deeply(\@lookupDonorIds, [$olsonId], "findDonor: ... and finds right entry.") lives_ok { @lookupDonorIds = $sp->findDonor({emailAddress => 'everyone@example.net'}); } "findDonor: single criteria find expecting multiple records succeeds..."; -my(%vals); +%vals = (); @vals{@lookupDonorIds} = @lookupDonorIds; is_deeply(\%vals, { $olsonId => $olsonId, $drapperId => $drapperId }, "findDonor: ... and finds the right entires.");