merge branches and cleanup db
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use chrono::{Duration, Utc};
|
||||
use heromodels::db::{Collection, Db};
|
||||
use heromodels::models::finance::marketplace::{Bid, Listing, ListingType};
|
||||
use heromodels::models::finance::asset::AssetType;
|
||||
use heromodels::models::finance::marketplace::{Bid, Listing, ListingType};
|
||||
use heromodels_core::Model;
|
||||
|
||||
// Helper function to print listing details
|
||||
@@ -16,32 +16,32 @@ fn print_listing_details(listing: &Listing) {
|
||||
println!("Price: {} {}", listing.price, listing.currency);
|
||||
println!("Listing Type: {:?}", listing.listing_type);
|
||||
println!("Status: {:?}", listing.status);
|
||||
|
||||
|
||||
if let Some(expires_at) = listing.expires_at {
|
||||
println!("Expires At: {}", expires_at);
|
||||
} else {
|
||||
println!("Expires At: Never");
|
||||
}
|
||||
|
||||
|
||||
if let Some(sold_at) = listing.sold_at {
|
||||
println!("Sold At: {}", sold_at);
|
||||
}
|
||||
|
||||
|
||||
if let Some(buyer_id) = &listing.buyer_id {
|
||||
println!("Buyer ID: {}", buyer_id);
|
||||
}
|
||||
|
||||
|
||||
if let Some(sale_price) = listing.sale_price {
|
||||
println!("Sale Price: {} {}", sale_price, listing.currency);
|
||||
}
|
||||
|
||||
|
||||
println!("Bids: {}", listing.bids.len());
|
||||
println!("Tags: {:?}", listing.tags);
|
||||
|
||||
|
||||
if let Some(image_url) = &listing.image_url {
|
||||
println!("Image URL: {}", image_url);
|
||||
}
|
||||
|
||||
|
||||
println!("Created At: {}", listing.base_data.created_at);
|
||||
println!("Modified At: {}", listing.base_data.modified_at);
|
||||
}
|
||||
@@ -77,7 +77,11 @@ fn main() {
|
||||
"USD",
|
||||
ListingType::FixedPrice,
|
||||
Some(Utc::now() + Duration::days(30)), // Expires in 30 days
|
||||
vec!["music".to_string(), "instrument".to_string(), "vintage".to_string()],
|
||||
vec![
|
||||
"music".to_string(),
|
||||
"instrument".to_string(),
|
||||
"vintage".to_string(),
|
||||
],
|
||||
Some("https://example.com/images/vintage_guitar.jpg"),
|
||||
);
|
||||
|
||||
@@ -93,7 +97,11 @@ fn main() {
|
||||
"USD",
|
||||
ListingType::Auction,
|
||||
Some(Utc::now() + Duration::days(7)), // Auction ends in 7 days
|
||||
vec!["art".to_string(), "painting".to_string(), "antique".to_string()],
|
||||
vec![
|
||||
"art".to_string(),
|
||||
"painting".to_string(),
|
||||
"antique".to_string(),
|
||||
],
|
||||
Some("https://example.com/images/rare_painting.jpg"),
|
||||
);
|
||||
|
||||
@@ -114,9 +122,21 @@ fn main() {
|
||||
);
|
||||
|
||||
// Save all listings to database and get their assigned IDs and updated models
|
||||
let (fixed_price_id, db_fixed_price) = db.collection().expect("can open listing collection").set(&fixed_price_listing).expect("can set listing");
|
||||
let (auction_id, db_auction) = db.collection().expect("can open listing collection").set(&auction_listing).expect("can set listing");
|
||||
let (exchange_id, db_exchange) = db.collection().expect("can open listing collection").set(&exchange_listing).expect("can set listing");
|
||||
let (fixed_price_id, db_fixed_price) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&fixed_price_listing)
|
||||
.expect("can set listing");
|
||||
let (auction_id, db_auction) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&auction_listing)
|
||||
.expect("can set listing");
|
||||
let (exchange_id, db_exchange) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&exchange_listing)
|
||||
.expect("can set listing");
|
||||
|
||||
println!("Fixed Price Listing assigned ID: {}", fixed_price_id);
|
||||
println!("Auction Listing assigned ID: {}", auction_id);
|
||||
@@ -138,17 +158,13 @@ fn main() {
|
||||
|
||||
// Create bids for the auction listing
|
||||
let bid1 = Bid::new(
|
||||
auction_id,
|
||||
101, // Bidder ID
|
||||
5200.0,
|
||||
"USD",
|
||||
auction_id, 101, // Bidder ID
|
||||
5200.0, "USD",
|
||||
);
|
||||
|
||||
let bid2 = Bid::new(
|
||||
auction_id,
|
||||
102, // Bidder ID
|
||||
5500.0,
|
||||
"USD",
|
||||
auction_id, 102, // Bidder ID
|
||||
5500.0, "USD",
|
||||
);
|
||||
|
||||
// Print the bids
|
||||
@@ -166,7 +182,8 @@ fn main() {
|
||||
.expect("can add second bid");
|
||||
|
||||
// Save the updated auction listing
|
||||
let (_, db_updated_auction) = db.collection()
|
||||
let (_, db_updated_auction) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&updated_auction)
|
||||
.expect("can set updated auction");
|
||||
@@ -189,7 +206,8 @@ fn main() {
|
||||
.expect("can complete sale");
|
||||
|
||||
// Save the updated listing
|
||||
let (_, db_completed_fixed_price) = db.collection()
|
||||
let (_, db_completed_fixed_price) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&completed_fixed_price)
|
||||
.expect("can set completed listing");
|
||||
@@ -204,14 +222,15 @@ fn main() {
|
||||
// Store the bidder_id and amount before moving db_updated_auction
|
||||
let bidder_id = db_updated_auction.highest_bid().unwrap().bidder_id;
|
||||
let amount = db_updated_auction.highest_bid().unwrap().amount;
|
||||
|
||||
|
||||
// Now complete the sale
|
||||
let completed_auction = db_updated_auction
|
||||
.complete_sale(bidder_id.to_string(), amount)
|
||||
.expect("can complete auction");
|
||||
|
||||
// Save the updated auction listing
|
||||
let (_, db_completed_auction) = db.collection()
|
||||
let (_, db_completed_auction) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&completed_auction)
|
||||
.expect("can set completed auction");
|
||||
@@ -223,12 +242,11 @@ fn main() {
|
||||
println!("\n--- Cancelling a Listing ---");
|
||||
|
||||
// Cancel the exchange listing
|
||||
let cancelled_exchange = db_exchange
|
||||
.cancel()
|
||||
.expect("can cancel listing");
|
||||
let cancelled_exchange = db_exchange.cancel().expect("can cancel listing");
|
||||
|
||||
// Save the updated listing
|
||||
let (_, db_cancelled_exchange) = db.collection()
|
||||
let (_, db_cancelled_exchange) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&cancelled_exchange)
|
||||
.expect("can set cancelled listing");
|
||||
@@ -256,7 +274,8 @@ fn main() {
|
||||
);
|
||||
|
||||
// Save the expired listing
|
||||
let (expired_id, db_expired) = db.collection()
|
||||
let (expired_id, db_expired) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&expired_listing)
|
||||
.expect("can set expired listing");
|
||||
@@ -267,7 +286,8 @@ fn main() {
|
||||
let checked_expired = db_expired.check_expiration();
|
||||
|
||||
// Save the checked listing
|
||||
let (_, db_checked_expired) = db.collection()
|
||||
let (_, db_checked_expired) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&checked_expired)
|
||||
.expect("can set checked listing");
|
||||
@@ -295,7 +315,8 @@ fn main() {
|
||||
);
|
||||
|
||||
// Save the listing
|
||||
let (update_id, db_to_update) = db.collection()
|
||||
let (update_id, db_to_update) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&listing_to_update)
|
||||
.expect("can set listing to update");
|
||||
@@ -315,7 +336,8 @@ fn main() {
|
||||
.add_tags(vec!["updated".to_string(), "premium".to_string()]);
|
||||
|
||||
// Save the updated listing
|
||||
let (_, db_updated_listing) = db.collection()
|
||||
let (_, db_updated_listing) = db
|
||||
.collection()
|
||||
.expect("can open listing collection")
|
||||
.set(&updated_listing)
|
||||
.expect("can set updated listing");
|
||||
|
@@ -19,7 +19,7 @@ fn main() {
|
||||
"Test User".to_string(),
|
||||
"test@example.com".to_string(),
|
||||
);
|
||||
|
||||
|
||||
println!(" Signer created: {}", signer.name);
|
||||
println!(" Last reminder: {:?}", signer.last_reminder_mail_sent_at);
|
||||
assert_eq!(signer.last_reminder_mail_sent_at, None);
|
||||
@@ -44,7 +44,10 @@ fn main() {
|
||||
println!("Test 4: Mark reminder as sent");
|
||||
signer.mark_reminder_sent(current_time);
|
||||
println!(" Reminder marked as sent at: {}", current_time);
|
||||
println!(" Last reminder timestamp: {:?}", signer.last_reminder_mail_sent_at);
|
||||
println!(
|
||||
" Last reminder timestamp: {:?}",
|
||||
signer.last_reminder_mail_sent_at
|
||||
);
|
||||
assert_eq!(signer.last_reminder_mail_sent_at, Some(current_time));
|
||||
println!(" ✓ Reminder timestamp updated correctly\n");
|
||||
|
||||
@@ -86,9 +89,15 @@ fn main() {
|
||||
.comments("Test signer with reminder");
|
||||
|
||||
println!(" Signer: {}", signer_with_reminder.name);
|
||||
println!(" Last reminder: {:?}", signer_with_reminder.last_reminder_mail_sent_at);
|
||||
println!(" Can send reminder: {}", signer_with_reminder.can_send_reminder(current_time));
|
||||
|
||||
println!(
|
||||
" Last reminder: {:?}",
|
||||
signer_with_reminder.last_reminder_mail_sent_at
|
||||
);
|
||||
println!(
|
||||
" Can send reminder: {}",
|
||||
signer_with_reminder.can_send_reminder(current_time)
|
||||
);
|
||||
|
||||
let remaining = signer_with_reminder.reminder_cooldown_remaining(current_time);
|
||||
println!(" Cooldown remaining: {:?} seconds", remaining);
|
||||
assert_eq!(remaining, Some(10 * 60)); // 10 minutes remaining
|
||||
@@ -97,8 +106,14 @@ fn main() {
|
||||
// Test 9: Test clear reminder timestamp
|
||||
println!("Test 9: Clear reminder timestamp");
|
||||
let cleared_signer = signer_with_reminder.clear_last_reminder_mail_sent_at();
|
||||
println!(" Last reminder after clear: {:?}", cleared_signer.last_reminder_mail_sent_at);
|
||||
println!(" Can send reminder: {}", cleared_signer.can_send_reminder(current_time));
|
||||
println!(
|
||||
" Last reminder after clear: {:?}",
|
||||
cleared_signer.last_reminder_mail_sent_at
|
||||
);
|
||||
println!(
|
||||
" Can send reminder: {}",
|
||||
cleared_signer.can_send_reminder(current_time)
|
||||
);
|
||||
assert_eq!(cleared_signer.last_reminder_mail_sent_at, None);
|
||||
assert!(cleared_signer.can_send_reminder(current_time));
|
||||
println!(" ✓ Clear reminder timestamp works correctly\n");
|
||||
|
@@ -11,7 +11,7 @@ fn main() {
|
||||
"Test User".to_string(),
|
||||
"test@example.com".to_string(),
|
||||
);
|
||||
|
||||
|
||||
println!(" Signer created: {}", signer.name);
|
||||
println!(" Status: {:?}", signer.status);
|
||||
println!(" Signature data: {:?}", signer.signature_data);
|
||||
@@ -23,14 +23,17 @@ fn main() {
|
||||
println!("Test 2: Sign with signature data");
|
||||
let signature_data = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==".to_string();
|
||||
let comments = "I agree to all terms and conditions.".to_string();
|
||||
|
||||
|
||||
signer.sign(Some(signature_data.clone()), Some(comments.clone()));
|
||||
|
||||
|
||||
println!(" Status after signing: {:?}", signer.status);
|
||||
println!(" Signed at: {:?}", signer.signed_at);
|
||||
println!(" Comments: {:?}", signer.comments);
|
||||
println!(" Signature data length: {}", signer.signature_data.as_ref().unwrap().len());
|
||||
|
||||
println!(
|
||||
" Signature data length: {}",
|
||||
signer.signature_data.as_ref().unwrap().len()
|
||||
);
|
||||
|
||||
assert_eq!(signer.status, SignerStatus::Signed);
|
||||
assert!(signer.signed_at.is_some());
|
||||
assert_eq!(signer.signature_data, Some(signature_data));
|
||||
@@ -44,13 +47,16 @@ fn main() {
|
||||
"Test User 2".to_string(),
|
||||
"test2@example.com".to_string(),
|
||||
);
|
||||
|
||||
signer2.sign(None, Some("Electronic signature without visual data".to_string()));
|
||||
|
||||
|
||||
signer2.sign(
|
||||
None,
|
||||
Some("Electronic signature without visual data".to_string()),
|
||||
);
|
||||
|
||||
println!(" Status: {:?}", signer2.status);
|
||||
println!(" Signature data: {:?}", signer2.signature_data);
|
||||
println!(" Comments: {:?}", signer2.comments);
|
||||
|
||||
|
||||
assert_eq!(signer2.status, SignerStatus::Signed);
|
||||
assert_eq!(signer2.signature_data, None);
|
||||
assert!(signer2.comments.is_some());
|
||||
@@ -63,13 +69,13 @@ fn main() {
|
||||
"Test User 3".to_string(),
|
||||
"test3@example.com".to_string(),
|
||||
);
|
||||
|
||||
|
||||
signer3.sign(None, None);
|
||||
|
||||
|
||||
println!(" Status: {:?}", signer3.status);
|
||||
println!(" Signature data: {:?}", signer3.signature_data);
|
||||
println!(" Comments: {:?}", signer3.comments);
|
||||
|
||||
|
||||
assert_eq!(signer3.status, SignerStatus::Signed);
|
||||
assert_eq!(signer3.signature_data, None);
|
||||
assert_eq!(signer3.comments, None);
|
||||
@@ -88,16 +94,25 @@ fn main() {
|
||||
|
||||
println!(" Signer: {}", signer_with_signature.name);
|
||||
println!(" Status: {:?}", signer_with_signature.status);
|
||||
println!(" Signature data: {:?}", signer_with_signature.signature_data);
|
||||
println!(
|
||||
" Signature data: {:?}",
|
||||
signer_with_signature.signature_data
|
||||
);
|
||||
println!(" Comments: {:?}", signer_with_signature.comments);
|
||||
|
||||
assert_eq!(signer_with_signature.signature_data, Some("data:image/png;base64,example".to_string()));
|
||||
|
||||
assert_eq!(
|
||||
signer_with_signature.signature_data,
|
||||
Some("data:image/png;base64,example".to_string())
|
||||
);
|
||||
println!(" ✓ Builder pattern with signature data works correctly\n");
|
||||
|
||||
// Test 6: Clear signature data
|
||||
println!("Test 6: Clear signature data");
|
||||
let cleared_signer = signer_with_signature.clear_signature_data();
|
||||
println!(" Signature data after clear: {:?}", cleared_signer.signature_data);
|
||||
println!(
|
||||
" Signature data after clear: {:?}",
|
||||
cleared_signer.signature_data
|
||||
);
|
||||
assert_eq!(cleared_signer.signature_data, None);
|
||||
println!(" ✓ Clear signature data works correctly\n");
|
||||
|
||||
@@ -114,14 +129,24 @@ fn main() {
|
||||
// Serialize to JSON
|
||||
let json = serde_json::to_string(&original_signer).expect("Failed to serialize");
|
||||
println!(" Serialized JSON length: {} characters", json.len());
|
||||
|
||||
|
||||
// Deserialize from JSON
|
||||
let deserialized_signer: ContractSigner = serde_json::from_str(&json).expect("Failed to deserialize");
|
||||
|
||||
println!(" Original signature data: {:?}", original_signer.signature_data);
|
||||
println!(" Deserialized signature data: {:?}", deserialized_signer.signature_data);
|
||||
|
||||
assert_eq!(original_signer.signature_data, deserialized_signer.signature_data);
|
||||
let deserialized_signer: ContractSigner =
|
||||
serde_json::from_str(&json).expect("Failed to deserialize");
|
||||
|
||||
println!(
|
||||
" Original signature data: {:?}",
|
||||
original_signer.signature_data
|
||||
);
|
||||
println!(
|
||||
" Deserialized signature data: {:?}",
|
||||
deserialized_signer.signature_data
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
original_signer.signature_data,
|
||||
deserialized_signer.signature_data
|
||||
);
|
||||
assert_eq!(original_signer.name, deserialized_signer.name);
|
||||
assert_eq!(original_signer.email, deserialized_signer.email);
|
||||
println!(" ✓ Serialization/Deserialization works correctly\n");
|
||||
@@ -138,17 +163,21 @@ fn main() {
|
||||
"comments": null,
|
||||
"last_reminder_mail_sent_at": null
|
||||
}"#;
|
||||
|
||||
let old_signer: ContractSigner = serde_json::from_str(old_json).expect("Failed to deserialize old format");
|
||||
|
||||
let old_signer: ContractSigner =
|
||||
serde_json::from_str(old_json).expect("Failed to deserialize old format");
|
||||
println!(" Old signer name: {}", old_signer.name);
|
||||
println!(" Old signer signature data: {:?}", old_signer.signature_data);
|
||||
|
||||
println!(
|
||||
" Old signer signature data: {:?}",
|
||||
old_signer.signature_data
|
||||
);
|
||||
|
||||
assert_eq!(old_signer.signature_data, None);
|
||||
println!(" ✓ Backward compatibility works correctly\n");
|
||||
|
||||
println!("All tests passed! ✅");
|
||||
println!("ContractSigner signature functionality is working correctly.");
|
||||
|
||||
|
||||
// Summary
|
||||
println!("\n📋 Summary of Features Tested:");
|
||||
println!(" ✅ New signer creation (signature_data: None)");
|
||||
|
Reference in New Issue
Block a user