Commit graph

417 commits

Author SHA1 Message Date
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
d654622ebe We've already done one ResetDB above.
So make sure we're reseting the right DB
2015-12-20 12:45:43 -08:00
Bradley M. Kuhn
49273ecbde Be sure DESTROY is called, etc. 2015-12-20 12:45:36 -08:00
Bradley M. Kuhn
17c0f38639 Correct test: wrong comparison.
It was comparing a request_id to a request_type_id.  That is herein corected.
2015-12-20 12:45:15 -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
5cc564202e Remove debugging print in tests. 2015-12-20 12:11:42 -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
5e03ffd74d _getOrCreateRequestConfiguration:Refine unit tests
The unit tests had some bugs, which are herein fixed.
2015-12-20 12:09:52 -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
4ef9b9634a Improve test string here. 2015-12-20 11:12:46 -08:00
Bradley M. Kuhn
fc2250203d _getOrCreateRequestConfiguration: Additional test.
This additional test makes sure that it still fails a previous condition
when the requestTypeId is correct.
2015-12-20 11:12:12 -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
1c33f4cbba _getOrCreateRequestConfiguration: Basic unit tests
This also required resetting the database in an earlier portion of the
tests than previous.
2015-12-20 10:58:22 -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
8876808aec Corrected some tests for _getOrCreateRequestType() 2015-12-17 20:15:09 -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
e2a63b30fa Tests for _getOrCreateRequestType
This is an internal helper function that I will need will implementing
the others.
2015-12-17 19:41:21 -08:00
Bradley M. Kuhn
2e2798459c Tests relating to requests, which spec out API.
This specs out the API for for addRequest(), getRequest(), and
fufillRequest().  These tests explain the basics of how they should
work.
2015-12-17 18:58:28 -08:00
Bradley M. Kuhn
5dc73c0936 This handle no longer needed either. 2015-12-17 17:13:01 -08:00
Bradley M. Kuhn
3480c5b5c4 Use postal address API. 2015-12-17 17:12:29 -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
6e57396399 Correct test that now fails after recent changes.
This test now started failing after the other corrections made in the
last few commits.

As it turns out, this test was buggy.  We wanted to test a request_type
that didn't exist, and verify that calls to addRequestConfigurations
with bad arguments didn't create the request_type if it didn't already
existed.  That's what the test now does.
2015-12-16 20:16:26 -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
fd85bb68f5 Remove blank line. 2015-12-16 20:13:32 -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
470b889c3e new: Tests verify $dbh is a valid database handle
These tests ensure new() method checks to see if you're really giving a
DBI class member as the first argument.
2015-12-16 19:21:01 -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
9417690277 Fix typo from last commit. 2015-12-16 18:42:59 -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
bb84d6ad31 Minor documentation correction. 2015-12-16 18:25:07 -08:00
Bradley M. Kuhn
69260413f3 Import script no longer needs to make this link.
addSupporter() now does it properly in the API.
2015-12-16 18:15:54 -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
74146a15c9 Disconnect from this database handle too. 2015-12-14 17:28:36 -08:00
Bradley M. Kuhn
159d3d6609 Also verify it's a HASH reftype. 2015-12-14 17:28:19 -08:00
Bradley M. Kuhn
2950067c63 bug in tests found with transaction ref counting
Now that we are properly nesting transactions, this test is shown to be
incorrect.  Namely, it is indeed correct that the entire add should fail
when we've given something invalid: we don't want to add the requestType
if it wasn't already there if the parameter to add
addRequestConfigurations was invalid.
2015-12-14 17:25:02 -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
6b8d79553b Test various database integrity questions.
This new section of tests verifies that when the database disappears
underneath or has other types of problems that the API still functions
as expected.

The second test committed herein currently fails.
2015-12-14 17:05:42 -08:00
Bradley M. Kuhn
6bbb59c36a Test to verify email address mapping created.
This currently fails; addSupporter() must be corrected.
2015-12-14 16:43:47 -08:00