|
|
@@ -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',
|
|
|
+ ]
|