-
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: added new tests and moved notify (#579)
* test: added new tests and moved notify * test: updated thresholds
- Loading branch information
1 parent
39819e6
commit 5aefbdd
Showing
6 changed files
with
86 additions
and
73 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
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,36 @@ | ||
import { getInputType } from '..' | ||
import { YOUTUBE_CHANNEL, RSS, TWITTER_HANDLE, GITHUB_REPOSITORY, TOPIC } 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(YOUTUBE_CHANNEL) | ||
}) | ||
|
||
it('should assert we can check for twitter spaces regex', async () => { | ||
expect(getInputType('https://twitter.com/i/spaces/1zqKVqwrVzlxB?s=20')).toBe(RSS) | ||
}) | ||
|
||
it('should assert we can check for twitter tweet regex', async () => { | ||
expect(getInputType('https://twitter.com/LarryRuane/status/1720496960489095668')).toBe(RSS) | ||
}) | ||
|
||
it('should assert we can check for mp3 url regex', async () => { | ||
expect(getInputType('https://hahaha.com/i/spaces/1zqKVqwrVzlxB?s=20.mp3')).toBe(RSS) | ||
}) | ||
|
||
it('should assert we can check for generic url regex', async () => { | ||
expect(getInputType('https://idkwhat.com/routeing/tou')).toBe(RSS) | ||
}) | ||
|
||
it('should assert we can check for twitter handle regex', async () => { | ||
expect(getInputType('https://twitter.com/@KevKevPal')).toBe(TWITTER_HANDLE) | ||
}) | ||
|
||
it('should assert we can check for github repo regex', async () => { | ||
expect(getInputType('https://github.com/stakwork/sphinx-relay')).toBe(GITHUB_REPOSITORY) | ||
}) | ||
|
||
it('should assert we can check for topic regex', async () => { | ||
expect(getInputType('Bitcoin')).toBe(TOPIC) | ||
}) | ||
}) |
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 { DOCUMENT, YOUTUBE_CHANNEL, TWITTER_HANDLE, GITHUB_REPOSITORY, RSS, TOPIC } from '~/constants' | ||
|
||
const twitterHandlePattern = /@(\w+)/g | ||
const youtubeChannelPattern = /https?:\/\/(www\.)?youtube\.com\/(@)?([\w-]+)/i | ||
const githubRepoPattern = /https?:\/\/github\.com\/([\w-]+)\/([\w-]+)/i | ||
const genericUrlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/ | ||
|
||
export function getInputType(source: string) { | ||
let inputType = DOCUMENT | ||
|
||
if (youtubeChannelPattern.test(source)) { | ||
inputType = YOUTUBE_CHANNEL | ||
} else if (twitterHandlePattern.test(source)) { | ||
inputType = TWITTER_HANDLE | ||
} else if (githubRepoPattern.test(source)) { | ||
inputType = GITHUB_REPOSITORY | ||
} else if (genericUrlRegex.test(source)) { | ||
inputType = RSS | ||
} else { | ||
inputType = TOPIC | ||
} | ||
|
||
return inputType | ||
} |
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