Commit graph

132 commits

Author SHA1 Message Date
Bradley M. Kuhn
990fa89f1d _getDonorField: generalize code for donor fields
This method can be used for a one-liner for any field in the donor
table.

Used it to implement getLedgerEntityId and getPublicAck.
2015-12-30 17:03:07 -08:00
Bradley M. Kuhn
ec7e50e8e0 getPublicAck: initial tests spec out API. 2015-12-30 16:51:04 -08:00
Bradley M. Kuhn
195732b6b0 confess is better here than die.
Maybe I should use it throughout?
2015-12-30 16:09:59 -08:00
Bradley M. Kuhn
724cb77605 new: additional arguments related to ledger.
I'll need a full command line here, as it turns out, and also regular
expressions to use for searching for monthly vs. annual donations.
2015-12-30 12:08:33 -08:00
Bradley M. Kuhn
2e14c340ec getLedgerEntityId: Initial implementation.
All tests now pass:

ok 15 - getLedgerEntityId: fails when rows are not returned but _verifyId() somehow passed
ok 16 - getLedgerEntityId: fails when rows are not returned but _verifyId() somehow passed
ok 17 - getLedgerEntityId: lives when valid id is given...
ok 18 - getLedgerEntityId: ...and return value is correct.
2015-12-30 11:31:36 -08:00
Bradley M. Kuhn
0ca9d394e2 getLedgerEntityId: tests showing basic API & docs
These tests show the basic API for the getLedgerEntityId() method.

Documentation for the method also included.
2015-12-30 11:31:09 -08:00
Bradley M. Kuhn
2e9938738f Add license notice at top of these files. 2015-12-30 11:09:47 -08:00
Bradley M. Kuhn
cb38348048 findDonor: initial implementation.
This seems to work and all existing tests for it pass:

ok 134 - findDonor: no search criteria dies
ok 135 - findDonor: 1 lookup of known missing succeeds ...
ok 136 - findDonor: ... but finds nothing.
ok 137 - findDonor: 2 lookup of known missing succeeds ...
ok 138 - findDonor: ... but finds nothing.
ok 139 - findDonor: 1 and'ed criteria succeeds   ...
ok 140 - findDonor: ... but finds nothing.
ok 141 - findDonor: 2 and'ed criteria succeeds   ...
ok 142 - findDonor: ... but finds nothing.
ok 143 - findDonor: 1 valid multiple criteria succeeds   ...
ok 144 - findDonor: ... and finds right entry.
ok 145 - findDonor: 2 valid multiple criteria succeeds   ...
ok 146 - findDonor: ... and finds right entry.
ok 147 - findDonor: 3 valid multiple criteria succeeds   ...
ok 148 - findDonor: ... and finds right entry.
ok 149 - findDonor: single criteria find expecting multiple records succeeds...
ok 150 - findDonor: ... and finds the right entires.
2015-12-30 06:09:43 -08:00
Bradley M. Kuhn
501355b839 addEmailAddress: redundant add w/ same address.
This should succeed as the previous tests show.  They now pass:

ok 21 - addEmailAddress: fails adding existing email address with mismatched type.
ok 22 - addEmailAddress: succeeds when adding email that already exists...
ok 23 - addEmailAddress: ... and returns same id.
2015-12-30 06:00:42 -08:00
Bradley M. Kuhn
6d1825240a addEmailAddress: permit shared email addresses.
An existing email address can exist already.  If it does, just map it to
the new donor_id as well.
2015-12-30 05:49:12 -08:00
Bradley M. Kuhn
736f022005 _lookupEmailAddress: replace _lookupEmailAddressId
Actually, I will ultimately need the whole record for my purposes, so
rework this function to return everything.
2015-12-30 05:41:10 -08:00
Bradley M. Kuhn
4d2fc22de1 _lookupEmailAddressId: implement helper function
This helper function will be needed for a few changes I'm about to make.
2015-12-30 05:33:05 -08:00
Bradley M. Kuhn
9c8db6b84f fulfillRequest: allow requestTypeId per getRequest
getRequest() now allows requestTypeId, so fulfillRequest() can as well.
Add tests for that, and don't die if requestType isn't given.
2015-12-30 04:12:21 -08:00
Bradley M. Kuhn
1760f60759 getRequest: re-implement to take hash argument
Instead of a bunch of serial arguments, reimplement getRequest() to take
a hash of parameters.

In the process, add support for requestTypeId to be included.
2015-12-30 04:04:37 -08:00
Bradley M. Kuhn
e4dcfd11d5 _verifyRequestTypeId =>_lookupRequestTypeById
I found need to have _verifyRequestTypeId() actually return the
request_type in a reimplementation of getRequest() that I'm working on,
so I've made this change.
2015-12-30 03:57:19 -08:00
Bradley M. Kuhn
10030b3488 _verifyRequestTypeId =>_lookupRequestTypeById
I found need to have _verifyRequestTypeId() actually return the
request_type in a reimplementation of getRequest() that I'm working on,
so I've made this change.  Some tests are failing because of the use of
_verifyRequestTypeId().  Next commit will address that.
2015-12-30 03:55:28 -08:00
Bradley M. Kuhn
b03a469338 Simplify code: use helper function that does same
This code was roughly duplicate of what _verifyRequestTypeId() was
already doing.
2015-12-30 03:33:36 -08:00
Bradley M. Kuhn
9de60c3c5e Use donorId rather than supporterId as main handle
Since we converted to making this a more general donor database, change
the handle used for an individual in the database from supporterId to
donorId.

Note that I left addSupporter() method name untouched because it does
automatically assume you mean a supporter, not a mere donor.  Later, an
addDonor() method should likely be added.
2015-12-30 03:13:41 -08:00
Bradley M. Kuhn
95ef1fce28 Change table to donor; add is_supporter field.
Up until now, this software has been focused on just Supporters, but
really there is no reason this should not be a general donor database.
Therefore, don't use the name supporter in the database, and add a
field.

public_ack is now allowed to be NULL, because the idea being we don't
have an answer from all who donate whether or not they want public
acknowledgment.

the is_supporter boolean is added to record whether or not they came
through the supporter program.
2015-12-30 03:10:07 -08:00
Bradley M. Kuhn
f74c5d1854 DESTROY: detect _beginWork/_commit mismatches.
The best place to detect these mismatches is in DESTROY.  An error
should be given when they are mismatched and we DESTROY the object.
That's now done.
2015-12-20 18:52:08 -08:00
Bradley M. Kuhn
096561a5c4 _rollback() work if failure occurs in these calls.
This is the location where there was unbalanced _beginWork()/_commit()
calls.  In future, when writing tests, it's probably good to check this
often in the tests.
2015-12-20 18:51:53 -08:00
Bradley M. Kuhn
5a37adc626 getPreferredEmailAddress: initial implementation. 2015-12-20 18:22:15 -08:00
Bradley M. Kuhn
2e39065c3e setPreferredEmailAddress: initial implementation
These tests now pass:

ok 106 - setPreferredEmailAddress: dies for undefined id
ok 107 - setPreferredEmailAddress: dies for non-numeric id
ok 108 - setPreferredEmailAddress: email address undefined fails
ok 109 - setPreferredEmailAddress: email address with extra @ fails to add.
ok 112 - setPreferredEmailAddress: email address not found in database does not die....
ok 113 - setPreferredEmailAddress: ....but returns undef
ok 116 - setPreferredEmailAddress: setting preferred email address succeeds....
ok 117 - setPreferredEmailAddress: ... and returns correct email_address_id on success
2015-12-20 18:10:56 -08:00
Bradley M. Kuhn
f1b8406e61 Add missing =back in documentation. 2015-12-20 17:11:01 -08:00
Bradley M. Kuhn
cb1ce38650 fulfillRequest: test had incorrect return value.
fulfillRequest() returns the id, not a hash of values.
2015-12-20 17:07:44 -08:00
Bradley M. Kuhn
f29a243db3 Extract $requestId from getRequest() return.
of course, getRequest() returns  a hash so we must properly extract the
value we want.

This fix causes this test to now pass:

ok 73 - fulfillRequest: databse entry from successful return is correct
2015-12-20 17:02:44 -08:00
Bradley M. Kuhn
3b3ee21288 Fix typos in SQL and return value.
This causes the basic add test to finally pass:

ok 70 - fulfillRequest: succeeds for existing request
2015-12-20 16:58:13 -08:00
Bradley M. Kuhn
a1f00e68a0 confess() rather than die() here.
We  really want to know the context of what happened when it dies here.
2015-12-20 16:55:15 -08:00
Bradley M. Kuhn
6de0eb64a2 Remove uncontrolled debugging statements.
Yes, I should add a debug mode.  But I'm not going to.
2015-12-20 16:43:16 -08:00
Bradley M. Kuhn
89149fe043 getRequest: Initial implementation.
This implementation of getRequest passes all the current tests, except
for those relate to fulfillment.
2015-12-20 16:40:27 -08:00
Bradley M. Kuhn
ccfa057cce Fix my bad spelling: fufill -> fulfill 2015-12-20 14:01:15 -08:00
Bradley M. Kuhn
aff5e66786 fulfillRequest(): basic implementation.
First attempt at implementing fulfillRequest() method.

