Skip to content

Commit 61dddb1

Browse files
committed
feat: add conformance test for 'requires_escalation' via risk signals
Why: - To verify that the server correctly implements the 'requires_escalation' status when risk checks fail during completion. - Ensures conformance with the checkout status lifecycle. What: - Added 'test_escalation_flow' to 'CheckoutLifecycleTest'. - Triggers escalation by sending 'simulation_trigger': 'escalation_required' in 'risk_signals' during 'complete_checkout'. - Asserts that status becomes 'requires_escalation' and 'continue_url' is present.
1 parent 0905946 commit 61dddb1

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

checkout_lifecycle_test.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,46 @@ def test_cannot_cancel_completed_checkout(self):
413413
msg="Should not be able to cancel a completed checkout.",
414414
)
415415

416+
def test_escalation_flow(self):
417+
"""Test checkout escalation flow.
418+
419+
Given a checkout session,
420+
When completion is attempted with a risk signal triggering escalation,
421+
Then the status should be 'requires_escalation' and continue_url should be
422+
present.
423+
"""
424+
response_json = self.create_checkout_session()
425+
checkout_obj = checkout.Checkout(**response_json)
426+
checkout_id = checkout_obj.id
427+
428+
# Complete with risk signal
429+
payment_payload = integration_test_utils.get_valid_payment_payload()
430+
payment_payload["risk_signals"] = {
431+
"simulation_trigger": "escalation_required"
432+
}
433+
434+
response = self.client.post(
435+
f"/checkout-sessions/{checkout_id}/complete",
436+
json=payment_payload,
437+
headers=integration_test_utils.get_headers(),
438+
)
439+
440+
self.assert_response_status(response, 200)
441+
updated_checkout = checkout.Checkout(**response.json())
442+
443+
self.assertEqual(
444+
updated_checkout.status,
445+
"requires_escalation",
446+
msg="Status should be requires_escalation",
447+
)
448+
self.assertIsNotNone(
449+
updated_checkout.continue_url, "continue_url should be present"
450+
)
451+
self.assertTrue(updated_checkout.messages, "Messages should be present")
452+
self.assertEqual(
453+
updated_checkout.messages[0].root.severity, "requires_buyer_input"
454+
)
455+
416456

417457
if __name__ == "__main__":
418458
absltest.main()

0 commit comments

Comments
 (0)