1
0

remove unused megalodon components

This commit is contained in:
Hazelnoot
2025-03-21 21:45:28 -04:00
parent cb9079208a
commit 75b6c63f44
102 changed files with 30 additions and 14604 deletions
@@ -1,6 +0,0 @@
describe('test', () => {
it('should be true', () => {
const res = true
expect(res).toEqual(true)
})
})
@@ -1,80 +0,0 @@
import MastodonAPI from '@/mastodon/api_client'
import MegalodonEntity from '@/entity'
import MastodonEntity from '@/mastodon/entity'
import MegalodonNotificationType from '@/notification'
import MastodonNotificationType from '@/mastodon/notification'
describe('api_client', () => {
describe('notification', () => {
describe('encode', () => {
it('megalodon notification type should be encoded to mastodon notification type', () => {
const cases: Array<{ src: MegalodonEntity.NotificationType; dist: MastodonEntity.NotificationType }> = [
{
src: MegalodonNotificationType.Follow,
dist: MastodonNotificationType.Follow
},
{
src: MegalodonNotificationType.Favourite,
dist: MastodonNotificationType.Favourite
},
{
src: MegalodonNotificationType.Reblog,
dist: MastodonNotificationType.Reblog
},
{
src: MegalodonNotificationType.Mention,
dist: MastodonNotificationType.Mention
},
{
src: MegalodonNotificationType.PollExpired,
dist: MastodonNotificationType.Poll
},
{
src: MegalodonNotificationType.FollowRequest,
dist: MastodonNotificationType.FollowRequest
},
{
src: MegalodonNotificationType.Status,
dist: MastodonNotificationType.Status
}
]
cases.forEach(c => {
expect(MastodonAPI.Converter.encodeNotificationType(c.src)).toEqual(c.dist)
})
})
})
describe('decode', () => {
it('mastodon notification type should be decoded to megalodon notification type', () => {
const cases: Array<{ src: MastodonEntity.NotificationType; dist: MegalodonEntity.NotificationType }> = [
{
src: MastodonNotificationType.Follow,
dist: MegalodonNotificationType.Follow
},
{
src: MastodonNotificationType.Favourite,
dist: MegalodonNotificationType.Favourite
},
{
src: MastodonNotificationType.Mention,
dist: MegalodonNotificationType.Mention
},
{
src: MastodonNotificationType.Reblog,
dist: MegalodonNotificationType.Reblog
},
{
src: MastodonNotificationType.Poll,
dist: MegalodonNotificationType.PollExpired
},
{
src: MastodonNotificationType.FollowRequest,
dist: MegalodonNotificationType.FollowRequest
}
]
cases.forEach(c => {
expect(MastodonAPI.Converter.decodeNotificationType(c.src)).toEqual(c.dist)
})
})
})
})
})
@@ -1,226 +0,0 @@
import PleromaAPI from '@/pleroma/api_client'
import MegalodonEntity from '@/entity'
import PleromaEntity from '@/pleroma/entity'
import MegalodonNotificationType from '@/notification'
import PleromaNotificationType from '@/pleroma/notification'
const account: PleromaEntity.Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
noindex: null,
suspended: null,
limited: null,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: [],
bot: false,
source: {
privacy: null,
sensitive: false,
language: null,
note: 'test',
fields: []
}
}
describe('api_client', () => {
describe('notification', () => {
describe('encode', () => {
it('megalodon notification type should be encoded to pleroma notification type', () => {
const cases: Array<{ src: MegalodonEntity.NotificationType; dist: PleromaEntity.NotificationType }> = [
{
src: MegalodonNotificationType.Follow,
dist: PleromaNotificationType.Follow
},
{
src: MegalodonNotificationType.Favourite,
dist: PleromaNotificationType.Favourite
},
{
src: MegalodonNotificationType.Reblog,
dist: PleromaNotificationType.Reblog
},
{
src: MegalodonNotificationType.Mention,
dist: PleromaNotificationType.Mention
},
{
src: MegalodonNotificationType.PollExpired,
dist: PleromaNotificationType.Poll
},
{
src: MegalodonNotificationType.EmojiReaction,
dist: PleromaNotificationType.PleromaEmojiReaction
},
{
src: MegalodonNotificationType.FollowRequest,
dist: PleromaNotificationType.FollowRequest
},
{
src: MegalodonNotificationType.Update,
dist: PleromaNotificationType.Update
},
{
src: MegalodonNotificationType.Move,
dist: PleromaNotificationType.Move
}
]
cases.forEach(c => {
expect(PleromaAPI.Converter.encodeNotificationType(c.src)).toEqual(c.dist)
})
})
})
describe('decode', () => {
it('pleroma notification type should be decoded to megalodon notification type', () => {
const cases: Array<{ src: PleromaEntity.NotificationType; dist: MegalodonEntity.NotificationType }> = [
{
src: PleromaNotificationType.Follow,
dist: MegalodonNotificationType.Follow
},
{
src: PleromaNotificationType.Favourite,
dist: MegalodonNotificationType.Favourite
},
{
src: PleromaNotificationType.Mention,
dist: MegalodonNotificationType.Mention
},
{
src: PleromaNotificationType.Reblog,
dist: MegalodonNotificationType.Reblog
},
{
src: PleromaNotificationType.Poll,
dist: MegalodonNotificationType.PollExpired
},
{
src: PleromaNotificationType.PleromaEmojiReaction,
dist: MegalodonNotificationType.EmojiReaction
},
{
src: PleromaNotificationType.FollowRequest,
dist: MegalodonNotificationType.FollowRequest
},
{
src: PleromaNotificationType.Update,
dist: MegalodonNotificationType.Update
},
{
src: PleromaNotificationType.Move,
dist: MegalodonNotificationType.Move
}
]
cases.forEach(c => {
expect(PleromaAPI.Converter.decodeNotificationType(c.src)).toEqual(c.dist)
})
})
})
})
describe('status', () => {
describe('plain content is included', () => {
it('plain content in pleroma entity should be exported in plain_content column', () => {
const plainContent = 'hoge\nfuga\nfuga'
const content = '<p>hoge<br>fuga<br>fuga</p>'
const pleromaStatus: PleromaEntity.Status = {
id: '1',
uri: 'https://pleroma.io/notice/1',
url: 'https://pleroma.io/notice/1',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: content,
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
poll: null,
application: {
name: 'Web'
} as MastodonEntity.Application,
language: null,
pinned: null,
bookmarked: false,
pleroma: {
content: {
'text/plain': plainContent
},
local: false
}
}
const megalodonStatus = PleromaAPI.Converter.status(pleromaStatus)
expect(megalodonStatus.plain_content).toEqual(plainContent)
expect(megalodonStatus.content).toEqual(content)
})
})
describe('plain content is not included', () => {
it('plain_content should be null', () => {
const content = '<p>hoge<br>fuga<br>fuga</p>'
const pleromaStatus: PleromaEntity.Status = {
id: '1',
uri: 'https://pleroma.io/notice/1',
url: 'https://pleroma.io/notice/1',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: content,
created_at: '2019-03-26T21:40:32',
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
poll: null,
application: {
name: 'Web'
} as MastodonEntity.Application,
language: null,
pinned: null,
bookmarked: false,
pleroma: {
local: false
}
}
const megalodonStatus = PleromaAPI.Converter.status(pleromaStatus)
expect(megalodonStatus.plain_content).toBeNull()
expect(megalodonStatus.content).toEqual(content)
})
})
})
})
@@ -1,185 +0,0 @@
import { Parser } from '@/mastodon/web_socket'
import Entity from '@/entity'
const account: Entity.Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
group: false,
noindex: null,
suspended: null,
limited: null,
created_at: '2019-03-26T21:30:32',
followers_count: 10,
following_count: 10,
statuses_count: 100,
note: 'engineer',
url: 'https://pleroma.io',
avatar: '',
avatar_static: '',
header: '',
header_static: '',
emojis: [],
moved: null,
fields: [],
bot: false
}
const status: Entity.Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
account: account,
in_reply_to_id: null,
in_reply_to_account_id: null,
reblog: null,
content: 'hoge',
plain_content: 'hoge',
created_at: '2019-03-26T21:40:32',
edited_at: null,
emojis: [],
replies_count: 0,
reblogs_count: 0,
favourites_count: 0,
reblogged: null,
favourited: null,
muted: null,
sensitive: false,
spoiler_text: '',
visibility: 'public',
media_attachments: [],
mentions: [],
tags: [],
card: null,
poll: null,
application: {
name: 'Web'
} as Entity.Application,
language: null,
pinned: null,
emoji_reactions: [],
bookmarked: false,
quote: false
}
const notification: Entity.Notification = {
id: '1',
account: account,
status: status,
type: 'favourite',
created_at: '2019-04-01T17:01:32'
}
const conversation: Entity.Conversation = {
id: '1',
accounts: [account],
last_status: status,
unread: true
}
describe('Parser', () => {
let parser: Parser
beforeEach(() => {
parser = new Parser()
})
describe('parse', () => {
describe('message is heartbeat', () => {
describe('message is an object', () => {
const message = Buffer.alloc(0)
it('should be called', () => {
const spy = jest.fn()
parser.once('heartbeat', spy)
parser.parse(message, true)
expect(spy).toHaveBeenCalledWith({})
})
})
describe('message is empty string', () => {
const message: string = ''
it('should be called', () => {
const spy = jest.fn()
parser.once('heartbeat', spy)
parser.parse(Buffer.from(message), false)
expect(spy).toHaveBeenCalledWith({})
})
})
})
describe('message is not json', () => {
describe('event is delete', () => {
const message = JSON.stringify({
event: 'delete',
payload: '12asdf34'
})
it('should be called', () => {
const spy = jest.fn()
parser.once('delete', spy)
parser.parse(Buffer.from(message), false)
expect(spy).toHaveBeenCalledWith('12asdf34')
})
})
describe('event is not delete', () => {
const message = JSON.stringify({
event: 'event',
payload: '12asdf34'
})
it('should be called', () => {
const error = jest.fn()
const deleted = jest.fn()
parser.once('error', error)
parser.once('delete', deleted)
parser.parse(Buffer.from(message), false)
expect(error).toHaveBeenCalled()
expect(deleted).not.toHaveBeenCalled()
})
})
})
describe('message is json', () => {
describe('event is update', () => {
const message = JSON.stringify({
event: 'update',
payload: JSON.stringify(status)
})
it('should be called', () => {
const spy = jest.fn()
parser.once('update', spy)
parser.parse(Buffer.from(message), false)
expect(spy).toHaveBeenCalledWith(status)
})
})
describe('event is notification', () => {
const message = JSON.stringify({
event: 'notification',
payload: JSON.stringify(notification)
})
it('should be called', () => {
const spy = jest.fn()
parser.once('notification', spy)
parser.parse(Buffer.from(message), false)
expect(spy).toHaveBeenCalledWith(notification)
})
})
describe('event is conversation', () => {
const message = JSON.stringify({
event: 'conversation',
payload: JSON.stringify(conversation)
})
it('should be called', () => {
const spy = jest.fn()
parser.once('conversation', spy)
parser.parse(Buffer.from(message), false)
expect(spy).toHaveBeenCalledWith(conversation)
})
})
})
})
})