2019-02-07 13:46:10 -08:00
|
|
|
import * as MatcherService from 'src/services/matcher/matcher.service.js'
|
2019-01-30 09:15:35 -08:00
|
|
|
|
|
|
|
const localAttn = () => ({
|
|
|
|
id: 123,
|
|
|
|
is_local: true,
|
|
|
|
name: 'Guy',
|
|
|
|
screen_name: 'person',
|
|
|
|
statusnet_profile_url: 'https://instance.com/users/person'
|
|
|
|
})
|
|
|
|
|
|
|
|
const externalAttn = () => ({
|
|
|
|
id: 123,
|
|
|
|
is_local: false,
|
|
|
|
name: 'Guy',
|
|
|
|
screen_name: 'person@instance.com',
|
|
|
|
statusnet_profile_url: 'https://instance.com/users/person'
|
|
|
|
})
|
|
|
|
|
2019-02-07 13:46:10 -08:00
|
|
|
describe('MatcherService', () => {
|
2019-02-10 11:06:13 -08:00
|
|
|
describe('mentionMatchesUrl', () => {
|
2019-01-30 09:15:35 -08:00
|
|
|
it('should match local mention', () => {
|
|
|
|
const attention = localAttn()
|
|
|
|
const url = 'https://instance.com/users/person'
|
|
|
|
|
2019-02-07 13:46:10 -08:00
|
|
|
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(true)
|
2019-01-30 09:15:35 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not match a local mention with same name but different instance', () => {
|
|
|
|
const attention = localAttn()
|
|
|
|
const url = 'https://website.com/users/person'
|
|
|
|
|
2019-02-07 13:46:10 -08:00
|
|
|
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false)
|
2019-01-30 09:15:35 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should match external pleroma mention', () => {
|
|
|
|
const attention = externalAttn()
|
|
|
|
const url = 'https://instance.com/users/person'
|
|
|
|
|
2019-02-07 13:46:10 -08:00
|
|
|
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(true)
|
2019-01-30 09:15:35 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not match external pleroma mention with same name but different instance', () => {
|
|
|
|
const attention = externalAttn()
|
|
|
|
const url = 'https://website.com/users/person'
|
|
|
|
|
2019-02-07 13:46:10 -08:00
|
|
|
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false)
|
2019-01-30 09:15:35 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should match external mastodon mention', () => {
|
|
|
|
const attention = externalAttn()
|
|
|
|
const url = 'https://instance.com/@person'
|
|
|
|
|
2019-02-07 13:46:10 -08:00
|
|
|
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(true)
|
2019-01-30 09:15:35 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should not match external mastodon mention with same name but different instance', () => {
|
|
|
|
const attention = externalAttn()
|
|
|
|
const url = 'https://website.com/@person'
|
|
|
|
|
2019-02-07 13:46:10 -08:00
|
|
|
expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false)
|
|
|
|
})
|
|
|
|
})
|
2019-02-10 11:06:13 -08:00
|
|
|
describe('extractTagFromUrl', () => {
|
2019-02-07 13:46:10 -08:00
|
|
|
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)
|
2019-01-30 09:15:35 -08:00
|
|
|
})
|
2023-07-21 10:54:10 -07:00
|
|
|
|
|
|
|
it('should return tag name from non-ascii tags', () => {
|
|
|
|
const url = encodeURI('https://website.com/tag/喵喵喵')
|
|
|
|
|
|
|
|
expect(MatcherService.extractTagFromUrl(url)).to.eql('喵喵喵')
|
|
|
|
})
|
2019-01-30 09:15:35 -08:00
|
|
|
})
|
|
|
|
})
|