Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate twitter URLS start with https://twitter.com in landscape.yml; …
…closes #195 (#311) * Validate twitter URLS start with https://twitter.com in landscape.yml * Remove query string from twitter URLs * When twitter is set to null ignore twitter url from crunchbase
- Loading branch information
Showing
4 changed files
with
94 additions
and
37 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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import actualTwitter from '../../tools/actualTwitter'; | ||
|
||
describe('Twitter URL', () => { | ||
describe('when crunchbase data not set', () => { | ||
const node = { twitter: 'https://twitter.com/foo' }; | ||
|
||
test('returns URL from node', async () => { | ||
expect(actualTwitter(node, null)).toBe(node.twitter) | ||
}) | ||
}); | ||
|
||
describe('when node does not have twitter URL', () => { | ||
const crunchbaseData = { twitter: 'https://twitter.com/foo' }; | ||
|
||
test('returns URL from node', async () => { | ||
expect(actualTwitter({}, crunchbaseData)).toBe(crunchbaseData.twitter) | ||
}) | ||
}); | ||
|
||
describe('when node has twitter URL set to null', () => { | ||
const crunchbaseData = { twitter: 'https://twitter.com/foo' }; | ||
const node = { twitter: null }; | ||
|
||
test('returns undefined', async () => { | ||
expect(actualTwitter(node, crunchbaseData)).toBe(undefined) | ||
}) | ||
}); | ||
|
||
describe('when both node and crunchbase have twitter URL', () => { | ||
const node = { twitter: 'https://twitter.com/main' }; | ||
const crunchbaseData = { twitter: 'https://twitter.com/other' }; | ||
|
||
test('returns URL from node', async () => { | ||
expect(actualTwitter(node, crunchbaseData)).toBe(node.twitter) | ||
}) | ||
}); | ||
|
||
describe('when twitter URL is not set anywhere', () => { | ||
const node = {}; | ||
const crunchbaseData = {}; | ||
|
||
test('returns undefined', async () => { | ||
expect(actualTwitter(node, crunchbaseData)).toBe(undefined) | ||
}) | ||
}); | ||
|
||
describe('cleaning up twitter URL', () => { | ||
test('replaces http with https', async () => { | ||
const node = { twitter: 'http://twitter.com/foo' }; | ||
expect(actualTwitter(node)).toBe('https://twitter.com/foo') | ||
}); | ||
|
||
test('removes www', async () => { | ||
const node = { twitter: 'https://www.twitter.com/foo' }; | ||
expect(actualTwitter(node)).toBe('https://twitter.com/foo') | ||
}); | ||
|
||
test('query string', async () => { | ||
const node = { twitter: 'https://twitter.com/foo?omg' }; | ||
expect(actualTwitter(node)).toBe('https://twitter.com/foo') | ||
}); | ||
}); | ||
}); |
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,25 +1,8 @@ | ||
import _ from 'lodash'; | ||
export default function actualTwitter(node, crunchbaseEntry) { | ||
const url = (function() { | ||
if (_.isUndefined(node.twitter)) { | ||
return (crunchbaseEntry || {}).twitter; | ||
} | ||
return node.twitter; | ||
})(); | ||
if (_.isEmpty(url)) { | ||
return null; | ||
const twitterUrl = 'twitter' in node ? node.twitter : (crunchbaseEntry || {}).twitter; | ||
|
||
if (twitterUrl) { | ||
return twitterUrl.replace(/^http(?:s)?\:\/\/(?:www\.)?/, 'https://') | ||
.replace(/\?.*/, ''); | ||
} | ||
const fixedUrl = (function() { | ||
if (url.indexOf('http://twitter.com/') === 0) { | ||
return url.replace('http://twitter.com/', 'https://twitter.com/'); | ||
} | ||
if (url.indexOf('https://www.twitter.com/') === 0) { | ||
return url.replace('https://www.twitter.com/', 'https://twitter.com/'); | ||
} | ||
if (url.indexOf('http://twitter.com/') === 0) { | ||
return url.replace('http://twitter.com/', 'https://twitter.com/'); | ||
} | ||
return url; | ||
})(); | ||
return fixedUrl; | ||
} |
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