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,38 +0,0 @@
import MastodonAPI from '@/mastodon/api_client'
import { Worker } from 'jest-worker'
jest.mock('axios', () => {
const mockAxios = jest.requireActual('axios')
mockAxios.get = (_path: string) => {
return new Promise(resolve => {
setTimeout(() => {
console.log('hoge')
resolve({
data: 'hoge',
status: 200,
statusText: '200OK',
headers: [],
config: {}
})
}, 5000)
})
}
return mockAxios
})
const worker = async (client: MastodonAPI.Client) => {
const w: any = new Worker(require.resolve('./cancelWorker.ts'))
await w.cancel(client)
}
// Could not use jest-worker under typescript.
// I'm waiting for resolve this issue.
// https://github.com/facebook/jest/issues/8872
describe.skip('cancel', () => {
const client = new MastodonAPI.Client('testToken', 'https://pleroma.io/api/v1')
it('should be raised', async () => {
const getPromise = client.get<{}>('/timelines/home')
worker(client)
await expect(getPromise).rejects.toThrow()
})
})
@@ -1,5 +0,0 @@
import MastodonAPI from '@/mastodon/api_client'
export function cancel(client: MastodonAPI.Client) {
return client.cancel()
}
@@ -1,218 +0,0 @@
import MastodonEntity from '@/mastodon/entity'
import MastodonNotificationType from '@/mastodon/notification'
import Mastodon from '@/mastodon'
import MegalodonNotificationType from '@/notification'
import axios, { AxiosResponse, InternalAxiosRequestConfig, AxiosHeaders } from 'axios'
jest.mock('axios')
const account: MastodonEntity.Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
group: false,
noindex: false,
suspended: false,
limited: false,
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: []
}
}
const status: MastodonEntity.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',
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
}
const follow: MastodonEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '1',
type: MastodonNotificationType.Follow
}
const favourite: MastodonEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '2',
status: status,
type: MastodonNotificationType.Favourite
}
const mention: MastodonEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '3',
status: status,
type: MastodonNotificationType.Mention
}
const reblog: MastodonEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '4',
status: status,
type: MastodonNotificationType.Reblog
}
const poll: MastodonEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '5',
type: MastodonNotificationType.Poll
}
const followRequest: MastodonEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '6',
type: MastodonNotificationType.FollowRequest
}
const toot: MastodonEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '7',
status: status,
type: MastodonNotificationType.Status
}
const unknownEvent: MastodonEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '8',
type: 'unknown'
}
;(axios.CancelToken.source as any).mockImplementation(() => {
return {
token: {
throwIfRequested: () => {},
promise: {
then: () => {},
catch: () => {}
}
}
}
})
describe('getNotifications', () => {
const client = new Mastodon('http://localhost', 'sample token')
const cases: Array<{ event: MastodonEntity.Notification; expected: Entity.NotificationType; title: string }> = [
{
event: follow,
expected: MegalodonNotificationType.Follow,
title: 'follow'
},
{
event: favourite,
expected: MegalodonNotificationType.Favourite,
title: 'favourite'
},
{
event: mention,
expected: MegalodonNotificationType.Mention,
title: 'mention'
},
{
event: reblog,
expected: MegalodonNotificationType.Reblog,
title: 'reblog'
},
{
event: poll,
expected: MegalodonNotificationType.PollExpired,
title: 'poll'
},
{
event: followRequest,
expected: MegalodonNotificationType.FollowRequest,
title: 'followRequest'
},
{
event: toot,
expected: MegalodonNotificationType.Status,
title: 'status'
}
]
cases.forEach(c => {
it(`should be ${c.title} event`, async () => {
const config: InternalAxiosRequestConfig<any> = {
headers: new AxiosHeaders()
}
const mockResponse: AxiosResponse<Array<MastodonEntity.Notification>> = {
data: [c.event],
status: 200,
statusText: '200OK',
headers: {},
config: config
}
;(axios.get as any).mockResolvedValue(mockResponse)
const res = await client.getNotifications()
expect(res.data[0].type).toEqual(c.expected)
})
})
it('UnknownEvent should be ignored', async () => {
const config: InternalAxiosRequestConfig<any> = {
headers: new AxiosHeaders()
}
const mockResponse: AxiosResponse<Array<MastodonEntity.Notification>> = {
data: [unknownEvent],
status: 200,
statusText: '200OK',
headers: {},
config: config
}
;(axios.get as any).mockResolvedValue(mockResponse)
const res = await client.getNotifications()
expect(res.data).toEqual([])
})
})
@@ -1,177 +0,0 @@
import MastodonAPI from '@/mastodon/api_client'
import Entity from '@/entity'
import Response from '@/response'
import axios, { AxiosResponse, InternalAxiosRequestConfig, AxiosHeaders } from 'axios'
jest.mock('axios')
const account: Entity.Account = {
id: '1',
username: 'h3poteto',
acct: 'h3poteto@pleroma.io',
display_name: 'h3poteto',
locked: false,
group: false,
noindex: false,
suspended: false,
limited: false,
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: []
}
}
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: null,
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
}
;(axios.CancelToken.source as any).mockImplementation(() => {
return {
token: {
throwIfRequested: () => {},
promise: {
then: () => {},
catch: () => {}
}
}
}
})
const config: InternalAxiosRequestConfig<any> = {
headers: new AxiosHeaders()
}
describe('get', () => {
const client = new MastodonAPI.Client('testToken', 'https://pleroma.io/api/v1')
const mockResponse: AxiosResponse<Array<Entity.Status>> = {
data: [status],
status: 200,
statusText: '200OK',
headers: {},
config: config
}
it('should be responsed', async () => {
;(axios.get as any).mockResolvedValue(mockResponse)
const response: Response<Array<Entity.Status>> = await client.get<Array<Entity.Status>>('/timelines/home')
expect(response.data).toEqual([status])
})
})
describe('put', () => {
const client = new MastodonAPI.Client('testToken', 'https://pleroma.io/api/v1')
const mockResponse: AxiosResponse<Entity.Account> = {
data: account,
status: 200,
statusText: '200OK',
headers: {},
config: config
}
it('should be responsed', async () => {
;(axios.put as any).mockResolvedValue(mockResponse)
const response: Response<Entity.Account> = await client.put<Entity.Account>('/accounts/update_credentials', {
display_name: 'hoge'
})
expect(response.data).toEqual(account)
})
})
describe('patch', () => {
const client = new MastodonAPI.Client('testToken', 'https://pleroma.io/api/v1')
const mockResponse: AxiosResponse<Entity.Account> = {
data: account,
status: 200,
statusText: '200OK',
headers: {},
config: config
}
it('should be responsed', async () => {
;(axios.patch as any).mockResolvedValue(mockResponse)
const response: Response<Entity.Account> = await client.patch<Entity.Account>('/accounts/update_credentials', {
display_name: 'hoge'
})
expect(response.data).toEqual(account)
})
})
describe('post', () => {
const client = new MastodonAPI.Client('testToken', 'https://pleroma.io/api/v1')
const mockResponse: AxiosResponse<Entity.Status> = {
data: status,
status: 200,
statusText: '200OK',
headers: {},
config: config
}
it('should be responsed', async () => {
;(axios.post as any).mockResolvedValue(mockResponse)
const response: Response<Entity.Status> = await client.post<Entity.Status>('/statuses', {
status: 'hoge'
})
expect(response.data).toEqual(status)
})
})
describe('del', () => {
const client = new MastodonAPI.Client('testToken', 'https://pleroma.io/api/v1')
const mockResponse: AxiosResponse<{}> = {
data: {},
status: 200,
statusText: '200OK',
headers: {},
config: config
}
it('should be responsed', async () => {
;(axios.delete as any).mockResolvedValue(mockResponse)
const response: Response<{}> = await client.del<{}>('/statuses/12asdf34')
expect(response.data).toEqual({})
})
})
@@ -1,222 +0,0 @@
import PleromaEntity from '@/pleroma/entity'
import Pleroma from '@/pleroma'
import MegalodonNotificationType from '@/notification'
import PleromaNotificationType from '@/pleroma/notification'
import axios, { AxiosResponse, InternalAxiosRequestConfig, AxiosHeaders } from 'axios'
jest.mock('axios')
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: []
}
}
const status: PleromaEntity.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',
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 follow: PleromaEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '1',
type: PleromaNotificationType.Follow
}
const favourite: PleromaEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '2',
type: PleromaNotificationType.Favourite,
status: status
}
const mention: PleromaEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '3',
type: PleromaNotificationType.Mention,
status: status
}
const reblog: PleromaEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '4',
type: PleromaNotificationType.Reblog,
status: status
}
const poll: PleromaEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '5',
type: PleromaNotificationType.Poll,
status: status
}
const emojiReaction: PleromaEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '6',
type: PleromaNotificationType.PleromaEmojiReaction,
status: status,
emoji: '♥'
}
const unknownEvent: PleromaEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '8',
type: 'unknown'
}
const followRequest: PleromaEntity.Notification = {
account: account,
created_at: '2021-01-31T23:33:26',
id: '7',
type: PleromaNotificationType.FollowRequest
}
;(axios.CancelToken.source as any).mockImplementation(() => {
return {
token: {
throwIfRequested: () => {},
promise: {
then: () => {},
catch: () => {}
}
}
}
})
describe('getNotifications', () => {
const client = new Pleroma('http://localhost', 'sample token')
const cases: Array<{ event: PleromaEntity.Notification; expected: Entity.NotificationType; title: string }> = [
{
event: follow,
expected: MegalodonNotificationType.Follow,
title: 'follow'
},
{
event: favourite,
expected: MegalodonNotificationType.Favourite,
title: 'favourite'
},
{
event: mention,
expected: MegalodonNotificationType.Mention,
title: 'mention'
},
{
event: reblog,
expected: MegalodonNotificationType.Reblog,
title: 'reblog'
},
{
event: poll,
expected: MegalodonNotificationType.PollExpired,
title: 'poll'
},
{
event: emojiReaction,
expected: MegalodonNotificationType.EmojiReaction,
title: 'emojiReaction'
},
{
event: followRequest,
expected: MegalodonNotificationType.FollowRequest,
title: 'followRequest'
}
]
cases.forEach(c => {
it(`should be ${c.title} event`, async () => {
const config: InternalAxiosRequestConfig<any> = {
headers: new AxiosHeaders()
}
const mockResponse: AxiosResponse<Array<PleromaEntity.Notification>> = {
data: [c.event],
status: 200,
statusText: '200OK',
headers: {},
config: config
}
;(axios.get as any).mockResolvedValue(mockResponse)
const res = await client.getNotifications()
expect(res.data[0].type).toEqual(c.expected)
})
})
it('UnknownEvent should be ignored', async () => {
const config: InternalAxiosRequestConfig<any> = {
headers: new AxiosHeaders()
}
const mockResponse: AxiosResponse<Array<PleromaEntity.Notification>> = {
data: [unknownEvent],
status: 200,
statusText: '200OK',
headers: {},
config: config
}
;(axios.get as any).mockResolvedValue(mockResponse)
const res = await client.getNotifications()
expect(res.data).toEqual([])
})
})