mention_matcher.spec.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import * as MentionMatcher from 'src/services/mention_matcher/mention_matcher.js'
  2. const localAttn = () => ({
  3. id: 123,
  4. is_local: true,
  5. name: 'Guy',
  6. screen_name: 'person',
  7. statusnet_profile_url: 'https://instance.com/users/person'
  8. })
  9. const externalAttn = () => ({
  10. id: 123,
  11. is_local: false,
  12. name: 'Guy',
  13. screen_name: 'person@instance.com',
  14. statusnet_profile_url: 'https://instance.com/users/person'
  15. })
  16. describe('MentionMatcher', () => {
  17. describe.only('mentionMatchesUrl', () => {
  18. it('should match local mention', () => {
  19. const attention = localAttn()
  20. const url = 'https://instance.com/users/person'
  21. expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(true)
  22. })
  23. it('should not match a local mention with same name but different instance', () => {
  24. const attention = localAttn()
  25. const url = 'https://website.com/users/person'
  26. expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(false)
  27. })
  28. it('should match external pleroma mention', () => {
  29. const attention = externalAttn()
  30. const url = 'https://instance.com/users/person'
  31. expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(true)
  32. })
  33. it('should not match external pleroma mention with same name but different instance', () => {
  34. const attention = externalAttn()
  35. const url = 'https://website.com/users/person'
  36. expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(false)
  37. })
  38. it('should match external mastodon mention', () => {
  39. const attention = externalAttn()
  40. const url = 'https://instance.com/@person'
  41. expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(true)
  42. })
  43. it('should not match external mastodon mention with same name but different instance', () => {
  44. const attention = externalAttn()
  45. const url = 'https://website.com/@person'
  46. expect(MentionMatcher.mentionMatchesUrl(attention, url)).to.eql(false)
  47. })
  48. })
  49. })