fix: serialize mobile presign conversion amounts.
This commit is contained in:
1 parent
e0dc7f4cee
commit
54ec8e1cd1
2 files changed
+84
-1
No files matched your search
@@ -740,13 +740,19 @@ def convert_presign_order(
|
||||
sales_user_id=row.sales_user_id,
|
||||
region_manager_user_id=row.region_manager_user_id,
|
||||
)
|
||||
return presign_crud.convert_to_protocol(
|
||||
result = presign_crud.convert_to_protocol(
|
||||
db,
|
||||
order_id=order_id,
|
||||
tenant_no=ctx.tenant_no,
|
||||
user_id=ctx.user_id,
|
||||
create_dept_id=_current_dept_id(user_info),
|
||||
)
|
||||
if isinstance(result.get('presignOrder'), dict):
|
||||
result = dict(result)
|
||||
result['presignOrder'] = _mobile_order_to_dict(
|
||||
db, row, ctx.tenant_no, with_children=True
|
||||
)
|
||||
return result
|
||||
except Exception:
|
||||
db.rollback()
|
||||
raise
|
||||
@@ -2304,3 +2304,80 @@ process.stdout.write(JSON.stringify(values.map(formatPresignMoney)))
|
||||
'-',
|
||||
'¥0.00',
|
||||
]
|
||||
|
||||
|
||||
def test_mobile_presign_convert_response_preserves_decimal_for_presenter(
|
||||
monkeypatch,
|
||||
):
|
||||
import json
|
||||
import subprocess
|
||||
from decimal import Decimal
|
||||
from pathlib import Path
|
||||
|
||||
from app.crud import presign_order as presign_crud
|
||||
from app.services import market_presign
|
||||
|
||||
db = _session()
|
||||
_add_master_data(db)
|
||||
db.commit()
|
||||
maximum = Decimal('9999999999999999.99')
|
||||
order = _order('convert-money', sales_user_id='u1')
|
||||
order.protocol_no = 'P-CONVERT-MONEY'
|
||||
order.contract_amount = maximum
|
||||
|
||||
monkeypatch.setattr(
|
||||
market_presign,
|
||||
'_scoped_order_for_update',
|
||||
lambda *_args, **_kwargs: order,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
presign_crud,
|
||||
'_get_order_or_raise',
|
||||
lambda *_args, **_kwargs: order,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
presign_crud,
|
||||
'confirmed_deposit_amount',
|
||||
lambda *_args, **_kwargs: maximum,
|
||||
)
|
||||
# SQLite binds Numeric through float. Keep the exact Decimal on the real ORM
|
||||
# instance while exercising the complete core conversion and mobile response.
|
||||
monkeypatch.setattr(db, 'commit', db.flush)
|
||||
monkeypatch.setattr(db, 'refresh', lambda *_args, **_kwargs: None)
|
||||
|
||||
response = market_presign.convert_presign_order(
|
||||
db,
|
||||
order_id=order.id,
|
||||
ctx=_ctx('specialist'),
|
||||
user_info=_user(),
|
||||
)
|
||||
nested = response['presignOrder']
|
||||
assert response['protocolId']
|
||||
assert order.order_status == 'converted'
|
||||
assert nested['contractAmount'] == str(maximum)
|
||||
assert nested['confirmedDepositAmount'] == str(maximum)
|
||||
|
||||
presenter_url = (
|
||||
Path(__file__).resolve().parents[2]
|
||||
/ 'mobile-oa-h5/src/market/presign/presign-presenter.js'
|
||||
).as_uri()
|
||||
script = """
|
||||
import fs from 'node:fs'
|
||||
const { formatPresignMoney } = await import(process.argv[1])
|
||||
const dto = JSON.parse(fs.readFileSync(0, 'utf8'))
|
||||
process.stdout.write(JSON.stringify([
|
||||
formatPresignMoney(dto.contractAmount),
|
||||
formatPresignMoney(dto.confirmedDepositAmount)
|
||||
]))
|
||||
"""
|
||||
formatted = subprocess.run(
|
||||
['node', '--input-type=module', '-e', script, presenter_url],
|
||||
input=json.dumps(nested),
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
assert json.loads(formatted.stdout) == [
|
||||
'¥9,999,999,999,999,999.99',
|
||||
'¥9,999,999,999,999,999.99',
|
||||
]
|
||||
Reference in new issue
Block a user