diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/unit/specs/modules/statuses.spec.js | 76 | ||||
| -rw-r--r-- | test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js | 102 |
2 files changed, 127 insertions, 51 deletions
diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js index f4d0ddf4..076e238c 100644 --- a/test/unit/specs/modules/statuses.spec.js +++ b/test/unit/specs/modules/statuses.spec.js @@ -1,8 +1,8 @@ import { cloneDeep } from 'lodash' -import { defaultState, mutations, prepareStatus, statusType } from '../../../../src/modules/statuses.js' +import { defaultState, mutations, prepareStatus } from '../../../../src/modules/statuses.js' // eslint-disable-next-line camelcase -const makeMockStatus = ({id, text, is_post_verb = true}) => { +const makeMockStatus = ({id, text, type = 'status'}) => { return { id, user: {id: '0'}, @@ -10,42 +10,12 @@ const makeMockStatus = ({id, text, is_post_verb = true}) => { text: text || `Text number ${id}`, fave_num: 0, uri: '', - is_post_verb, + type, attentions: [] } } -describe('Statuses.statusType', () => { - it('identifies favorites', () => { - const fav = { - uri: 'tag:soykaf.com,2016-08-21:fave:2558:note:339495:2016-08-21T16:54:04+00:00' - } - - const mastoFav = { - uri: 'tag:mastodon.social,2016-11-27:objectId=73903:objectType=Favourite' - } - - expect(statusType(fav)).to.eql('favorite') - expect(statusType(mastoFav)).to.eql('favorite') - }) -}) - describe('Statuses.prepareStatus', () => { - it('sets nsfw for statuses with the #nsfw tag', () => { - const safe = makeMockStatus({id: '1', text: 'Hello oniichan'}) - const nsfw = makeMockStatus({id: '1', text: 'Hello oniichan #nsfw'}) - - expect(prepareStatus(safe).nsfw).to.eq(false) - expect(prepareStatus(nsfw).nsfw).to.eq(true) - }) - - it('leaves existing nsfw settings alone', () => { - const nsfw = makeMockStatus({id: '1', text: 'Hello oniichan #nsfw'}) - nsfw.nsfw = false - - expect(prepareStatus(nsfw).nsfw).to.eq(false) - }) - it('sets deleted flag to false', () => { const aStatus = makeMockStatus({id: '1', text: 'Hello oniichan'}) expect(prepareStatus(aStatus).deleted).to.eq(false) @@ -112,7 +82,7 @@ describe('The Statuses module', () => { const status = makeMockStatus({id: '1'}) const otherStatus = makeMockStatus({id: '3'}) status.uri = 'xxx' - const deletion = makeMockStatus({id: '2', is_post_verb: false}) + const deletion = makeMockStatus({id: 2, type: 'deletion'}) deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.' deletion.uri = 'xxx' @@ -161,9 +131,9 @@ describe('The Statuses module', () => { it('splits retweets from their status and links them', () => { const state = cloneDeep(defaultState) - const status = makeMockStatus({id: '1'}) - const retweet = makeMockStatus({id: '2', is_post_verb: false}) - const modStatus = makeMockStatus({id: '1', text: 'something else'}) + const status = makeMockStatus({id: 1}) + const retweet = makeMockStatus({id: 2, type: 'retweet'}) + const modStatus = makeMockStatus({id: 1, text: 'something else'}) retweet.retweeted_status = status @@ -203,9 +173,9 @@ describe('The Statuses module', () => { it('replaces existing statuses with the same id, coming from a retweet', () => { const state = cloneDeep(defaultState) - const status = makeMockStatus({id: '1'}) - const modStatus = makeMockStatus({id: '1', text: 'something else'}) - const retweet = makeMockStatus({id: '2', is_post_verb: false}) + const status = makeMockStatus({id: 1}) + const modStatus = makeMockStatus({id: 1, text: 'something else'}) + const retweet = makeMockStatus({id: 2, type: 'retweet'}) retweet.retweeted_status = modStatus // Add original status @@ -227,8 +197,8 @@ describe('The Statuses module', () => { const status = makeMockStatus({id: '1'}) const favorite = { - id: '2', - is_post_verb: false, + id: 2, + type: 'favorite', in_reply_to_status_id: '1', // The API uses strings here... uri: 'tag:shitposter.club,2016-08-21:fave:3895:note:773501:2016-08-21T16:52:15+00:00', text: 'a favorited something by b', @@ -255,8 +225,8 @@ describe('The Statuses module', () => { } const ownFavorite = { - id: '3', - is_post_verb: false, + id: 3, + type: 'favorite', in_reply_to_status_id: '1', // The API uses strings here... uri: 'tag:shitposter.club,2016-08-21:fave:3895:note:773501:2016-08-21T16:52:15+00:00', text: 'a favorited something by b', @@ -281,7 +251,7 @@ describe('The Statuses module', () => { mentionedStatus.uri = 'xxx' otherStatus.attentions = [user] - const deletion = makeMockStatus({id: '4', is_post_verb: false}) + const deletion = makeMockStatus({id: 4, type: 'deletion'}) deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.' deletion.uri = 'xxx' @@ -290,10 +260,12 @@ describe('The Statuses module', () => { state, { notifications: [{ - ntype: 'mention', + from_profile: { id: 2 }, + id: 998, + type: 'mention', status: otherStatus, - notice: otherStatus, - is_seen: false + action: otherStatus, + seen: false }] }) @@ -302,10 +274,12 @@ describe('The Statuses module', () => { state, { notifications: [{ - ntype: 'mention', + from_profile: { id: 2 }, + id: 999, + type: 'mention', status: mentionedStatus, - notice: mentionedStatus, - is_seen: false + action: mentionedStatus, + seen: false }] }) diff --git a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js new file mode 100644 index 00000000..e5882725 --- /dev/null +++ b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js @@ -0,0 +1,102 @@ +import { parseStatus, parseUser, parseNotification } from '../../../../../src/services/entity_normalizer/entity_normalizer.service.js' + +const makeMockStatusQvitter = (overrides = {}) => { + return Object.assign({ + activity_type: 'post', + attachments: [], + attentions: [], + created_at: 'Tue Jan 15 13:57:56 +0000 2019', + external_url: 'https://ap.example/whatever', + fave_num: 1, + favorited: false, + id: 10335970, + in_reply_to_ostatus_uri: null, + in_reply_to_profileurl: null, + in_reply_to_screen_name: null, + in_reply_to_status_id: null, + in_reply_to_user_id: null, + is_local: false, + is_post_verb: true, + possibly_sensitive: false, + repeat_num: 0, + repeated: false, + statusnet_conversation_id: 16300488, + statusnet_html: '<p>haha benis</p>', + summary: null, + tags: [], + text: 'haha benis', + uri: 'https://ap.example/whatever', + user: makeMockUserQvitter(), + visibility: 'public' + }, overrides) +} + +const makeMockUserQvitter = (overrides = {}) => { + return Object.assign({ + background_image: null, + cover_photo: '', + created_at: 'Mon Jan 14 13:56:51 +0000 2019', + default_scope: 'public', + description: 'ebin', + description_html: '<p>ebin</p>', + favourites_count: 0, + fields: [], + followers_count: 1, + following: true, + follows_you: true, + friends_count: 1, + id: 60717, + is_local: false, + locked: false, + name: 'Spurdo :ebin:', + name_html: 'Spurdo <img src="whatever">', + no_rich_text: false, + pleroma: { confirmation_pending: false, tags: [] }, + profile_image_url: 'https://ap.example/whatever', + profile_image_url_https: 'https://ap.example/whatever', + profile_image_url_original: 'https://ap.example/whatever', + profile_image_url_profile_size: 'https://ap.example/whatever', + rights: { delete_others_notice: false }, + screen_name: 'spurdo@ap.example', + statuses_count: 46, + statusnet_blocking: false, + statusnet_profile_url: '' + }, overrides) +} + +parseNotification +parseUser +parseStatus +makeMockStatusQvitter +makeMockUserQvitter + +describe('QVitter preprocessing', () => { + it('identifies favorites', () => { + const fav = { + uri: 'tag:soykaf.com,2016-08-21:fave:2558:note:339495:2016-08-21T16:54:04+00:00', + is_post_verb: false + } + + const mastoFav = { + uri: 'tag:mastodon.social,2016-11-27:objectId=73903:objectType=Favourite', + is_post_verb: false + } + + expect(parseStatus(makeMockStatusQvitter(fav))).to.have.property('type', 'favorite') + expect(parseStatus(makeMockStatusQvitter(mastoFav))).to.have.property('type', 'favorite') + }) + + it('sets nsfw for statuses with the #nsfw tag', () => { + const safe = makeMockStatusQvitter({id: 1, text: 'Hello oniichan'}) + const nsfw = makeMockStatusQvitter({id: 1, text: 'Hello oniichan #nsfw'}) + + expect(parseStatus(safe).nsfw).to.eq(false) + expect(parseStatus(nsfw).nsfw).to.eq(true) + }) + + it('leaves existing nsfw settings alone', () => { + const nsfw = makeMockStatusQvitter({id: 1, text: 'Hello oniichan #nsfw', nsfw: false}) + + expect(parseStatus(nsfw).nsfw).to.eq(false) + }) +}) |
