// Force-expire the most-recent SEARCHING / PENDING_ACCEPTANCE chat_session
// by hitting the dev-only /internal/_test/force-pairing-timeout endpoint.
// Used by ts-mitra-3-06-popup_expires_after_30s.yaml to surface the
// "Permintaan kedaluwarsa" stale-card UX without waiting the real 30s.
//
// Backend (backend/src/routes/internal/_test.routes.js::force-pairing-timeout):
//   - Locates the latest SEARCHING or PENDING_ACCEPTANCE chat_session
//   - For blast pairings: expirePairingRequest(target, NO_MITRA_AVAILABLE)
//   - For targeted pairings: expireTargetedPairingRequest(target)
//   - Either path broadcasts `chat_request_closed` with reason=expired so the
//     mitra-app's chat_request_notifier flips into ChatRequestStaleData(expired)
//
// Writes the pairing kind + session id to output so callers can branch.
const url = BACKEND_INTERNAL_URL || 'http://localhost:3001'
const resp = http.post(`${url}/internal/_test/force-pairing-timeout`, {
  body: JSON.stringify({ latest: true }),
  headers: { 'Content-Type': 'application/json' },
})
if (resp.status !== 200) {
  throw new Error(`force-pairing-timeout failed (${resp.status}): ${resp.body}`)
}
const data = json(resp.body)
output.SESSION_ID = data.session_id
output.PAIRING_KIND = data.kind
