add: Megalodon, initial mastodon api
This commit is contained in:
parent
240d76a987
commit
2375d043d1
103 changed files with 9492 additions and 82 deletions
27
packages/megalodon/test/integration/megalodon.spec.ts
Normal file
27
packages/megalodon/test/integration/megalodon.spec.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { detector } from '../../src/index'
|
||||
|
||||
describe('detector', () => {
|
||||
describe('mastodon', () => {
|
||||
const url = 'https://fedibird.com'
|
||||
it('should be mastodon', async () => {
|
||||
const mastodon = await detector(url)
|
||||
expect(mastodon).toEqual('mastodon')
|
||||
})
|
||||
})
|
||||
|
||||
describe('pleroma', () => {
|
||||
const url = 'https://pleroma.soykaf.com'
|
||||
it('should be pleroma', async () => {
|
||||
const pleroma = await detector(url)
|
||||
expect(pleroma).toEqual('pleroma')
|
||||
})
|
||||
})
|
||||
|
||||
describe('misskey', () => {
|
||||
const url = 'https://misskey.io'
|
||||
it('should be misskey', async () => {
|
||||
const misskey = await detector(url)
|
||||
expect(misskey).toEqual('misskey')
|
||||
})
|
||||
})
|
||||
})
|
204
packages/megalodon/test/integration/misskey.spec.ts
Normal file
204
packages/megalodon/test/integration/misskey.spec.ts
Normal file
|
@ -0,0 +1,204 @@
|
|||
import MisskeyEntity from '@/misskey/entity'
|
||||
import MisskeyNotificationType from '@/misskey/notification'
|
||||
import Misskey from '@/misskey'
|
||||
import MegalodonNotificationType from '@/notification'
|
||||
import axios, { AxiosResponse } from 'axios'
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const user: MisskeyEntity.User = {
|
||||
id: '1',
|
||||
name: 'test_user',
|
||||
username: 'TestUser',
|
||||
host: 'misskey.io',
|
||||
avatarUrl: 'https://example.com/icon.png',
|
||||
avatarColor: '#000000',
|
||||
emojis: []
|
||||
}
|
||||
|
||||
const note: MisskeyEntity.Note = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: '1',
|
||||
user: user,
|
||||
text: 'hogehoge',
|
||||
cw: null,
|
||||
visibility: 'public',
|
||||
renoteCount: 0,
|
||||
repliesCount: 0,
|
||||
reactions: {},
|
||||
emojis: [],
|
||||
fileIds: [],
|
||||
files: [],
|
||||
replyId: null,
|
||||
renoteId: null
|
||||
}
|
||||
|
||||
const follow: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.Follow
|
||||
}
|
||||
|
||||
const mention: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.Mention,
|
||||
note: note
|
||||
}
|
||||
|
||||
const reply: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.Reply,
|
||||
note: note
|
||||
}
|
||||
|
||||
const renote: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.Renote,
|
||||
note: note
|
||||
}
|
||||
|
||||
const quote: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.Quote,
|
||||
note: note
|
||||
}
|
||||
|
||||
const reaction: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.Reaction,
|
||||
note: note,
|
||||
reaction: '♥'
|
||||
}
|
||||
|
||||
const pollVote: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.PollEnded,
|
||||
note: note
|
||||
}
|
||||
|
||||
const receiveFollowRequest: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.ReceiveFollowRequest
|
||||
}
|
||||
|
||||
const followRequestAccepted: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.FollowRequestAccepted
|
||||
}
|
||||
|
||||
const groupInvited: MisskeyEntity.Notification = {
|
||||
id: '1',
|
||||
createdAt: '2021-02-01T01:49:29',
|
||||
userId: user.id,
|
||||
user: user,
|
||||
type: MisskeyNotificationType.GroupInvited
|
||||
}
|
||||
|
||||
;(axios.CancelToken.source as any).mockImplementation(() => {
|
||||
return {
|
||||
token: {
|
||||
throwIfRequested: () => {},
|
||||
promise: {
|
||||
then: () => {},
|
||||
catch: () => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
describe('getNotifications', () => {
|
||||
const client = new Misskey('http://localhost', 'sample token')
|
||||
const cases: Array<{ event: MisskeyEntity.Notification; expected: Entity.NotificationType; title: string }> = [
|
||||
{
|
||||
event: follow,
|
||||
expected: MegalodonNotificationType.Follow,
|
||||
title: 'follow'
|
||||
},
|
||||
{
|
||||
event: mention,
|
||||
expected: MegalodonNotificationType.Mention,
|
||||
title: 'mention'
|
||||
},
|
||||
{
|
||||
event: reply,
|
||||
expected: MegalodonNotificationType.Mention,
|
||||
title: 'reply'
|
||||
},
|
||||
{
|
||||
event: renote,
|
||||
expected: MegalodonNotificationType.Reblog,
|
||||
title: 'renote'
|
||||
},
|
||||
{
|
||||
event: quote,
|
||||
expected: MegalodonNotificationType.Reblog,
|
||||
title: 'quote'
|
||||
},
|
||||
{
|
||||
event: reaction,
|
||||
expected: MegalodonNotificationType.Reaction,
|
||||
title: 'reaction'
|
||||
},
|
||||
{
|
||||
event: pollVote,
|
||||
expected: MegalodonNotificationType.Poll,
|
||||
title: 'pollVote'
|
||||
},
|
||||
{
|
||||
event: receiveFollowRequest,
|
||||
expected: MegalodonNotificationType.FollowRequest,
|
||||
title: 'receiveFollowRequest'
|
||||
},
|
||||
{
|
||||
event: followRequestAccepted,
|
||||
expected: MegalodonNotificationType.Follow,
|
||||
title: 'followRequestAccepted'
|
||||
},
|
||||
{
|
||||
event: groupInvited,
|
||||
expected: MisskeyNotificationType.GroupInvited,
|
||||
title: 'groupInvited'
|
||||
}
|
||||
]
|
||||
cases.forEach(c => {
|
||||
it(`should be ${c.title} event`, async () => {
|
||||
const mockResponse: AxiosResponse<Array<MisskeyEntity.Notification>> = {
|
||||
data: [c.event],
|
||||
status: 200,
|
||||
statusText: '200OK',
|
||||
headers: {},
|
||||
config: {}
|
||||
}
|
||||
;(axios.post as any).mockResolvedValue(mockResponse)
|
||||
const res = await client.getNotifications()
|
||||
expect(res.data[0].type).toEqual(c.expected)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue