Vereinfacht client: email normalization, multi-match warning, Bypass tests, doc note
- Normalize email (trim + downcase) before filter lookup - Log warning when API returns multiple contacts for same email - Add Bypass tests for find_contact_by_email (query params, empty/single response parsing) - Document vereinfacht_required_field? as legacy/unused in vereinfacht-api.md - Add bypass dependency (dev+test) for HTTP stubbing
This commit is contained in:
parent
9f169b9835
commit
01b9ebd74b
5 changed files with 100 additions and 7 deletions
|
|
@ -183,8 +183,9 @@ defmodule Mv.Vereinfacht.Client do
|
|||
end
|
||||
|
||||
defp do_find_contact_by_email(email) do
|
||||
normalized_email = email |> String.trim() |> String.downcase()
|
||||
base = base_url() |> String.trim_trailing("/") |> then(&"#{&1}/finance-contacts")
|
||||
encoded_email = URI.encode_www_form(email |> String.trim())
|
||||
encoded_email = URI.encode_www_form(normalized_email)
|
||||
url = "#{base}?filter[isExternal]=true&filter[email]=#{encoded_email}"
|
||||
|
||||
case Req.get(url, [headers: headers(api_key())] ++ req_http_options()) do
|
||||
|
|
@ -202,11 +203,19 @@ defmodule Mv.Vereinfacht.Client do
|
|||
end
|
||||
end
|
||||
|
||||
defp get_first_contact_id_from_list(%{"data" => [%{"id" => id} | _]}) do
|
||||
normalize_contact_id(id)
|
||||
defp get_first_contact_id_from_list(%{"data" => data} = _body) when is_list(data) do
|
||||
if length(data) > 1 do
|
||||
Logger.warning(
|
||||
"Vereinfacht find_contact_by_email: API returned multiple contacts for same email (count: #{length(data)}), using first. Check for duplicate or inconsistent data."
|
||||
)
|
||||
end
|
||||
|
||||
case data do
|
||||
[%{"id" => id} | _] -> normalize_contact_id(id)
|
||||
[] -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp get_first_contact_id_from_list(%{"data" => []}), do: nil
|
||||
defp get_first_contact_id_from_list(_), do: nil
|
||||
|
||||
defp normalize_contact_id(id) when is_binary(id), do: id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue