Skip to content

Commit ee87068

Browse files
test: add test for cancel_payout
1 parent c8722ff commit ee87068

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/payout/entity.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,58 @@ impl TryFrom<EntityEvents<PayoutEvent>> for Payout {
166166
builder.events(events).build()
167167
}
168168
}
169+
170+
#[cfg(test)]
171+
mod tests {
172+
use rust_decimal::Decimal;
173+
174+
use super::*;
175+
176+
fn mock_payout() -> Payout {
177+
Payout {
178+
id: uuid::Uuid::new_v4().into(),
179+
wallet_id: uuid::Uuid::new_v4().into(),
180+
profile_id: uuid::Uuid::new_v4().into(),
181+
payout_queue_id: uuid::Uuid::new_v4().into(),
182+
batch_id: None,
183+
outpoint: None,
184+
satoshis: Satoshis::from(Decimal::from(21)),
185+
destination: PayoutDestination::OnchainAddress {
186+
value: "bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej"
187+
.parse()
188+
.unwrap(),
189+
},
190+
external_id: String::from("test_external_id"),
191+
metadata: None,
192+
events: EntityEvents::new(),
193+
}
194+
}
195+
196+
#[test]
197+
fn errors_when_payout_already_cancelled() {
198+
let mut payout = mock_payout();
199+
payout.events.push(PayoutEvent::Cancelled {
200+
executed_by: payout.profile_id,
201+
});
202+
203+
let result = payout.cancel_payout(payout.profile_id);
204+
assert!(matches!(result, Err(PayoutError::PayoutAlreadyCancelled)));
205+
}
206+
207+
#[test]
208+
fn errors_when_payout_already_committed() {
209+
let mut payout = mock_payout();
210+
payout.batch_id = Some(uuid::Uuid::new_v4().into());
211+
212+
let result = payout.cancel_payout(payout.profile_id);
213+
assert!(matches!(result, Err(PayoutError::PayoutAlreadyCommitted)));
214+
}
215+
216+
#[test]
217+
fn cancel_payout_success() {
218+
let mut payout = mock_payout();
219+
220+
let result = payout.cancel_payout(payout.profile_id);
221+
assert!(result.is_ok());
222+
}
223+
}

0 commit comments

Comments
 (0)