cleaned up all the tests and refactored the db class
This commit is contained in:
parent
6dbd58faf4
commit
858e5bb9e8
@ -77,7 +77,7 @@
|
||||
::METHOD addContact
|
||||
expose db
|
||||
use arg contactDict /* Use a Rexx 'directory' to pass multiple values around */
|
||||
sql = "INSERT INTO contacts (first_name, last_name) VALUES ('"contactDict~firstName"', '"contactDict~lastName"')"
|
||||
sql = "INSERT INTO contacts (first_name, last_name) VALUES ('"contactDict~First_Name"', '"contactDict~Last_Name"')"
|
||||
rc = db~exec(sql)
|
||||
if rc \= 0 then do
|
||||
say "Error adding contact:" db~errMsg()
|
||||
@ -108,43 +108,6 @@
|
||||
return
|
||||
END
|
||||
return contacts[1] /* Rexx is 1-indexed */
|
||||
/***
|
||||
returnedContent~firstName = contact["FIRST_NAME"]
|
||||
returnedContent~lastName = contact["LAST_NAME"]
|
||||
sql2 = "SELECT * FROM email_addresses WHERE contact_id = "contactId
|
||||
emails = db~exec(sql2,.true,.ooSQLite~OO_ARRAY_OF_DIRECTORIES)
|
||||
email_array = .Array~new()
|
||||
do row over emails
|
||||
email_array.append(row["EMAIL"])
|
||||
END
|
||||
returnedContent~emailAddresses = email_array
|
||||
|
||||
sql3 = "SELECT * FROM phone_numbers WHERE contact_id = "contactId
|
||||
phones = db~exec(sql3,.true,.ooSQLite~OO_ARRAY_OF_DIRECTORIES)
|
||||
phone_dir = .Directory~new()
|
||||
phone_array = .Array~new()
|
||||
do phone over phones
|
||||
phone_dir~put(phone["NUMBER"], phone["TYPE"])
|
||||
phone_array.append(phone_dir)
|
||||
END
|
||||
returnedContent~phoneNumbers = phone_array
|
||||
|
||||
sql4 = "SELECT * FROM addresses WHERE contact_id = "contactId
|
||||
addresses = db~exec(sql3,.true,.ooSQLite~~OO_ARRAY_OF_DIRECTORIES)
|
||||
address_dir = .Dictionary~new()
|
||||
address_array = .Array~new()
|
||||
do address over addresses
|
||||
address_dir~type = address["TYPE"]
|
||||
address_dir~street = address["STREET"]
|
||||
address_dir~city = address["CITY"]
|
||||
address_dir~state = address["STATE"]
|
||||
address_dir~postal_code = address["POSTAL_CODE"]
|
||||
address_dir~country = address["COUNTRY"]
|
||||
address_array.append(address_dir)
|
||||
END
|
||||
returnedContent~addresses = address_array
|
||||
return returnedContent
|
||||
***/
|
||||
|
||||
::METHOD getAllContacts
|
||||
expose db
|
||||
@ -180,18 +143,6 @@
|
||||
return -1
|
||||
end
|
||||
return rc
|
||||
/**
|
||||
self~removeContactPhones(contactId)
|
||||
self~removeContactEmails(contactId)
|
||||
self~removeContactAddresses(contactId)
|
||||
|
||||
/* Then add new entries */
|
||||
self~addPhoneNumber(contactId, contactDict["PHONE_TYPE"], contactDict["PHONE_NUMBER"])
|
||||
self~addEmailAddress(contactId, contactDict["EMAIL_TYPE"], contactDict["EMAIL_ADDRESS"])
|
||||
self~addAddress(contactId, contactDict~addressType, contactDict~street, contactDict~city, contactDict~state,
|
||||
contactDict~postalCode, contactDict~country)
|
||||
return 0
|
||||
**/
|
||||
|
||||
::METHOD deleteContact
|
||||
expose db
|
||||
@ -251,19 +202,17 @@
|
||||
return rc
|
||||
|
||||
::METHOD deletePhoneNumber
|
||||
expose db
|
||||
use arg phoneId
|
||||
|
||||
stmt = db~prepare("DELETE FROM phone_numbers WHERE id = ?")
|
||||
stmt~bind(1, phoneId)
|
||||
stmt~step
|
||||
|
||||
return db~changes() > 0
|
||||
|
||||
|
||||
expose db
|
||||
use arg phoneId
|
||||
sql = "DELETE FROM phone_numbers WHERE id = "phoneId
|
||||
rc = db~exec(sql)
|
||||
if rc \= 0 then DO
|
||||
Say "Unable to delete phone id "phoneId
|
||||
return rc
|
||||
END
|
||||
return rc
|
||||
|
||||
/* Email address operations */
|
||||
|
||||
::METHOD addEmailAddress
|
||||
expose db
|
||||
use arg contactId, emailType, emailAddress
|
||||
@ -303,14 +252,16 @@
|
||||
|
||||
|
||||
::METHOD deleteEmailAddress
|
||||
expose db
|
||||
use arg emailId
|
||||
expose db
|
||||
use arg emailId
|
||||
|
||||
stmt = db~prepare("DELETE FROM email_addresses WHERE id = ?")
|
||||
stmt~bind(1, emailId)
|
||||
stmt~step
|
||||
|
||||
return db~changes() > 0
|
||||
sql = "DELETE FROM email_addresses WHERE id = "emailId
|
||||
rc = db~exec(sql)
|
||||
if rc \= 0 then do
|
||||
say "Error deleting email address:" db~errMsg()
|
||||
return -1
|
||||
end
|
||||
return rc
|
||||
|
||||
/* Physical address operations */
|
||||
|
||||
@ -408,4 +359,3 @@
|
||||
return -1
|
||||
end
|
||||
return 0
|
||||
|
||||
|
Binary file not shown.
@ -25,6 +25,11 @@ DO
|
||||
tests~TestAddRealAddress
|
||||
tests~TestFullDetailRetrieval
|
||||
tests~TestUpdateContact
|
||||
tests~TestSearchForContact
|
||||
tests~TestEmailDeletion
|
||||
tests~TestPhoneNumberDeletion
|
||||
tests~TestDeleteEntireContact
|
||||
|
||||
END
|
||||
|
||||
tests~tearDown
|
||||
@ -81,8 +86,8 @@ exit 0
|
||||
phoneArray~append(phoneDict2)
|
||||
|
||||
contactDict = .Directory~new()
|
||||
contactDict~firstName = "John"
|
||||
contactDict~lastName = "Doe"
|
||||
contactDict~First_Name = "John"
|
||||
contactDict~Last_Name = "Doe"
|
||||
|
||||
|
||||
::METHOD TestCreateContact
|
||||
@ -90,7 +95,7 @@ exit 0
|
||||
/* Test contact creation */
|
||||
say ""
|
||||
say "=== TESTING CONTACT CREATION ==="
|
||||
say "Creating contact:" contactDict~firstName contactDict~lastName
|
||||
say "Creating contact:" contactDict~First_Name contactDict~Last_Name
|
||||
contactId = db~addContact(contactDict)
|
||||
say "Contact created with ID:" contactId
|
||||
|
||||
@ -265,62 +270,89 @@ exit 0
|
||||
say "ERROR: Failed to retrieve updated contact details!"
|
||||
end
|
||||
|
||||
::METHOD TestDeletion
|
||||
say ""
|
||||
say "=== TESTING DELETION ==="
|
||||
|
||||
/* Test deleting an email */
|
||||
say "Deleting personal email..."
|
||||
result = db~deleteEmailAddress(personalEmailId)
|
||||
say "Deletion successful:" result
|
||||
|
||||
/* Get contact to verify deletion */
|
||||
contact = db~getContact(contactId)
|
||||
say "Email addresses after deletion:"
|
||||
do email over contact['emails']
|
||||
say " " email['type']":" email['email'] "(ID:" email['id']")"
|
||||
end
|
||||
|
||||
::METHOD OtherStuff
|
||||
/* Test deleting the entire contact */
|
||||
say "Deleting entire contact..."
|
||||
result = db~deleteContact(contactId)
|
||||
say "Deletion successful:" result
|
||||
|
||||
/* Try to retrieve the deleted contact */
|
||||
contact = db~getContact(contactId)
|
||||
if contact = .nil then
|
||||
say "Contact successfully deleted - could not retrieve contact with ID" contactId
|
||||
else
|
||||
say "ERROR: Contact was not properly deleted!"
|
||||
|
||||
::METHOD TestSearchForContact
|
||||
expose db
|
||||
/* Test searching functionality */
|
||||
say ""
|
||||
say "=== TESTING SEARCH FUNCTIONALITY ==="
|
||||
|
||||
/* Add multiple contacts for search testing */
|
||||
say "Adding test contacts for search..."
|
||||
db~addContact("Jane", "Smith")
|
||||
db~addContact("John", "Johnson")
|
||||
db~addContact("Bob", "Smith")
|
||||
db~addContact("Sarah", "Williams")
|
||||
first_names = .Array~of("Jane", "John", "Bob", "Sarah", "Tom", "Davey")
|
||||
last_names = .Array~of("Smith", "Johnson", "Smith", "Williams", "Jones", "Jones")
|
||||
Do i = 1 to 6
|
||||
tempDict = .Directory~new()
|
||||
tempDict~First_Name = first_names[i]; tempDict~Last_Name = last_names[i];
|
||||
contactId = db~addContact(tempDict)
|
||||
END
|
||||
|
||||
/* Search for contacts */
|
||||
say "Searching for 'Smith'..."
|
||||
results = db~searchContacts("Smith")
|
||||
say "Found" results~items() "contacts:"
|
||||
do contact over results
|
||||
say " " contact['firstName'] contact['lastName'] "(ID:" contact['id']")"
|
||||
say " " contact['FIRST_NAME'] contact['LAST_NAME'] "(ID:" contact['ID']")"
|
||||
end
|
||||
|
||||
say "Searching for 'John'..."
|
||||
results = db~searchContacts("John")
|
||||
say "Found" results~items() "contacts:"
|
||||
do contact over results
|
||||
say " " contact['firstName'] contact['lastName'] "(ID:" contact['id']")"
|
||||
say " " contact['FIRST_NAME'] contact['LAST_NAME'] "(ID:" contact['ID']")"
|
||||
end
|
||||
|
||||
::METHOD TestEmailDeletion
|
||||
expose db contactDict
|
||||
say ""
|
||||
say "=== TESTING EMAIL DELETION ==="
|
||||
emails = db~getEmailAddresses(1)
|
||||
say "Email addresses Before deletion:"
|
||||
do email over emails
|
||||
say " " email['TYPE']":" email['EMAIL'] "(ID:" email['ID']")"
|
||||
end
|
||||
|
||||
/* Test deleting an email */
|
||||
say "Deleting personal email..."
|
||||
result = db~deleteEmailAddress(1)
|
||||
say "Deletion successful:" result
|
||||
|
||||
/* Get contact to verify deletion */
|
||||
emails = db~getEmailAddresses(1)
|
||||
say "Email addresses After deletion:"
|
||||
do email over emails
|
||||
say " " email['TYPE']":" email['EMAIL'] "(ID:" email['ID']")"
|
||||
end
|
||||
|
||||
::METHOD TestPhoneNumberDeletion
|
||||
expose db contactDict
|
||||
say ""
|
||||
say "=== TESTING PHONE DELETION ==="
|
||||
phones = db~getPhoneNumbers(1)
|
||||
say "Phone Numbers Before deletion:"
|
||||
do phone over phones
|
||||
say " " phone['TYPE']":" phone['NUMBER'] "(ID:" phone['ID']")"
|
||||
end
|
||||
|
||||
say "Deleting Personal Phone Number..."
|
||||
result = db~deletePhoneNumber(1)
|
||||
say "Deletion successful:" result
|
||||
|
||||
phones = db~getPhoneNumbers(1)
|
||||
say "Phone Numbers After deletion:"
|
||||
do phone over phones
|
||||
say " " phone['TYPE']":" phone['NUMBER'] "(ID:" phone['ID']")"
|
||||
end
|
||||
|
||||
::METHOD TestDeleteEntireContact
|
||||
expose db
|
||||
/* Test deleting the entire contact */
|
||||
say ""
|
||||
say "=== TESTING FULL CONTACT DELETION ==="
|
||||
result = db~deleteContact(1)
|
||||
say "Deletion successful:" result
|
||||
|
||||
/* Try to retrieve the deleted contact */
|
||||
contact = db~getContact(1)
|
||||
if contact = .nil then
|
||||
say "Contact successfully deleted - could not retrieve contact with ID: 1"
|
||||
else
|
||||
say "ERROR: Contact was not properly deleted!"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user