fix: acknowledge signed payment notice before querying provider
This commit is contained in:
@@ -133,26 +133,30 @@ def test_huihui_org_callback_verifies_provider_before_granting_points(authorizat
|
||||
pending = send(payload, callback_path=legacy_path)
|
||||
assert pending.status_code == 200
|
||||
assert pending.json()["data"] == {"received": True, "paid": False, "awaitingProvider": True}
|
||||
provider.get_order.assert_not_called()
|
||||
db = SessionLocal()
|
||||
try:
|
||||
assert db.get(HuihuiOrgPaymentNotice, order_no).status == "awaiting_provider"
|
||||
assert db.query(TokenPaymentOrder).filter(TokenPaymentOrder.order_no == order_no).one().status == "pending"
|
||||
finally:
|
||||
db.close()
|
||||
provider.get_order.return_value = {**provider_data, "payStatus": 2}
|
||||
assert send({**payload, "paymentNo": "wrong"}).status_code == 409
|
||||
provider.get_order.return_value = {**provider_data, "payStatus": 2, "chargeAmount": 2}
|
||||
assert send(payload).status_code == 422
|
||||
provider.get_order.return_value = {**provider_data, "payStatus": 2}
|
||||
db = SessionLocal()
|
||||
try:
|
||||
notice = db.get(HuihuiOrgPaymentNotice, order_no)
|
||||
notice.next_check_at = datetime.utcnow() - timedelta(seconds=1)
|
||||
db.commit()
|
||||
from routers.tokens import reconcile_huihui_org_notices
|
||||
provider.get_order.return_value = {**provider_data, "payStatus": 2, "chargeAmount": 2}
|
||||
assert reconcile_huihui_org_notices(db) == 0
|
||||
assert db.get(HuihuiOrgPaymentNotice, order_no).status == "rejected"
|
||||
assert db.query(TokenPaymentOrder).filter(TokenPaymentOrder.order_no == order_no).one().status == "pending"
|
||||
assert send(payload).status_code == 200
|
||||
notice.next_check_at = datetime.utcnow() - timedelta(seconds=1)
|
||||
db.commit()
|
||||
provider.get_order.return_value = provider_data
|
||||
assert reconcile_huihui_org_notices(db) == 0
|
||||
assert db.get(HuihuiOrgPaymentNotice, order_no).attempts == 2
|
||||
assert db.get(HuihuiOrgPaymentNotice, order_no).attempts == 1
|
||||
assert db.query(TokenPaymentOrder).filter(TokenPaymentOrder.order_no == order_no).one().status == "pending"
|
||||
notice.next_check_at = datetime.utcnow() - timedelta(seconds=1)
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user