Revert "test: check old megalodon version"

This reverts commit 89eea5df52.
This commit is contained in:
Mar0xy 2023-09-25 01:49:57 +02:00
parent 08cd1f313c
commit 3fd2b55406
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
230 changed files with 21178 additions and 7596 deletions

View file

@ -0,0 +1,6 @@
describe('test', () => {
it('should be true', () => {
const res = true
expect(res).toEqual(true)
})
})

View file

@ -0,0 +1,80 @@
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)
})
})
})
})
})

View file

@ -14,8 +14,6 @@ const user: MisskeyEntity.User = {
emojis: []
}
const converter: MisskeyAPI.Converter = new MisskeyAPI.Converter("https://example.com")
describe('api_client', () => {
describe('notification', () => {
describe('encode', () => {
@ -34,7 +32,7 @@ describe('api_client', () => {
dist: MisskeyNotificationType.Reaction
},
{
src: MegalodonNotificationType.Reaction,
src: MegalodonNotificationType.EmojiReaction,
dist: MisskeyNotificationType.Reaction
},
{
@ -42,8 +40,8 @@ describe('api_client', () => {
dist: MisskeyNotificationType.Renote
},
{
src: MegalodonNotificationType.Poll,
dist: MisskeyNotificationType.PollEnded
src: MegalodonNotificationType.PollVote,
dist: MisskeyNotificationType.PollVote
},
{
src: MegalodonNotificationType.FollowRequest,
@ -51,7 +49,7 @@ describe('api_client', () => {
}
]
cases.forEach(c => {
expect(converter.encodeNotificationType(c.src)).toEqual(c.dist)
expect(MisskeyAPI.Converter.encodeNotificationType(c.src)).toEqual(c.dist)
})
})
})
@ -80,11 +78,11 @@ describe('api_client', () => {
},
{
src: MisskeyNotificationType.Reaction,
dist: MegalodonNotificationType.Reaction
dist: MegalodonNotificationType.EmojiReaction
},
{
src: MisskeyNotificationType.PollEnded,
dist: MegalodonNotificationType.Poll
src: MisskeyNotificationType.PollVote,
dist: MegalodonNotificationType.PollVote
},
{
src: MisskeyNotificationType.ReceiveFollowRequest,
@ -96,7 +94,7 @@ describe('api_client', () => {
}
]
cases.forEach(c => {
expect(converter.decodeNotificationType(c.src)).toEqual(c.dist)
expect(MisskeyAPI.Converter.decodeNotificationType(c.src)).toEqual(c.dist)
})
})
})
@ -162,7 +160,7 @@ describe('api_client', () => {
}
]
const reactions = converter.reactions(misskeyReactions)
const reactions = MisskeyAPI.Converter.reactions(misskeyReactions)
expect(reactions).toEqual([
{
count: 3,
@ -194,13 +192,14 @@ describe('api_client', () => {
renoteCount: 0,
repliesCount: 0,
reactions: {},
reactionEmojis: {},
emojis: [],
fileIds: [],
files: [],
replyId: null,
renoteId: null
}
const megalodonStatus = converter.note(note, user.host || 'misskey.io')
const megalodonStatus = MisskeyAPI.Converter.note(note)
expect(megalodonStatus.plain_content).toEqual(plainContent)
expect(megalodonStatus.content).toEqual(content)
})
@ -218,16 +217,161 @@ describe('api_client', () => {
renoteCount: 0,
repliesCount: 0,
reactions: {},
reactionEmojis: {},
emojis: [],
fileIds: [],
files: [],
replyId: null,
renoteId: null
}
const megalodonStatus = converter.note(note, user.host || 'misskey.io')
const megalodonStatus = MisskeyAPI.Converter.note(note)
expect(megalodonStatus.plain_content).toEqual(plainContent)
expect(megalodonStatus.content).toEqual(content)
})
})
describe('emoji reaction', () => {
it('reactionEmojis should be parsed', () => {
const plainContent = 'hoge\nfuga\nfuga'
const note: MisskeyEntity.Note = {
id: '1',
createdAt: '2021-02-01T01:49:29',
userId: '1',
user: user,
text: plainContent,
cw: null,
visibility: 'public',
renoteCount: 0,
repliesCount: 0,
reactions: {
':example1@.:': 1,
':example2@example.com:': 2
},
reactionEmojis: {
'example2@example.com': 'https://example.com/emoji.png'
},
emojis: [],
fileIds: [],
files: [],
replyId: null,
renoteId: null
}
const megalodonStatus = MisskeyAPI.Converter.note(note)
expect(megalodonStatus.emojis).toEqual([
{
shortcode: 'example2@example.com',
static_url: 'https://example.com/emoji.png',
url: 'https://example.com/emoji.png',
visible_in_picker: true,
category: ''
}
])
expect(megalodonStatus.emoji_reactions).toEqual([
{
count: 1,
me: false,
name: ':example1@.:'
},
{
count: 2,
me: false,
name: ':example2@example.com:'
}
])
})
})
describe('emoji', () => {
it('emojis in array format should be parsed', () => {
const plainContent = 'hoge\nfuga\nfuga'
const note: MisskeyEntity.Note = {
id: '1',
createdAt: '2021-02-01T01:49:29',
userId: '1',
user: user,
text: plainContent,
cw: null,
visibility: 'public',
renoteCount: 0,
repliesCount: 0,
reactions: {},
reactionEmojis: {},
emojis: [
{
aliases: [],
name: ':example1:',
url: 'https://example.com/emoji1.png',
category: '',
},
{
aliases: [],
name: ':example2:',
url: 'https://example.com/emoji2.png',
category: '',
},
],
fileIds: [],
files: [],
replyId: null,
renoteId: null
}
const megalodonStatus = MisskeyAPI.Converter.note(note)
expect(megalodonStatus.emojis).toEqual([
{
shortcode: ':example1:',
static_url: 'https://example.com/emoji1.png',
url: 'https://example.com/emoji1.png',
visible_in_picker: true,
category: ''
},
{
shortcode: ':example2:',
static_url: 'https://example.com/emoji2.png',
url: 'https://example.com/emoji2.png',
visible_in_picker: true,
category: ''
}
])
})
it('emojis in object format should be parsed', () => {
const plainContent = 'hoge\nfuga\nfuga'
const note: MisskeyEntity.Note = {
id: '1',
createdAt: '2021-02-01T01:49:29',
userId: '1',
user: user,
text: plainContent,
cw: null,
visibility: 'public',
renoteCount: 0,
repliesCount: 0,
reactions: {},
reactionEmojis: {},
emojis: {
':example1:': 'https://example.com/emoji1.png',
':example2:': 'https://example.com/emoji2.png',
},
fileIds: [],
files: [],
replyId: null,
renoteId: null
}
const megalodonStatus = MisskeyAPI.Converter.note(note)
expect(megalodonStatus.emojis).toEqual([
{
shortcode: ':example1:',
static_url: 'https://example.com/emoji1.png',
url: 'https://example.com/emoji1.png',
visible_in_picker: true,
category: ''
},
{
shortcode: ':example2:',
static_url: 'https://example.com/emoji2.png',
url: 'https://example.com/emoji2.png',
visible_in_picker: true,
category: ''
}
])
})
})
})
})

View file

@ -7,6 +7,10 @@ const account: Entity.Account = {
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,
@ -54,9 +58,9 @@ const status: Entity.Status = {
} as Entity.Application,
language: null,
pinned: null,
reactions: [],
emoji_reactions: [],
bookmarked: false,
quote: null
quote: false
}
const notification: Entity.Notification = {

View file

@ -0,0 +1,226 @@
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)
})
})
})
})

View file

@ -0,0 +1,184 @@
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',
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)
})
})
})
})
})