Qonto transaction ids run ~67 chars (<org>-<n>-<n>-transaction-<uuid>) but Dolibarr stores num_payment in varchar(50) (llx_paiement.num_paiement, llx_paiementfourn.num_paiement) — POSTing a payment with the raw id fails HTTP 400 "value too long for type character varying(50)". Parade proven live on the sandbox (2026-07-11): store the UUID suffix (globally unique, ~37 chars). Wise ids (short numerics) are unaffected. Writer side — payment-record.sh strips everything through "transaction-" before POST, announces the normalization on stderr, REFUSES (never truncates) ids still >50 chars after normalization, and emits the normalized num in the output JSON. Reader side — bank-match.sh PASS 0 (exact tx-id, erp#28) now compares BOTH sides in raw AND canonical short form: Qonto feed ids are carried long+short, payment nums are normalized on compare — so nums stored short (the varchar(50) form) and historical long-form nums both keep matching. Wise ids untouched. Proven offline (no credentials, no network, no sandbox/prod writes): - arcodange-bank-reco/tests/run-tests.sh — new bank-match --fixtures offline mode: long feed id ↔ short num, long ↔ long (back-compat), Wise numeric, each Δ+19d outside the ±7d window so only PASS 0 can pair them (exit 0, 3×[tx-id]); plus the empty-num negative (exit 1, 0 matched). - dolibarr-sandbox-write/tests/run-tests.sh — payment-record via a stubbed dol-write.sh (DOL_WRITE hook): long→short in POST body + output JSON, Wise untouched, >50-after-normalization refused BEFORE any POST, citing varchar(50). Both SKILL.md document the canonical short form + the varchar(50) constraint. Co-Authored-By: Claude Fable 5 <[email protected]>
59 lines
3.2 KiB
Bash
Executable File
59 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Offline tests for payment-record.sh's transaction_id normalization — the writer
|
|
# side of the varchar(50) fix (Dolibarr's num_payment columns truncate at 50 chars,
|
|
# Qonto ids run ~67). Uses tests/stub-dol-write.sh via the DOL_WRITE env hook, so
|
|
# NOTHING is written to the sandbox or prod.
|
|
# 1. Long Qonto id → POST carries the UUID suffix; JSON reports it; stderr says so.
|
|
# 2. Wise numeric id → passes through untouched, no normalization notice.
|
|
# 3. Id still >50 chars after normalization → refused BEFORE any POST, error
|
|
# cites varchar(50) (never a silent truncation).
|
|
set -euo pipefail
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PR="${SCRIPT_DIR}/../scripts/payment-record.sh"
|
|
STUB="${SCRIPT_DIR}/stub-dol-write.sh"
|
|
|
|
fail() { echo "FAIL: $*" >&2; exit 1; }
|
|
|
|
bash -n "${PR}" || fail "bash -n payment-record.sh"
|
|
bash -n "${STUB}" || fail "bash -n stub-dol-write.sh"
|
|
|
|
STATE="$(mktemp -d -t prtest.XXXXXX)"
|
|
trap 'rm -rf "${STATE}"' EXIT
|
|
|
|
LONG="arcodange-1246-1-transaction-019f14c5-e254-7ac9-9e9f-307ed9-d55f44"
|
|
SHORT="019f14c5-e254-7ac9-9e9f-307ed9-d55f44"
|
|
|
|
# --- Case 1: long Qonto id is normalized to the UUID suffix ---
|
|
OUT="$(printf '{"invoice_id":13,"kind":"supplier","account_id":1,"amount":96,"transaction_id":"%s"}' "${LONG}" \
|
|
| DOL_WRITE="${STUB}" STUB_STATE="${STATE}" bash "${PR}" 2>"${STATE}/stderr1")" \
|
|
|| fail "long-qonto-id: expected success, got $?"
|
|
grep -q "\"num_payment\": \"${SHORT}\"" "${STATE}/post_body.json" \
|
|
|| fail "long-qonto-id: POST body must carry the SHORT num, got: $(cat "${STATE}/post_body.json")"
|
|
python3 -c "
|
|
import json, sys
|
|
o = json.loads('''${OUT}''')
|
|
assert o['transaction_id'] == '${SHORT}', o
|
|
assert o['id'] == 77 and o['bank_transaction_id'] == 556, o
|
|
" || fail "long-qonto-id: output JSON must report the normalized num, got: ${OUT}"
|
|
grep -q 'normalized' "${STATE}/stderr1" || fail "long-qonto-id: normalization must be announced on stderr"
|
|
|
|
# --- Case 2: Wise numeric id passes through unchanged ---
|
|
OUT="$(printf '{"invoice_id":19,"account_id":2,"transaction_id":"2159468139"}' \
|
|
| DOL_WRITE="${STUB}" STUB_STATE="${STATE}" bash "${PR}" 2>"${STATE}/stderr2")" \
|
|
|| fail "wise-id: expected success, got $?"
|
|
grep -q '"num_payment": "2159468139"' "${STATE}/post_body.json" \
|
|
|| fail "wise-id: POST body must carry the id untouched"
|
|
grep -q 'normalized' "${STATE}/stderr2" && fail "wise-id: must NOT announce a normalization"
|
|
|
|
# --- Case 3: >50 chars after normalization is refused before any POST ---
|
|
rm -f "${STATE}/post_body.json" "${STATE}/post_endpoint"
|
|
BAD="qonto-migration-batch-7-payment-reference-0123456789-0123456789" # 63 chars, no "transaction-"
|
|
rc=0
|
|
printf '{"invoice_id":13,"kind":"supplier","account_id":1,"amount":96,"transaction_id":"%s"}' "${BAD}" \
|
|
| DOL_WRITE="${STUB}" STUB_STATE="${STATE}" bash "${PR}" >/dev/null 2>"${STATE}/stderr3" || rc=$?
|
|
[[ "${rc}" -ne 0 ]] || fail "overlong-id: must exit non-zero"
|
|
[[ ! -f "${STATE}/post_body.json" ]] || fail "overlong-id: must refuse BEFORE any POST"
|
|
grep -q 'varchar(50)' "${STATE}/stderr3" || fail "overlong-id: error must cite the varchar(50) constraint"
|
|
|
|
echo "OK: payment-record normalization tests passed (long→short, wise untouched, >50 refused pre-POST)"
|