Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Função codPostalVal() implementada #16

Merged
merged 1 commit into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions __tests__/valPT.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,39 @@ describe("Testa todas as validações PT", () => {
expect(resultadoActualValido).toBe(true);
});
});

describe("Testes para a função codPostVal()", () => {
/**
* Valida códigos postais PT
*/

test("Só contem 4 caracteres", () => {
//arrange
const cpValido = "2894";
const cpInvalido = "12344";
//act
const resultadoActualValido = vt.PT.codPostalVal(cpValido);
const resultadoActualInvalido = vt.PT.codPostalVal(cpInvalido);
//assertions
expect(resultadoActualValido).toBe(true);
expect(resultadoActualInvalido).toBe(false);
});

test("Só contém numeros.", () => {
//arrange
const cpValido = "2894";
const cpInvalidos = ["258d", "15 1", "3_1#"];
//act
const resultadoActualValido = vt.PT.codPostalVal(cpValido);
cpInvalidos.forEach((cp) => {
const resultadoActualInvalidos = vt.PT.codPostalVal(cp);
//assertions
expect(resultadoActualInvalidos).toBe(false);
});
//assertions
expect(resultadoActualValido).toBe(true);
});
});
});

//templates:
Expand Down
3 changes: 2 additions & 1 deletion validatuga.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ const Validatuga = {
* @returns true se for um código postal válido.
*/
codPostalVal: function (cp) {
return null;
const tamanho = cp.length === 4;
return tamanho && soNumeros(cp);
},

/**
Expand Down