-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: moved some regex and made a new function that we test (#567)
- Loading branch information
1 parent
23bc80f
commit e6e1200
Showing
3 changed files
with
51 additions
and
21 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { getInputType } from '../utils' | ||
import { LINK, TWITTER_SOURCE, WEB_PAGE } from '~/constants' | ||
|
||
describe('youtubeRegex', () => { | ||
it('should assert we can check for youtube clip regex', async () => { | ||
expect(getInputType('https://www.youtube.com/watch?v=83eQ9flwVS0&ab_channel=EthanChlebowski')).toBe(LINK) | ||
}) | ||
|
||
it('should assert we can check for twitter spaces regex', async () => { | ||
expect(getInputType('https://twitter.com/i/spaces/1zqKVqwrVzlxB?s=20')).toBe(LINK) | ||
}) | ||
|
||
it('should assert we can check for twitter tweet regex', async () => { | ||
expect(getInputType('https://twitter.com/LarryRuane/status/1720496960489095668')).toBe(TWITTER_SOURCE) | ||
}) | ||
|
||
it('should assert we can check for mp3 url regex', async () => { | ||
expect(getInputType('https://hahaha.com/i/spaces/1zqKVqwrVzlxB?s=20.mp3')).toBe(LINK) | ||
}) | ||
|
||
it('should assert we can check for generic url regex', async () => { | ||
expect(getInputType('https://idkwhat.com/routeing/tou')).toBe(WEB_PAGE) | ||
}) | ||
}) |
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,25 @@ | ||
import { DOCUMENT, LINK, TWITTER_SOURCE, WEB_PAGE } from '~/constants' | ||
|
||
const youtubeRegex = /(https?:\/\/)?(www\.)?youtube\.com\/watch\?v=([A-Za-z0-9_-]+)/ | ||
const twitterSpaceRegex = /https:\/\/twitter\.com\/i\/spaces\/([A-Za-z0-9_-]+)/ | ||
const tweetUrlRegex = /https:\/\/twitter\.com\/[^/]+\/status\/(\d+)/ | ||
const mp3Regex = /(https?:\/\/)?([A-Za-z0-9_-]+)\.mp3/ | ||
const genericUrlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/ | ||
|
||
export function getInputType(source: string) { | ||
let inputType = DOCUMENT | ||
|
||
if (youtubeRegex.test(source)) { | ||
inputType = LINK | ||
} else if (twitterSpaceRegex.test(source)) { | ||
inputType = LINK | ||
} else if (tweetUrlRegex.test(source)) { | ||
inputType = TWITTER_SOURCE | ||
} else if (mp3Regex.test(source)) { | ||
inputType = LINK | ||
} else if (genericUrlRegex.test(source)) { | ||
inputType = WEB_PAGE | ||
} | ||
|
||
return inputType | ||
} |