-
Notifications
You must be signed in to change notification settings - Fork 58
test(dispute): cover CantDo(DisputeCreationError) inconsistent flag path #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -544,6 +544,49 @@ mod tests { | |
| )); | ||
| } | ||
|
|
||
| /// Inconsistent DB state: the initiating side's dispute flag is already set, | ||
| /// but there is no `disputes` row (so the early `DisputeAlreadyExists` guard | ||
| /// does not fire). `setup_dispute` must fail with `DisputeCreationError`, and | ||
| /// no dispute row may be created — the path introduced by #848. | ||
| #[tokio::test] | ||
| async fn dispute_action_returns_dispute_creation_error_when_flag_set_without_dispute_row() { | ||
| let pool = create_test_pool().await; | ||
| let ctx = build_ctx(&pool); | ||
| let buyer = Keys::generate().public_key(); | ||
| let seller = Keys::generate().public_key(); | ||
|
|
||
| let mut order = create_order(Some(buyer), Some(seller), Status::Active); | ||
| order.buyer_dispute = true; | ||
| let order = order.create(&pool).await.unwrap(); | ||
|
|
||
| let event = create_event(buyer); | ||
| let result = dispute_action( | ||
| &ctx, | ||
| dispute_msg_for(Some(order.id)), | ||
| &event, | ||
| &Keys::generate(), | ||
| ) | ||
| .await; | ||
|
|
||
| assert!( | ||
| matches!( | ||
| result, | ||
| Err(MostroCantDo(CantDoReason::DisputeCreationError)) | ||
| ), | ||
| "expected DisputeCreationError, got {result:?}" | ||
| ); | ||
| assert!( | ||
| find_dispute_by_order_id(&pool, order.id).await.is_err(), | ||
| "no dispute row must be created when setup_dispute fails" | ||
| ); | ||
| let stored = Order::by_id(&pool, order.id).await.unwrap().unwrap(); | ||
| assert_eq!( | ||
| stored.status, | ||
| Status::Active.to_string(), | ||
| "order must not move to Dispute when setup_dispute fails" | ||
| ); | ||
|
Comment on lines
+582
to
+587
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Verify all state that must remain unchanged. The test checks only 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| /// Full buyer-initiated flow on an `Active` order. All DB side effects | ||
| /// (order flags/status, dispute row) and both queue notifications happen | ||
| /// before the final Nostr publish, which fails offline (default client | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Use an absence-specific assertion for the dispute row.
find_dispute_by_order_id(...).is_err()also passes for database access or row-decoding failures. The helper insrc/db.rs:555-572maps all query errors toErr, so this test does not prove that no row exists. Query withCOUNT(*)orfetch_optionaland assert0orNone.🤖 Prompt for AI Agents