feat: Add reminder functionality to ContractSigner model
- Added `last_reminder_mail_sent_at` field to track reminder timestamps. - Implemented `can_send_reminder` to check if a reminder can be sent based on a 30-minute cooldown. - Added `reminder_cooldown_remaining` to get remaining cooldown time. - Added `mark_reminder_sent` to update reminder timestamp. - Added example demonstrating reminder functionality in `legal_contract_example.rs`. - Added tests for reminder functionality in `test_reminder_functionality.rs`. - Updated Rhai scripts to include reminder-related functions and tests. - Improved formatting and clarity in example code.
This commit is contained in:
@@ -39,14 +39,17 @@ let signer1 = new_contract_signer(signer1_id, "Alice Wonderland", "alice@example
|
||||
print(`Signer 1 ID: ${signer1.id}, Name: ${signer1.name}, Email: ${signer1.email}`);
|
||||
print(`Signer 1 Status: ${signer1.status}, Comments: ${format_optional_string(signer1.comments, "N/A")}`);
|
||||
print(`Signer 1 Signed At: ${format_optional_int(signer1.signed_at, "Not signed")}`);
|
||||
print(`Signer 1 Last Reminder: ${format_optional_int(signer1.last_reminder_mail_sent_at, "Never sent")}`);
|
||||
|
||||
let signer2_id = "signer-uuid-002";
|
||||
let signer2 = new_contract_signer(signer2_id, "Bob The Builder", "bob@example.com")
|
||||
.status(SignerStatusConstants::Signed)
|
||||
.signed_at(1678886400) // Example timestamp
|
||||
.comments("Bob has already signed.");
|
||||
.comments("Bob has already signed.")
|
||||
.last_reminder_mail_sent_at(1678880000); // Example reminder timestamp
|
||||
|
||||
print(`Signer 2 ID: ${signer2.id}, Name: ${signer2.name}, Status: ${signer2.status}, Signed At: ${format_optional_int(signer2.signed_at, "N/A")}`);
|
||||
print(`Signer 2 Last Reminder: ${format_optional_int(signer2.last_reminder_mail_sent_at, "Never sent")}`);
|
||||
|
||||
// --- Test ContractRevision Model ---
|
||||
print("\n--- Testing ContractRevision Model ---");
|
||||
@@ -116,4 +119,31 @@ print("Updated Contract saved.");
|
||||
let final_retrieved_contract = get_contract_by_id(contract1_base_id);
|
||||
print(`Final Retrieved Contract - Status: ${final_retrieved_contract.status}, Description: '${final_retrieved_contract.description}'`);
|
||||
|
||||
// --- Test Reminder Functionality ---
|
||||
print("\n--- Testing Reminder Functionality ---");
|
||||
let current_time = 1678900000; // Example current timestamp
|
||||
|
||||
// Test reminder functionality on signers
|
||||
if final_retrieved_contract.signers.len() > 0 {
|
||||
let test_signer = final_retrieved_contract.signers[0];
|
||||
print(`Testing reminder for signer: ${test_signer.name}`);
|
||||
|
||||
let can_send = can_send_reminder(test_signer, current_time);
|
||||
print(`Can send reminder: ${can_send}`);
|
||||
|
||||
let cooldown_remaining = reminder_cooldown_remaining(test_signer, current_time);
|
||||
print(`Cooldown remaining: ${format_optional_int(cooldown_remaining, "No cooldown")}`);
|
||||
|
||||
// Simulate sending a reminder
|
||||
if can_send {
|
||||
print("Simulating reminder sent...");
|
||||
mark_reminder_sent(test_signer, current_time);
|
||||
print("Reminder timestamp updated");
|
||||
|
||||
// Check cooldown after sending
|
||||
let new_cooldown = reminder_cooldown_remaining(test_signer, current_time);
|
||||
print(`New cooldown: ${format_optional_int(new_cooldown, "No cooldown")} seconds`);
|
||||
}
|
||||
}
|
||||
|
||||
print("\nLegal Rhai example script finished.");
|
||||
|
Reference in New Issue
Block a user