From 5a011614507def76652777ebd0c9e30e379ddcfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Enrique=20Aguilar=20D=C3=ADaz?= <38533197+CevaMenelao@users.noreply.github.com> Date: Wed, 8 Nov 2023 17:34:48 -0600 Subject: [PATCH] Support for 7 digit as valid CE (#17) Legally we have no restriction on the length of the immigration ID number. At the moment it is only required to validate that it has 6 or 7 digits --- lib/bali.ex | 2 +- lib/validators/colombia.ex | 2 +- mix.exs | 2 +- test/bali_test.exs | 2 +- test/validators/colombia_test.exs | 7 ++++++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/bali.ex b/lib/bali.ex index 61e7307..e710641 100644 --- a/lib/bali.ex +++ b/lib/bali.ex @@ -61,7 +61,7 @@ defmodule Bali do iex> Bali.validate(:co, :ce, "123456") {:ok, "123456"} - iex> Bali.validate(:co, :ce, "1234567") + iex> Bali.validate(:co, :ce, "12345678") {:error, "CE inválida"} iex> Bali.validate(:co, :nit, "123456-1") diff --git a/lib/validators/colombia.ex b/lib/validators/colombia.ex index 35ebe2d..59b758c 100644 --- a/lib/validators/colombia.ex +++ b/lib/validators/colombia.ex @@ -83,7 +83,7 @@ defmodule Bali.Validators.Colombia do # Su estructura es un bloque de 6 dígitos @spec ce() :: Regex.t() defp ce do - ~r/^\d{6}$/ + ~r/^\d{6,7}$/ end # Expresión regular para validar una NIT diff --git a/mix.exs b/mix.exs index 9bd0cc3..136b07c 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Bali.MixProject do def project do [ app: :bali, - version: "0.4.0", + version: "0.4.1", description: "Validate personal and tax identifiers for mx, co, es, pt, it, br", elixir: "~> 1.9", start_permanent: Mix.env() == :prod, diff --git a/test/bali_test.exs b/test/bali_test.exs index 9a1e741..8be9931 100644 --- a/test/bali_test.exs +++ b/test/bali_test.exs @@ -68,7 +68,7 @@ defmodule BaliTest do end test "Puedo validar que el identificador CE(Cédula de Extranjería) de Colombia no es correcto" do - value = "1234567" + value = "12345678" assert {:error, "CE inválida"} == Bali.validate(:co, :ce, value) end diff --git a/test/validators/colombia_test.exs b/test/validators/colombia_test.exs index ea7cc28..7ed7b5a 100644 --- a/test/validators/colombia_test.exs +++ b/test/validators/colombia_test.exs @@ -38,8 +38,13 @@ defmodule Validators.ColombiaTest do assert {:ok, value} == Colombia.validate(:ce, value) end - test "Puedo verificar que la CE es inválida a 7 dígitos" do + test "Puedo validar que la CE es correcta a 7 dígitos" do value = "1234567" + assert {:ok, value} == Colombia.validate(:ce, value) + end + + test "Puedo verificar que la CE es inválida a 8 dígitos" do + value = "12345678" assert {:error, "CE inválida"} == Colombia.validate(:ce, value) end