It seems that request_id was incorrectly missing from the fulfillment
table.
2015-12-20 13:59:50 -08:00
Bradley M. Kuhn
3afe947cdd fufillRequest: parameter checks.
Parameter check tests now pass:

ok 66 - fufillRequest: dies if supporterId not specified
ok 67 - fufillRequest: dies if supporterId not found in database
ok 68 - fufillRequest: dies if requestType not specified
ok 69 - fufillRequest: who not specified

Also added new test.
2015-12-20 13:46:45 -08:00
Bradley M. Kuhn
cb01c1a14c addRequest: initial implementation
addRequest-specific unit tests now all pass:

ok 55 - addRequest: dies if supporterId not specified.
ok 56 - addRequest: dies if requestTypeId / requestType not specified.
ok 57 - addRequest: dies if supporterId invalid.
ok 58 - addRequest: dies if requestTypeId invalid.
ok 59 - addRequest: succeeds with a requestType but no configuration parameter.
ok 60 - addRequest: id returned on successful addRequest() is a number
ok 61 - addRequest: underlying call to addRequestType works properly, per getRequestType
ok 62 - addRequest: succeeds with a requestType and requestConfiguration and a note.
ok 63 - addRequest: succeeds with a requestTypeId and requestConfigurationId with no a note.
2015-12-20 12:46:07 -08:00
Bradley M. Kuhn
847858bbf0 transaction counter is per instance.
The older transaction counter was for the whole class, which was
problematic if you had more than one supporter database open at a time,
or were otherwise using different supporter databases.

I'm not completely sure this fix is fully functional, because perhaps we
should be carrying this counter along with the DBH (i.e., what if two
Supporter instances are created with the same dbh).

I suppose we could fix this problem by changing the new() interface to
require the instance itself be in control of the dbh.
2015-12-20 12:21:38 -08:00
Bradley M. Kuhn
4ca89cfad4 _getOrCreateRequestConfiguration: Fix various bugs
There was some parameter confusion (using ids instead of the actual
types/descriptions) on some of the public facing methods.

Also, lookup of existing ids was buggy; just use public facing methods.
2015-12-20 12:10:27 -08:00
Bradley M. Kuhn
92d36a4039 _getOrCreateRequestConfiguration: Implement.
Implementation of this method.
2015-12-20 11:20:16 -08:00
Bradley M. Kuhn
3203a62d5b More descriptive variable name. 2015-12-20 11:14:13 -08:00
Bradley M. Kuhn
b065293ce7 Correct hash lookup typo. 2015-12-20 11:13:18 -08:00
Bradley M. Kuhn
8f22a89a47 _getOrCreateRequestConfiguration: error conditions
These tests now pass:

ok 110 - _getOrCreateRequestConfiguration: dies on empty hash
ok 111 - _getOrCreateRequestConfiguration: dies for string requestConfigurationId
ok 112 - _getOrCreateRequestConfiguration: dies for non-existant requestConfigurationId
ok 113 - _getOrCreateRequestConfiguration: dies for string request id
ok 114 - _getOrCreateRequestConfiguration: dies for non-existant requestTypeId
2015-12-20 11:11:42 -08:00
Bradley M. Kuhn
9dcea735f4 _verifyRequestTypeId: Implementation & unit tests.
Straightforward helper method.
2015-12-20 11:07:06 -08:00
Bradley M. Kuhn
591fa396ca addRequest: begin implementation
Basic implementation of addRequest, which causes these test to now pass:

ok 55 - addRequest: dies if supporterId not specified.
ok 56 - addRequest: dies if requestTypeId / requestType not specified.
ok 57 - addRequest: dies if supporterId invalid.
ok 58 - addRequest: dies if requestTypeId invalid.
ok 61 - addRequest: underlying call to addRequestType works properly, per getRequestType
2015-12-20 10:08:37 -08:00
Bradley M. Kuhn
d1d9b80583 Implementation of _getOrCreateRequestType
Tests pass for this now:
ok 97 - _getOrCreateRequestType: dies on empty hash
ok 98 - _getOrCreateRequestType: dies for string request id
ok 99 - _getOrCreateRequestType: dies for non-existant requestTypeId
ok 100 - _getOrCreateRequestType: succeeds with just requestType
ok 101 - _getOrCreateRequestType: lookup of a request works after _getOrCreateRequestType
ok 102 - _getOrCreateRequestType: lookup of a request works after _getOrCreateRequestType
ok 103 - _getOrCreateRequestType: lookup of existing requestType suceeds.
ok 104 - _getOrCreateRequestType: deletes requestType if both are provided.
2015-12-17 20:15:41 -08:00
Bradley M. Kuhn
eee5a0d3d6 We should call the DBI quote function for integer. 2015-12-17 19:54:37 -08:00
Bradley M. Kuhn
60805389b7 Correct mistyped variable name. 2015-12-17 16:59:27 -08:00
Bradley M. Kuhn
0cbd8ae1ae Remove these debugging statements.
I should probably instead add a debug mode, but whatever.
2015-12-16 20:25:41 -08:00
Bradley M. Kuhn
05654fe11f Implementation of addPostalAddress().
All tests related to addPostalAddress now pass.

ok 28 - addPostalAddress: dies for undefined id
ok 29 - addPostalAddress: dies for non-numeric id
ok 30 - addPostalAddress: postal address undefined fails
ok 31 - addPostalAddress: type is not added when other input paramaters are invalid
ok 32 - addPostalAddress: addPostalAddress of a valid formatted_address works.
ok 33 - addPostalAddress: id returned is sane.
2015-12-16 20:24:52 -08:00
Bradley M. Kuhn
e3cf1665d9 More robust call to addAddressType.
This is not strictly necessary, but it seems right to me that we trap
the error and rollback ourselves here as well.
2015-12-16 20:24:24 -08:00
Bradley M. Kuhn
67a37ddd10 Revert incorrect table change from earlier commit.
An earlier commit that meant to remove the "my" from beginning of this
statement inadvertently changed the table name.  This is now corrected.
2015-12-16 20:13:57 -08:00
Bradley M. Kuhn
031fbab35a Fix rollbacks calls properly here.
Upon fixing the reference counter thing in the previous commit, this bug
caused tests to fail.  We have to _rollback() properly any time we've
called _begin_work(), particularly before die()'ing after a
_begin_work().
2015-12-16 20:11:50 -08:00
Bradley M. Kuhn
ea60b11965 Rework the reference counter for begin_work/commit
This code was clearly not correct as it was.  The main problem is that I
was envisioning begin_work/commit pairs as always matched, but of course
if we die in the middle of a transaction, the counter has to be reset.
That's why we have to set the $dbh->{HandleError} in new() to a
subroutine that does that.

Also, we need to similarly wrap rollback() calls.  When rolling back, we
have to reset the counter as we're not going to commit() (that's the
point).
2015-12-16 20:09:49 -08:00
Bradley M. Kuhn
aef01b3031 new: Implement verification of $dbh
The two previously committed tests now pass:

ok 2 - new: dies when dbh is undefined.
ok 3 - new: dies when dbh is blessed into another module.
2015-12-16 19:25:20 -08:00
Bradley M. Kuhn
731bc2a05d Remove duplicate my.
Did not cause a problem, but generated a warning.
2015-12-16 18:43:11 -08:00
Bradley M. Kuhn
5d8d480223 Begin implementation of addPostalAddress.
These tests mostly fail, although a few pass automatically:

not ok 26 - addPostalAddress: dies for undefined id
not ok 27 - addPostalAddress: dies for non-numeric id
not ok 28 - addPostalAddress: postal address undefined fails
ok 29 - addPostalAddress: type is not added when other input paramaters are invalid
ok 30 - addPostalAddress: addPostalAddress of a valid formatted_address works.
ok 30 - addPostalAddress: addPostalAddress of a valid formatted_address works.
not ok 31 - addPostalAddress: id returned is sane.

Goal is to implement those and make sure they all pass.
2015-12-16 18:36:47 -08:00
Bradley M. Kuhn
c4668b81d6 addEmailAddress: supporter_email_address_mapping
Properly map email address to supporter when email address is added.

Test now passes:
   ok 12 - addSuporter: email address mapping is created on addSupporter() w/ email address included
2015-12-16 18:13:28 -08:00
Bradley M. Kuhn
3f3f8b7090 Did I have some other language on the brain?
$self is the standard name for the current object in Perl, of course. :)
2015-12-16 18:07:46 -08:00
Bradley M. Kuhn
6e10f76d5a Wrap addSupporter operations in transaction
All of the addSupporter must now succeed (including sub-operations like
addEmailAddress).

