From c0b833cb85ccd10942accbefc3ba4d70cf3d745e Mon Sep 17 00:00:00 2001 From: Edijs Date: Thu, 7 Feb 2019 14:46:10 -0700 Subject: Added tag extractor method and spec --- test/unit/specs/services/matcher/matcher.spec.js | 82 ++++++++++++++++++++++ .../mention_matcher/mention_matcher.spec.js | 63 ----------------- 2 files changed, 82 insertions(+), 63 deletions(-) create mode 100644 test/unit/specs/services/matcher/matcher.spec.js delete mode 100644 test/unit/specs/services/mention_matcher/mention_matcher.spec.js (limited to 'test') diff --git a/test/unit/specs/services/matcher/matcher.spec.js b/test/unit/specs/services/matcher/matcher.spec.js new file mode 100644 index 00000000..0b5363b4 --- /dev/null +++ b/test/unit/specs/services/matcher/matcher.spec.js @@ -0,0 +1,82 @@ +import * as MatcherService from 'src/services/matcher/matcher.service.js' + +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' +}) + +describe('MatcherService', () => { + describe.only('mentionMatchesUrl', () => { + it('should match local mention', () => { + const attention = localAttn() + const url = 'https://instance.com/users/person' + + 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(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false) + }) + + it('should match external pleroma mention', () => { + const attention = externalAttn() + const url = 'https://instance.com/users/person' + + 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(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false) + }) + + it('should match external mastodon mention', () => { + const attention = externalAttn() + const url = 'https://instance.com/@person' + + 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(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) + }) + }) +}) diff --git a/test/unit/specs/services/mention_matcher/mention_matcher.spec.js b/test/unit/specs/services/mention_matcher/mention_matcher.spec.js deleted file mode 100644 index 4f6f58ff..00000000 --- a/test/unit/specs/services/mention_matcher/mention_matcher.spec.js +++ /dev/null @@ -1,63 +0,0 @@ -import * as MentionMatcher from 'src/services/mention_matcher/mention_matcher.js' - -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' -}) - -describe('MentionMatcher', () => { - 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) - }) - - 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) - }) - - it('should match external pleroma mention', () => { - const attention = externalAttn() - const url = 'https://instance.com/users/person' - - expect(MentionMatcher.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) - }) - - it('should match external mastodon mention', () => { - const attention = externalAttn() - const url = 'https://instance.com/@person' - - expect(MentionMatcher.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) - }) - }) -}) -- cgit v1.2.3-70-g09d2 From 7addd408a9fa7f3a3d7966e050feaa162c8f6a5c Mon Sep 17 00:00:00 2001 From: Edijs Date: Sun, 10 Feb 2019 12:06:13 -0700 Subject: Typo --- test/unit/specs/services/matcher/matcher.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/specs/services/matcher/matcher.spec.js b/test/unit/specs/services/matcher/matcher.spec.js index 0b5363b4..7a2494f0 100644 --- a/test/unit/specs/services/matcher/matcher.spec.js +++ b/test/unit/specs/services/matcher/matcher.spec.js @@ -17,7 +17,7 @@ const externalAttn = () => ({ }) describe('MatcherService', () => { - describe.only('mentionMatchesUrl', () => { + describe('mentionMatchesUrl', () => { it('should match local mention', () => { const attention = localAttn() const url = 'https://instance.com/users/person' @@ -60,7 +60,7 @@ describe('MatcherService', () => { expect(MatcherService.mentionMatchesUrl(attention, url)).to.eql(false) }) }) - describe.only('extractTagFromUrl', () => { + describe('extractTagFromUrl', () => { it('should return tag name from valid pleroma url', () => { const url = 'https://website.com/tag/photo' -- cgit v1.2.3-70-g09d2 From be77707381609e555c565f6ba187318562e57dcf Mon Sep 17 00:00:00 2001 From: Edijs Date: Sun, 10 Feb 2019 19:32:01 -0700 Subject: Fix unit test --- test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js index 703fecf1..6245361c 100644 --- a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js +++ b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js @@ -241,7 +241,7 @@ describe('API Entities normalizer', () => { notice: makeMockStatusQvitter({ id: 444 }), from_profile: makeMockUserQvitter({ id: 'spurdo' }) }) - expect(parseNotification(notif)).to.have.property('id', '123') + expect(parseNotification(notif)).to.have.property('id', 123) expect(parseNotification(notif)).to.have.property('seen', false) expect(parseNotification(notif)).to.have.deep.property('status.id', '444') expect(parseNotification(notif)).to.have.deep.property('action.id', '444') @@ -259,7 +259,7 @@ describe('API Entities normalizer', () => { is_seen: 1, from_profile: makeMockUserQvitter({ id: 'spurdo' }) }) - expect(parseNotification(notif)).to.have.property('id', '123') + expect(parseNotification(notif)).to.have.property('id', 123) expect(parseNotification(notif)).to.have.property('type', 'like') expect(parseNotification(notif)).to.have.property('seen', true) expect(parseNotification(notif)).to.have.deep.property('status.id', '4412') -- cgit v1.2.3-70-g09d2