diff --git a/package.json b/package.json index 3ea437a..9841c5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kilix/functional-validation", - "version": "2.5.0", + "version": "2.5.1", "description": "Lightweight and customisable validation, built through composition", "main": "lib/index.js", "scripts": { diff --git a/src/__tests__/fieldValidators.js b/src/__tests__/fieldValidators.js index d9a8ea9..d92f6ee 100644 --- a/src/__tests__/fieldValidators.js +++ b/src/__tests__/fieldValidators.js @@ -157,26 +157,54 @@ it('testEmailFormat', () => { expect(actual).toBe(expected); }); -it('testLinkedInUrlFormat', () => { - let actual = testLinkedInUrlFormat('https://www.linkedin.com/in/url-test/'); - let expected = null; - expect(actual).toBe(expected); +describe('testLinkedInUrlFormat', () => { + it('Should return notLinkedInUrl error message if param is not an url', () => { + const actual = testLinkedInUrlFormat('Bob'); + expect(actual).toBe('notLinkedInUrl'); + }); + it('Should return notLinkedInUrl error message if url has not http', () => { + const actual = testLinkedInUrlFormat('www.linkedin.com/in/url-test/'); + expect(actual).toBe('notLinkedInUrl'); + }); + it('Should return notLinkedInUrl error message if http is badly written', () => { + let actual = testLinkedInUrlFormat('htps://www.linkedin.com/in/url-test/'); + expect(actual).toBe('notLinkedInUrl'); - actual = testLinkedInUrlFormat('Bob'); - expected = 'notLinkedInUrl'; - expect(actual).toBe(expected); + actual = testLinkedInUrlFormat('https//www.linkedin.com/in/url-test/'); + expect(actual).toBe('notLinkedInUrl'); - actual = testLinkedInUrlFormat(null); - expected = null; - expect(actual).toBe(expected); + actual = testLinkedInUrlFormat('https:www.linkedin.com/in/url-test/'); + expect(actual).toBe('notLinkedInUrl'); + }); + it('Should return notLinkedInUrl error message if dns is different of linkedIn dns', () => { + let actual = testLinkedInUrlFormat('https://www.linkedinsss.com/in/url-test/'); + expect(actual).toBe('notLinkedInUrl'); - actual = testLinkedInUrlFormat('https://www.linkedgin.com/in/url-test/'); - expected = 'notLinkedInUrl'; - expect(actual).toBe(expected); + actual = testLinkedInUrlFormat('https://wwwddd.linkedin.com/in/url-test/'); + expect(actual).toBe('notLinkedInUrl'); - actual = testLinkedInUrlFormat('https://www.linkedin.com/on/url-test/'); - expected = 'notLinkedInUrl'; - expect(actual).toBe(expected); + actual = testLinkedInUrlFormat('https://www.linkedin.fr/in/url-test/'); + expect(actual).toBe('notLinkedInUrl'); + }); + it('Should return notLinkedInUrl error message if url has not /in/', () => { + const actual = testLinkedInUrlFormat('https://www.linkedin.com/on/url-test/'); + expect(actual).toBe('notLinkedInUrl'); + }); + it('Should return null if url format is correct', () => { + // with number in end of the url + let actual = testLinkedInUrlFormat('https://www.linkedin.com/in/99erest/'); + expect(actual).toBe(null); + + // without www. + actual = testLinkedInUrlFormat('https://linkedin.com/in/url-test/'); + expect(actual).toBe(null); + + // with special chars in end of the url + actual = testLinkedInUrlFormat( + 'https://www.linkedin.com/in/%E2?9A=9B&+_#-test-url-716a96119/', + ); + expect(actual).toBe(null); + }); }); describe('checkMaxLength', () => { diff --git a/src/fieldValidators.js b/src/fieldValidators.js index 64cb512..29ddf7e 100644 --- a/src/fieldValidators.js +++ b/src/fieldValidators.js @@ -86,7 +86,7 @@ const testEmailFormat = (value: ?string) => { const testLinkedInUrlFormat = (value: ?string) => { if (!value) return null; - const regexp = /(https?)?:?(\/\/)?(([w]{3}||\w\w)\.)?linkedin.com\/in\//; // eslint-disable-line no-control-regex + const regexp = /(https?):(\/\/)(([w]{3}||\w\w)\.)?linkedin.com\/in\/.+/; // eslint-disable-line no-control-regex return regexp.test(value.trim()) ? null : 'notLinkedInUrl'; };