Added source and destination accounts.
This commit is contained in:
@@ -109,6 +109,8 @@ fn decode(row: RecurringTransactionRow) -> Result<RecurringTransaction, DecodeEr
|
||||
name: row.name,
|
||||
amount: Cents::try_from(row.amount_cents)?,
|
||||
direction: decode_direction(row.direction)?,
|
||||
source_account_id: row.source_account_id,
|
||||
destination_account_id: row.destination_account_id,
|
||||
schedule: Schedule::new(row.starts_at, row.ends_at, recurrence, weekend_adjustment)?,
|
||||
})
|
||||
}
|
||||
@@ -121,6 +123,8 @@ fn encode(transaction: RecurringTransaction) -> RecurringTransactionRow {
|
||||
name: transaction.name,
|
||||
amount_cents: transaction.amount.into(),
|
||||
direction: encode_direction(transaction.direction).to_owned(),
|
||||
source_account_id: transaction.source_account_id,
|
||||
destination_account_id: transaction.destination_account_id,
|
||||
starts_at: transaction.schedule.start(),
|
||||
ends_at: transaction.schedule.end(),
|
||||
recurrence_every: recurrence.every.into(),
|
||||
@@ -146,6 +150,8 @@ mod tests {
|
||||
name: "Rent".to_owned(),
|
||||
amount_cents: 120_000,
|
||||
direction: "out".to_owned(),
|
||||
source_account_id: Some(Uuid::new_v4()),
|
||||
destination_account_id: Some(Uuid::new_v4()),
|
||||
starts_at: Utc.with_ymd_and_hms(2026, 9, 24, 12, 0, 0).unwrap(),
|
||||
ends_at: None,
|
||||
recurrence_every: 1,
|
||||
@@ -157,7 +163,12 @@ mod tests {
|
||||
#[test]
|
||||
fn decodes_valid_rows() {
|
||||
let row = row();
|
||||
let (id, start) = (row.id, row.starts_at);
|
||||
let (id, start, source_account_id, destination_account_id) = (
|
||||
row.id,
|
||||
row.starts_at,
|
||||
row.source_account_id,
|
||||
row.destination_account_id,
|
||||
);
|
||||
let transaction = decode(row).unwrap();
|
||||
let recurrence = transaction.schedule.recurrence();
|
||||
|
||||
@@ -165,6 +176,8 @@ mod tests {
|
||||
assert_eq!(transaction.name, "Rent");
|
||||
assert_eq!(transaction.amount.get(), 120_000);
|
||||
assert_eq!(transaction.direction, Direction::Out);
|
||||
assert_eq!(transaction.source_account_id, source_account_id);
|
||||
assert_eq!(transaction.destination_account_id, destination_account_id);
|
||||
assert_eq!(transaction.schedule.start(), start);
|
||||
assert_eq!(transaction.schedule.end(), None);
|
||||
assert_eq!(recurrence.every.get(), 1);
|
||||
|
||||
Reference in New Issue
Block a user