Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/admin_take_dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ pub async fn admin_take_dispute_action(
// Get order from db using the dispute order id
let order = if let Some(order) = Order::by_id(pool, dispute.order_id)
.await
.map_err(|_| MostroInternalErr(ServiceError::InvalidOrderId))?
.map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?
{
order
} else {
return Err(MostroInternalErr(ServiceError::InvalidOrderId));
return Err(MostroCantDo(CantDoReason::NotFound));
};

// Update dispute fields
Expand Down
2 changes: 1 addition & 1 deletion src/app/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub async fn dispute_action(
let order_id = if let Some(order_id) = msg.get_inner_message_kind().id {
order_id
} else {
return Err(MostroInternalErr(ServiceError::InvalidOrderId));
return Err(MostroCantDo(CantDoReason::NotFound));
};
// Check dispute for this order id is yet present.
if find_dispute_by_order_id(pool, order_id).await.is_ok() {
Expand Down
65 changes: 61 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,16 +1168,14 @@ pub async fn get_dispute(msg: &Message, pool: &Pool<Sqlite>) -> Result<Dispute,

pub async fn get_order(msg: &Message, pool: &Pool<Sqlite>) -> Result<Order, MostroError> {
let order_msg = msg.get_inner_message_kind();
let order_id = order_msg
.id
.ok_or(MostroInternalErr(ServiceError::InvalidOrderId))?;
let order_id = order_msg.id.ok_or(MostroCantDo(CantDoReason::NotFound))?;
let order = Order::by_id(pool, order_id)
.await
.map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?;
if let Some(order) = order {
Ok(order)
} else {
Err(MostroInternalErr(ServiceError::InvalidOrderId))
Err(MostroCantDo(CantDoReason::NotFound))
}
}

Expand Down Expand Up @@ -1585,6 +1583,65 @@ mod tests {
assert!(orders.is_empty());
}

#[tokio::test]
async fn test_get_order_returns_not_found_when_id_missing() {
initialize();
let pool = setup_orders_pool().await;
let message = Message::Order(MessageKind::new(
None,
None,
None,
Action::AdminSettle,
None,
));

let err = get_order(&message, &pool).await.unwrap_err();
assert!(matches!(
err,
MostroError::MostroCantDo(CantDoReason::NotFound)
));
}

#[tokio::test]
async fn test_get_order_returns_not_found_when_order_absent() {
initialize();
let pool = setup_orders_pool().await;
let missing_id = Uuid::new_v4();
let message = Message::Order(MessageKind::new(
Some(missing_id),
None,
None,
Action::AdminSettle,
None,
));

let err = get_order(&message, &pool).await.unwrap_err();
assert!(matches!(
err,
MostroError::MostroCantDo(CantDoReason::NotFound)
));
}

#[tokio::test]
async fn test_get_order_returns_order_when_found() {
initialize();
let pool = setup_orders_pool().await;
let user_pubkey = "a".repeat(64);
let order_id = Uuid::new_v4();
insert_order(&pool, order_id, Some(&user_pubkey), None, &user_pubkey).await;

let message = Message::Order(MessageKind::new(
Some(order_id),
None,
None,
Action::AdminSettle,
None,
));

let order = get_order(&message, &pool).await.unwrap();
assert_eq!(order.id, order_id);
}

#[test]
fn test_get_dev_fee_basic() {
// 1000 sats Mostro fee at 30% -> 300 sats
Expand Down