Added tag extractor method and spec
This commit is contained in:
parent
a215f6856d
commit
c0b833cb85
3 changed files with 50 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
|||
import * as MentionMatcher from 'src/services/mention_matcher/mention_matcher.js'
|
||||
import * as MatcherService from 'src/services/matcher/matcher.service.js'
|
||||
|
||||
const localAttn = () => ({
|
||||
id: 123,
|
||||
|
@ -16,48 +16,67 @@ const externalAttn = () => ({
|
|||
statusnet_profile_url: 'https://instance.com/users/person'
|
||||
})
|
||||
|
||||
describe('MentionMatcher', () => {
|
||||
describe('MatcherService', () => {
|
||||
describe.only('mentionMatchesUrl', () => {
|
||||
it('should match local mention', () => {
|
||||
const attention = localAttn()
|
||||
const url = 'https://instance.com/users/person'
|
||||
|
||||
expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(true)
|
||||
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(true)
|
||||
})
|
||||
|
||||
it('should not match a local mention with same name but different instance', () => {
|
||||
const attention = localAttn()
|
||||
const url = 'https://website.com/users/person'
|
||||
|
||||
expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(false)
|
||||
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false)
|
||||
})
|
||||
|
||||
it('should match external pleroma mention', () => {
|
||||
const attention = externalAttn()
|
||||
const url = 'https://instance.com/users/person'
|
||||
|
||||
expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(true)
|
||||
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(true)
|
||||
})
|
||||
|
||||
it('should not match external pleroma mention with same name but different instance', () => {
|
||||
const attention = externalAttn()
|
||||
const url = 'https://website.com/users/person'
|
||||
|
||||
expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(false)
|
||||
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false)
|
||||
})
|
||||
|
||||
it('should match external mastodon mention', () => {
|
||||
const attention = externalAttn()
|
||||
const url = 'https://instance.com/@person'
|
||||
|
||||
expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(true)
|
||||
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(true)
|
||||
})
|
||||
|
||||
it('should not match external mastodon mention with same name but different instance', () => {
|
||||
const attention = externalAttn()
|
||||
const url = 'https://website.com/@person'
|
||||
|
||||
expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(false)
|
||||
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false)
|
||||
})
|
||||
})
|
||||
describe.only('extractTagFromUrl', () => {
|
||||
it('should return tag name from valid pleroma url', () => {
|
||||
const url = 'https://website.com/tag/photo'
|
||||
|
||||
expect(MatcherService.extractTagFromUrl(url)).to.eql('photo')
|
||||
})
|
||||
|
||||
it('should return tag name from valid mastodon url', () => {
|
||||
const url = 'https://website.com/tags/sky'
|
||||
|
||||
expect(MatcherService.extractTagFromUrl(url)).to.eql('sky')
|
||||
})
|
||||
|
||||
it('should not return string but false if invalid url', () => {
|
||||
const url = 'https://website.com/users/sky'
|
||||
|
||||
expect(MatcherService.extractTagFromUrl(url)).to.eql(false)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue