1
0
mirror of https://git.pleroma.social/sjw/pleroma-fe.git synced 2024-12-23 15:25:18 +01:00

migrated some tests to normalizer, fixed some potential bug, fixed tests to use

normalized naming instead of raw qvitter api objects. needs more tests tho.
This commit is contained in:
Henry Jameson 2019-01-15 18:39:24 +03:00
parent 966a9e78af
commit d7bd294666
5 changed files with 128 additions and 46 deletions

View File

@ -225,6 +225,9 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
remove(timelineObject.visibleStatuses, { uri })
}
},
'follow': (follow) => {
// NOOP, it is known status but we don't do anything about it for now
},
'default': (unknown) => {
console.log('unknown status type')
console.log(unknown)

View File

@ -44,7 +44,7 @@ const SUGGESTIONS_URL = '/api/v1/suggestions'
const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites'
import { each, map } from 'lodash'
import { parseStatus, parseUser, parseNotification } from '../status_normalizer/status_normalizer.service.js'
import { parseStatus, parseUser, parseNotification } from '../entity_normalizer/entity_normalizer.service.js'
import 'whatwg-fetch'
const oldfetch = window.fetch

View File

@ -139,7 +139,10 @@ export const parseStatus = (data) => {
if (data.retweeted_status) {
output.nsfw = data.retweeted_status.nsfw
}
} else {
output.nsfw = data.nsfw
}
output.statusnet_html = data.statusnet_html
output.text = data.text

View File

@ -1,8 +1,8 @@
import { cloneDeep } from 'lodash'
import { defaultState, mutations, findMaxId, prepareStatus, statusType } from '../../../../src/modules/statuses.js'
import { defaultState, mutations, findMaxId, 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)
@ -127,7 +97,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'
@ -177,7 +147,7 @@ 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 retweet = makeMockStatus({id: 2, type: 'retweet'})
const modStatus = makeMockStatus({id: 1, text: 'something else'})
retweet.retweeted_status = status
@ -220,7 +190,7 @@ describe('The Statuses module', () => {
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 retweet = makeMockStatus({id: 2, type: 'retweet'})
retweet.retweeted_status = modStatus
// Add original status
@ -243,7 +213,7 @@ describe('The Statuses module', () => {
const favorite = {
id: 2,
is_post_verb: false,
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',
@ -271,7 +241,7 @@ describe('The Statuses module', () => {
const ownFavorite = {
id: 3,
is_post_verb: false,
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',
@ -296,7 +266,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'
@ -305,10 +275,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
}]
})
@ -317,10 +289,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
}]
})

View File

@ -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)
})
})