Skip to content

Commit

Permalink
Add more types required for Colombia (#15)
Browse files Browse the repository at this point in the history
These types are required for clients validation
  • Loading branch information
erickgnavar authored Jul 7, 2023
1 parent f5c469d commit 3678809
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/bali.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Bali do

@personal_documents %{
mx: ["curp"],
co: ["cc", "ce"],
co: ["cc", "ce", "passport", "password"],
es: ["dni", "nie"],
it: ["cie", "cf"],
pt: ["nif"],
Expand Down Expand Up @@ -157,7 +157,7 @@ defmodule Bali do
Obtiene la lista de tipos de documentos soportados
"""
def get_document_types do
["DNI", "NIE", "NIF", "RFC", "CURP", "CC", "CE", "NIT", "CPF", "CNPJ"]
["DNI", "NIE", "NIF", "RFC", "CURP", "CC", "CE", "NIT", "CPF", "CNPJ", "PASSPORT", "PASSWORD"]
end

@doc """
Expand Down
11 changes: 11 additions & 0 deletions lib/validators/colombia.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ defmodule Bali.Validators.Colombia do
end
end

def validate(:passport, value) do
# we don't have a way to validate a passport, every country has its own format
{:ok, value}
end

def validate(:password, value) do
# this is a temporal document that it will be converted into a CC
# the number will be the same so we can reuse the regex
validate(:cc, value)
end

def validate(_, _) do
{:error, "Tipo de documento inválido"}
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Bali.MixProject do
def project do
[
app: :bali,
version: "0.3.0",
version: "0.4.0",
description: "Validate personal and tax identifiers for mx, co, es, pt, it, br",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
Expand Down
5 changes: 5 additions & 0 deletions test/validators/colombia_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ defmodule Validators.ColombiaTest do
assert {:error, "Tipo de documento inválido"} ==
Colombia.validate(:ab, "12345678A")
end

test "Validate a correct passport number" do
value = "AT386158"
assert {:ok, value} == Colombia.validate(:passport, value)
end
end

0 comments on commit 3678809

Please sign in to comment.