Skip to content

Commit

Permalink
Merge pull request #38 from Kilix/fix/lel-testLinkedInUrlFormat
Browse files Browse the repository at this point in the history
🐛 Fix: testLinkedInUrlFormat add more restrictions
  • Loading branch information
alefevre19 authored Oct 5, 2021
2 parents e72f3b0 + a9dc316 commit 906959b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
60 changes: 44 additions & 16 deletions src/__tests__/fieldValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/fieldValidators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
};

Expand Down

0 comments on commit 906959b

Please sign in to comment.