matcher.spec.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import * as MatcherService from 'src/services/matcher/matcher.service.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('MatcherService', () => {
  17. describe('mentionMatchesUrl', () => {
  18. it('should match local mention', () => {
  19. const attention = localAttn()
  20. const url = 'https://instance.com/users/person'
  21. expect(MatcherService.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(MatcherService.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(MatcherService.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(MatcherService.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(MatcherService.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(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false)
  47. })
  48. })
  49. describe('extractTagFromUrl', () => {
  50. it('should return tag name from valid pleroma url', () => {
  51. const url = 'https://website.com/tag/photo'
  52. expect(MatcherService.extractTagFromUrl(url)).to.eql('photo')
  53. })
  54. it('should return tag name from valid mastodon url', () => {
  55. const url = 'https://website.com/tags/sky'
  56. expect(MatcherService.extractTagFromUrl(url)).to.eql('sky')
  57. })
  58. it('should not return string but false if invalid url', () => {
  59. const url = 'https://website.com/users/sky'
  60. expect(MatcherService.extractTagFromUrl(url)).to.eql(false)
  61. })
  62. })
  63. })