This causes one failing test to now pass:
   ok 55 - addSupporter: fails if email_address given but email cannot be inserted
2015-12-14 17:30:44 -08:00
Bradley M. Kuhn
2a374b957e Correct off-by-one error in counter.
The counter should be incremented/decremented after testing its value,
not before.
2015-12-14 17:20:17 -08:00
Bradley M. Kuhn
45570a5db0 Wrap dbh->begin_work & dbh->commit
I want to be able to nest begin_work()/commit() calls.  Years ago (in
the mid-1990s), when I did database programming, this is how we handled
this scenario.  I have no idea if there is now a "better way" to do
this, but some quick net searches found nothing that is recommended, but
I admittedly didn't search that hard.

This should work for our needs.
2015-12-14 17:16:35 -08:00
Bradley M. Kuhn
69945c2704 Implementation of getRequestConfigurations
A basic implementation of getRequestConfigurations and tests to go with
it.

Also added here is the test to verify that no items are added when
duplicates are included.
2015-12-13 14:06:22 -08:00
Bradley M. Kuhn
4331093cee Basic implementation of addRequestConfigurations
Adjusted one test slightly: there was a missing argument.  Also,
corrected test count.

While implementing, I realized a failure mode that forces a rollback:
duplication on the input list of configurations.  Tests are now needed
for that.
2015-12-13 13:37:52 -08:00
Bradley M. Kuhn
735db56d47 Begin implementation of addRequestConfigurations
Includes some modifications to reuse data from previous tests.
2015-12-13 13:04:27 -08:00
Bradley M. Kuhn
8fd03e8e6f Fail causes on getRequestConfigurations. 2015-12-13 12:50:08 -08:00
Bradley M. Kuhn
19d513280f addRequestType and getRequestType methods.
Including tests for both.
2015-12-13 12:16:14 -08:00
Bradley M. Kuhn
bf4d5d8b23 Fix number of arguments on _verifyId in prototype. 2015-12-13 12:15:50 -08:00
Bradley M. Kuhn
b34de3c1da Verify email address format with external module. 2015-12-11 18:32:59 -08:00
Bradley M. Kuhn
9e2359ed72 Test to verify addEmailAddress returns a valid id. 2015-12-11 18:23:24 -08:00
Bradley M. Kuhn
5b07fe6af9 Actual email address add code; tests stay same. 2015-12-11 18:19:25 -08:00
Bradley M. Kuhn
b1436e037e addEmailAddress: call addAddressType underneath
address_type is added automatically from the addEmailAddress call.
Since addAddressType does a lookup first, this should not cause
duplicates.
2015-12-09 19:56:22 -08:00
Bradley M. Kuhn
a3aafac44a addAddressType: initial implementation & unit test 2015-12-09 19:48:59 -08:00
Bradley M. Kuhn
b0d7639bc3 Remove stray use command, likely bad paste. 2015-12-09 19:37:36 -08:00
Bradley M. Kuhn
ba6843e21e Begin work on addEmailAddress method.
Basic stub and a few tests.
2015-12-09 19:17:46 -08:00
Bradley M. Kuhn
587144f03e _verifyId method: initial implementation.
Internal method for use to verify that an id we have really is in the
database.

For use before other operations.
2015-12-09 18:39:18 -08:00
Bradley M. Kuhn
de7b145ac3 Some documentation for existing methods. 2015-12-09 18:37:26 -08:00
Bradley M. Kuhn
03b1ac5436 Add local variables for Emacs. 2015-12-09 18:36:57 -08:00
Bradley M. Kuhn
70ad0b8b30 Initial basic support for creating a new Supporter.
This is incomplete as of yet, since it doesn't properly set up other
tables.
2015-12-09 15:44:05 -08:00
Bradley M. Kuhn
3d672d1f68 Correct arguments to method; add public_ack 2015-12-06 19:24:10 -08:00
Bradley M. Kuhn
fc22b9a3cc Begin writing addSupporter method.
ledger_entity_id is required.
2015-12-06 18:56:59 -08:00
Bradley M. Kuhn
fa52370f53 Initial creation code and tests. 2015-12-06 18:28:49 -08:00
Bradley M. Kuhn
99c637f167 This is already version 0.2 2015-12-06 17:27:25 -08:00
Bradley M. Kuhn
be753d5b3d Wrote basic documentation. 2015-12-06 17:27:13 -08:00
Bradley M. Kuhn
97df181a76 Generated stubs for Supporters module.
Generated this by running: h2xs -AXc -n Supporters
2015-12-06 17:20:14 -08:00