-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44f0e70
commit 254dc00
Showing
46 changed files
with
1,765 additions
and
1,309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ webpack.config.js | |
jestTestFile.js | ||
BackupCopia | ||
.eslintrc.js | ||
jest.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"code-runner.executorMap": { | ||
"typescript": "npx ts-node", | ||
}, | ||
"typescript": "npx ts-node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,70 @@ | ||
import cnpjIsValid from '../../src/cnpjValidator'; | ||
|
||
describe('cnpjIsValid function', () => { | ||
test('should validate a valid CNPJ', () => { | ||
const result = cnpjIsValid('72.501.263/0001-40'); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe("CNPJ is not valid"); | ||
}); | ||
|
||
test('should invalidate an invalid CNPJ', () => { | ||
const result = cnpjIsValid('12.345.678/0001-91'); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe('CNPJ is not valid'); | ||
}); | ||
|
||
test('should invalidate a CNPJ with incorrect length', () => { | ||
const result = cnpjIsValid('1234567890123'); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe('CNPJ must have 14 numerical digits'); | ||
}); | ||
|
||
test('should invalidate a CNPJ with non-digit characters', () => { | ||
const result = cnpjIsValid('72.501.263/0001-4A'); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe('CNPJ is not valid'); | ||
}); | ||
|
||
test('should invalidate an empty CNPJ', () => { | ||
const result = cnpjIsValid(''); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe('CNPJ invalid'); | ||
}); | ||
|
||
test('should throw an error if input is not a string', () => { | ||
expect(() => { | ||
cnpjIsValid(12345678901234 as any); | ||
}).toThrow('The input should be a string.'); | ||
}); | ||
|
||
test('should throw an error if errorMsg is not an array', () => { | ||
expect(() => { | ||
cnpjIsValid('72.501.263/0001-40', 'error message' as any); | ||
}).toThrow('Must be an Array'); | ||
}); | ||
|
||
test('should throw an error if errorMsg contains non-string values', () => { | ||
expect(() => { | ||
cnpjIsValid('72.501.263/0001-40', [123, 'error message'] as any); | ||
}).toThrow('All values within the array must be strings or null/undefined.'); | ||
}); | ||
|
||
test('should return custom error messages', () => { | ||
const result = cnpjIsValid('12.345.678/0001-91', ['Custom invalid message', 'Custom length message', 'Custom not valid message', 'Custom unknown error message']); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe('Custom not valid message'); | ||
}); | ||
|
||
test('should return false when all digits are repeated', () => { | ||
const result = cnpjIsValid('11.111.111/1111-11'); | ||
import cnpjIsValid from "../../src/cnpjValidator"; | ||
|
||
describe("cnpjIsValid function", () => { | ||
test("should validate a valid CNPJ", () => { | ||
const result = cnpjIsValid("72.501.263/0001-40"); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe("CNPJ is not valid"); | ||
}); | ||
|
||
test("should invalidate an invalid CNPJ", () => { | ||
const result = cnpjIsValid("12.345.678/0001-91"); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe("CNPJ is not valid"); | ||
}); | ||
|
||
test("should invalidate a CNPJ with incorrect length", () => { | ||
const result = cnpjIsValid("1234567890123"); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe("CNPJ must have 14 numerical digits"); | ||
}); | ||
|
||
test("should invalidate a CNPJ with non-digit characters", () => { | ||
const result = cnpjIsValid("72.501.263/0001-4A"); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe("CNPJ is not valid"); | ||
}); | ||
|
||
test("should invalidate an empty CNPJ", () => { | ||
const result = cnpjIsValid(""); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe("CNPJ invalid"); | ||
}); | ||
|
||
test("should throw an error if input is not a string", () => { | ||
expect(() => { | ||
cnpjIsValid(12345678901234 as any); | ||
}).toThrow("The input should be a string."); | ||
}); | ||
|
||
test("should throw an error if errorMsg is not an array", () => { | ||
expect(() => { | ||
cnpjIsValid("72.501.263/0001-40", "error message" as any); | ||
}).toThrow("Must be an Array"); | ||
}); | ||
|
||
test("should throw an error if errorMsg contains non-string values", () => { | ||
expect(() => { | ||
cnpjIsValid("72.501.263/0001-40", [123, "error message"] as any); | ||
}).toThrow( | ||
"All values within the array must be strings or null/undefined.", | ||
); | ||
}); | ||
|
||
test("should return custom error messages", () => { | ||
const result = cnpjIsValid("12.345.678/0001-91", [ | ||
"Custom invalid message", | ||
"Custom length message", | ||
"Custom not valid message", | ||
"Custom unknown error message", | ||
]); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe("Custom not valid message"); | ||
}); | ||
|
||
test("should return false when all digits are repeated", () => { | ||
const result = cnpjIsValid("11.111.111/1111-11"); | ||
expect(result.isValid).toBe(false); | ||
expect(result.errorMsg).toBe('CNPJ is not valid'); | ||
expect(result.errorMsg).toBe("CNPJ is not valid"); | ||
}); | ||
}); |
Oops, something went wrong.