chore: format specs
This commit is contained in:
parent
63e740dccf
commit
788b979734
4 changed files with 584 additions and 565 deletions
|
@ -1,27 +1,27 @@
|
||||||
import { detector } from '../../src/index'
|
import { detector } from "../../src/index";
|
||||||
|
|
||||||
describe('detector', () => {
|
describe("detector", () => {
|
||||||
describe('mastodon', () => {
|
describe("mastodon", () => {
|
||||||
const url = 'https://fedibird.com'
|
const url = "https://fedibird.com";
|
||||||
it('should be mastodon', async () => {
|
it("should be mastodon", async () => {
|
||||||
const mastodon = await detector(url)
|
const mastodon = await detector(url);
|
||||||
expect(mastodon).toEqual('mastodon')
|
expect(mastodon).toEqual("mastodon");
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('pleroma', () => {
|
describe("pleroma", () => {
|
||||||
const url = 'https://pleroma.soykaf.com'
|
const url = "https://pleroma.soykaf.com";
|
||||||
it('should be pleroma', async () => {
|
it("should be pleroma", async () => {
|
||||||
const pleroma = await detector(url)
|
const pleroma = await detector(url);
|
||||||
expect(pleroma).toEqual('pleroma')
|
expect(pleroma).toEqual("pleroma");
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('misskey', () => {
|
describe("misskey", () => {
|
||||||
const url = 'https://misskey.io'
|
const url = "https://misskey.io";
|
||||||
it('should be misskey', async () => {
|
it("should be misskey", async () => {
|
||||||
const misskey = await detector(url)
|
const misskey = await detector(url);
|
||||||
expect(misskey).toEqual('misskey')
|
expect(misskey).toEqual("misskey");
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
|
@ -1,204 +1,207 @@
|
||||||
import MisskeyEntity from '@/misskey/entity'
|
import MisskeyEntity from "@/misskey/entity";
|
||||||
import MisskeyNotificationType from '@/misskey/notification'
|
import MisskeyNotificationType from "@/misskey/notification";
|
||||||
import Misskey from '@/misskey'
|
import Misskey from "@/misskey";
|
||||||
import MegalodonNotificationType from '@/notification'
|
import MegalodonNotificationType from "@/notification";
|
||||||
import axios, { AxiosResponse } from 'axios'
|
import axios, { AxiosResponse } from "axios";
|
||||||
|
|
||||||
jest.mock('axios')
|
jest.mock("axios");
|
||||||
|
|
||||||
const user: MisskeyEntity.User = {
|
const user: MisskeyEntity.User = {
|
||||||
id: '1',
|
id: "1",
|
||||||
name: 'test_user',
|
name: "test_user",
|
||||||
username: 'TestUser',
|
username: "TestUser",
|
||||||
host: 'misskey.io',
|
host: "misskey.io",
|
||||||
avatarUrl: 'https://example.com/icon.png',
|
avatarUrl: "https://example.com/icon.png",
|
||||||
avatarColor: '#000000',
|
avatarColor: "#000000",
|
||||||
emojis: []
|
emojis: [],
|
||||||
}
|
};
|
||||||
|
|
||||||
const note: MisskeyEntity.Note = {
|
const note: MisskeyEntity.Note = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: '1',
|
userId: "1",
|
||||||
user: user,
|
user: user,
|
||||||
text: 'hogehoge',
|
text: "hogehoge",
|
||||||
cw: null,
|
cw: null,
|
||||||
visibility: 'public',
|
visibility: "public",
|
||||||
renoteCount: 0,
|
renoteCount: 0,
|
||||||
repliesCount: 0,
|
repliesCount: 0,
|
||||||
reactions: {},
|
reactions: {},
|
||||||
emojis: [],
|
emojis: [],
|
||||||
fileIds: [],
|
fileIds: [],
|
||||||
files: [],
|
files: [],
|
||||||
replyId: null,
|
replyId: null,
|
||||||
renoteId: null
|
renoteId: null,
|
||||||
}
|
};
|
||||||
|
|
||||||
const follow: MisskeyEntity.Notification = {
|
const follow: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.Follow
|
type: MisskeyNotificationType.Follow,
|
||||||
}
|
};
|
||||||
|
|
||||||
const mention: MisskeyEntity.Notification = {
|
const mention: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.Mention,
|
type: MisskeyNotificationType.Mention,
|
||||||
note: note
|
note: note,
|
||||||
}
|
};
|
||||||
|
|
||||||
const reply: MisskeyEntity.Notification = {
|
const reply: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.Reply,
|
type: MisskeyNotificationType.Reply,
|
||||||
note: note
|
note: note,
|
||||||
}
|
};
|
||||||
|
|
||||||
const renote: MisskeyEntity.Notification = {
|
const renote: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.Renote,
|
type: MisskeyNotificationType.Renote,
|
||||||
note: note
|
note: note,
|
||||||
}
|
};
|
||||||
|
|
||||||
const quote: MisskeyEntity.Notification = {
|
const quote: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.Quote,
|
type: MisskeyNotificationType.Quote,
|
||||||
note: note
|
note: note,
|
||||||
}
|
};
|
||||||
|
|
||||||
const reaction: MisskeyEntity.Notification = {
|
const reaction: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.Reaction,
|
type: MisskeyNotificationType.Reaction,
|
||||||
note: note,
|
note: note,
|
||||||
reaction: '♥'
|
reaction: "♥",
|
||||||
}
|
};
|
||||||
|
|
||||||
const pollVote: MisskeyEntity.Notification = {
|
const pollVote: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.PollEnded,
|
type: MisskeyNotificationType.PollEnded,
|
||||||
note: note
|
note: note,
|
||||||
}
|
};
|
||||||
|
|
||||||
const receiveFollowRequest: MisskeyEntity.Notification = {
|
const receiveFollowRequest: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.ReceiveFollowRequest
|
type: MisskeyNotificationType.ReceiveFollowRequest,
|
||||||
}
|
};
|
||||||
|
|
||||||
const followRequestAccepted: MisskeyEntity.Notification = {
|
const followRequestAccepted: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.FollowRequestAccepted
|
type: MisskeyNotificationType.FollowRequestAccepted,
|
||||||
}
|
};
|
||||||
|
|
||||||
const groupInvited: MisskeyEntity.Notification = {
|
const groupInvited: MisskeyEntity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
type: MisskeyNotificationType.GroupInvited
|
type: MisskeyNotificationType.GroupInvited,
|
||||||
}
|
};
|
||||||
|
(axios.CancelToken.source as any).mockImplementation(() => {
|
||||||
|
return {
|
||||||
|
token: {
|
||||||
|
throwIfRequested: () => {},
|
||||||
|
promise: {
|
||||||
|
then: () => {},
|
||||||
|
catch: () => {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
;(axios.CancelToken.source as any).mockImplementation(() => {
|
describe("getNotifications", () => {
|
||||||
return {
|
const client = new Misskey("http://localhost", "sample token");
|
||||||
token: {
|
const cases: Array<{
|
||||||
throwIfRequested: () => {},
|
event: MisskeyEntity.Notification;
|
||||||
promise: {
|
expected: Entity.NotificationType;
|
||||||
then: () => {},
|
title: string;
|
||||||
catch: () => {}
|
}> = [
|
||||||
}
|
{
|
||||||
}
|
event: follow,
|
||||||
}
|
expected: MegalodonNotificationType.Follow,
|
||||||
})
|
title: "follow",
|
||||||
|
},
|
||||||
describe('getNotifications', () => {
|
{
|
||||||
const client = new Misskey('http://localhost', 'sample token')
|
event: mention,
|
||||||
const cases: Array<{ event: MisskeyEntity.Notification; expected: Entity.NotificationType; title: string }> = [
|
expected: MegalodonNotificationType.Mention,
|
||||||
{
|
title: "mention",
|
||||||
event: follow,
|
},
|
||||||
expected: MegalodonNotificationType.Follow,
|
{
|
||||||
title: 'follow'
|
event: reply,
|
||||||
},
|
expected: MegalodonNotificationType.Mention,
|
||||||
{
|
title: "reply",
|
||||||
event: mention,
|
},
|
||||||
expected: MegalodonNotificationType.Mention,
|
{
|
||||||
title: 'mention'
|
event: renote,
|
||||||
},
|
expected: MegalodonNotificationType.Reblog,
|
||||||
{
|
title: "renote",
|
||||||
event: reply,
|
},
|
||||||
expected: MegalodonNotificationType.Mention,
|
{
|
||||||
title: 'reply'
|
event: quote,
|
||||||
},
|
expected: MegalodonNotificationType.Reblog,
|
||||||
{
|
title: "quote",
|
||||||
event: renote,
|
},
|
||||||
expected: MegalodonNotificationType.Reblog,
|
{
|
||||||
title: 'renote'
|
event: reaction,
|
||||||
},
|
expected: MegalodonNotificationType.Reaction,
|
||||||
{
|
title: "reaction",
|
||||||
event: quote,
|
},
|
||||||
expected: MegalodonNotificationType.Reblog,
|
{
|
||||||
title: 'quote'
|
event: pollVote,
|
||||||
},
|
expected: MegalodonNotificationType.Poll,
|
||||||
{
|
title: "pollVote",
|
||||||
event: reaction,
|
},
|
||||||
expected: MegalodonNotificationType.Reaction,
|
{
|
||||||
title: 'reaction'
|
event: receiveFollowRequest,
|
||||||
},
|
expected: MegalodonNotificationType.FollowRequest,
|
||||||
{
|
title: "receiveFollowRequest",
|
||||||
event: pollVote,
|
},
|
||||||
expected: MegalodonNotificationType.Poll,
|
{
|
||||||
title: 'pollVote'
|
event: followRequestAccepted,
|
||||||
},
|
expected: MegalodonNotificationType.Follow,
|
||||||
{
|
title: "followRequestAccepted",
|
||||||
event: receiveFollowRequest,
|
},
|
||||||
expected: MegalodonNotificationType.FollowRequest,
|
{
|
||||||
title: 'receiveFollowRequest'
|
event: groupInvited,
|
||||||
},
|
expected: MisskeyNotificationType.GroupInvited,
|
||||||
{
|
title: "groupInvited",
|
||||||
event: followRequestAccepted,
|
},
|
||||||
expected: MegalodonNotificationType.Follow,
|
];
|
||||||
title: 'followRequestAccepted'
|
cases.forEach((c) => {
|
||||||
},
|
it(`should be ${c.title} event`, async () => {
|
||||||
{
|
const mockResponse: AxiosResponse<Array<MisskeyEntity.Notification>> = {
|
||||||
event: groupInvited,
|
data: [c.event],
|
||||||
expected: MisskeyNotificationType.GroupInvited,
|
status: 200,
|
||||||
title: 'groupInvited'
|
statusText: "200OK",
|
||||||
}
|
headers: {},
|
||||||
]
|
config: {},
|
||||||
cases.forEach(c => {
|
};
|
||||||
it(`should be ${c.title} event`, async () => {
|
(axios.post as any).mockResolvedValue(mockResponse);
|
||||||
const mockResponse: AxiosResponse<Array<MisskeyEntity.Notification>> = {
|
const res = await client.getNotifications();
|
||||||
data: [c.event],
|
expect(res.data[0].type).toEqual(c.expected);
|
||||||
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)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
|
@ -1,233 +1,245 @@
|
||||||
import MisskeyAPI from '@/misskey/api_client'
|
import MisskeyAPI from "@/misskey/api_client";
|
||||||
import MegalodonEntity from '@/entity'
|
import MegalodonEntity from "@/entity";
|
||||||
import MisskeyEntity from '@/misskey/entity'
|
import MisskeyEntity from "@/misskey/entity";
|
||||||
import MegalodonNotificationType from '@/notification'
|
import MegalodonNotificationType from "@/notification";
|
||||||
import MisskeyNotificationType from '@/misskey/notification'
|
import MisskeyNotificationType from "@/misskey/notification";
|
||||||
|
|
||||||
const user: MisskeyEntity.User = {
|
const user: MisskeyEntity.User = {
|
||||||
id: '1',
|
id: "1",
|
||||||
name: 'test_user',
|
name: "test_user",
|
||||||
username: 'TestUser',
|
username: "TestUser",
|
||||||
host: 'misskey.io',
|
host: "misskey.io",
|
||||||
avatarUrl: 'https://example.com/icon.png',
|
avatarUrl: "https://example.com/icon.png",
|
||||||
avatarColor: '#000000',
|
avatarColor: "#000000",
|
||||||
emojis: []
|
emojis: [],
|
||||||
}
|
};
|
||||||
|
|
||||||
const converter: MisskeyAPI.Converter = new MisskeyAPI.Converter("https://example.com")
|
const converter: MisskeyAPI.Converter = new MisskeyAPI.Converter(
|
||||||
|
"https://example.com",
|
||||||
|
);
|
||||||
|
|
||||||
describe('api_client', () => {
|
describe("api_client", () => {
|
||||||
describe('notification', () => {
|
describe("notification", () => {
|
||||||
describe('encode', () => {
|
describe("encode", () => {
|
||||||
it('megalodon notification type should be encoded to misskey notification type', () => {
|
it("megalodon notification type should be encoded to misskey notification type", () => {
|
||||||
const cases: Array<{ src: MegalodonEntity.NotificationType; dist: MisskeyEntity.NotificationType }> = [
|
const cases: Array<{
|
||||||
{
|
src: MegalodonEntity.NotificationType;
|
||||||
src: MegalodonNotificationType.Follow,
|
dist: MisskeyEntity.NotificationType;
|
||||||
dist: MisskeyNotificationType.Follow
|
}> = [
|
||||||
},
|
{
|
||||||
{
|
src: MegalodonNotificationType.Follow,
|
||||||
src: MegalodonNotificationType.Mention,
|
dist: MisskeyNotificationType.Follow,
|
||||||
dist: MisskeyNotificationType.Reply
|
},
|
||||||
},
|
{
|
||||||
{
|
src: MegalodonNotificationType.Mention,
|
||||||
src: MegalodonNotificationType.Favourite,
|
dist: MisskeyNotificationType.Reply,
|
||||||
dist: MisskeyNotificationType.Reaction
|
},
|
||||||
},
|
{
|
||||||
{
|
src: MegalodonNotificationType.Favourite,
|
||||||
src: MegalodonNotificationType.Reaction,
|
dist: MisskeyNotificationType.Reaction,
|
||||||
dist: MisskeyNotificationType.Reaction
|
},
|
||||||
},
|
{
|
||||||
{
|
src: MegalodonNotificationType.Reaction,
|
||||||
src: MegalodonNotificationType.Reblog,
|
dist: MisskeyNotificationType.Reaction,
|
||||||
dist: MisskeyNotificationType.Renote
|
},
|
||||||
},
|
{
|
||||||
{
|
src: MegalodonNotificationType.Reblog,
|
||||||
src: MegalodonNotificationType.Poll,
|
dist: MisskeyNotificationType.Renote,
|
||||||
dist: MisskeyNotificationType.PollEnded
|
},
|
||||||
},
|
{
|
||||||
{
|
src: MegalodonNotificationType.Poll,
|
||||||
src: MegalodonNotificationType.FollowRequest,
|
dist: MisskeyNotificationType.PollEnded,
|
||||||
dist: MisskeyNotificationType.ReceiveFollowRequest
|
},
|
||||||
}
|
{
|
||||||
]
|
src: MegalodonNotificationType.FollowRequest,
|
||||||
cases.forEach(c => {
|
dist: MisskeyNotificationType.ReceiveFollowRequest,
|
||||||
expect(converter.encodeNotificationType(c.src)).toEqual(c.dist)
|
},
|
||||||
})
|
];
|
||||||
})
|
cases.forEach((c) => {
|
||||||
})
|
expect(converter.encodeNotificationType(c.src)).toEqual(c.dist);
|
||||||
describe('decode', () => {
|
});
|
||||||
it('misskey notification type should be decoded to megalodon notification type', () => {
|
});
|
||||||
const cases: Array<{ src: MisskeyEntity.NotificationType; dist: MegalodonEntity.NotificationType }> = [
|
});
|
||||||
{
|
describe("decode", () => {
|
||||||
src: MisskeyNotificationType.Follow,
|
it("misskey notification type should be decoded to megalodon notification type", () => {
|
||||||
dist: MegalodonNotificationType.Follow
|
const cases: Array<{
|
||||||
},
|
src: MisskeyEntity.NotificationType;
|
||||||
{
|
dist: MegalodonEntity.NotificationType;
|
||||||
src: MisskeyNotificationType.Mention,
|
}> = [
|
||||||
dist: MegalodonNotificationType.Mention
|
{
|
||||||
},
|
src: MisskeyNotificationType.Follow,
|
||||||
{
|
dist: MegalodonNotificationType.Follow,
|
||||||
src: MisskeyNotificationType.Reply,
|
},
|
||||||
dist: MegalodonNotificationType.Mention
|
{
|
||||||
},
|
src: MisskeyNotificationType.Mention,
|
||||||
{
|
dist: MegalodonNotificationType.Mention,
|
||||||
src: MisskeyNotificationType.Renote,
|
},
|
||||||
dist: MegalodonNotificationType.Reblog
|
{
|
||||||
},
|
src: MisskeyNotificationType.Reply,
|
||||||
{
|
dist: MegalodonNotificationType.Mention,
|
||||||
src: MisskeyNotificationType.Quote,
|
},
|
||||||
dist: MegalodonNotificationType.Reblog
|
{
|
||||||
},
|
src: MisskeyNotificationType.Renote,
|
||||||
{
|
dist: MegalodonNotificationType.Reblog,
|
||||||
src: MisskeyNotificationType.Reaction,
|
},
|
||||||
dist: MegalodonNotificationType.Reaction
|
{
|
||||||
},
|
src: MisskeyNotificationType.Quote,
|
||||||
{
|
dist: MegalodonNotificationType.Reblog,
|
||||||
src: MisskeyNotificationType.PollEnded,
|
},
|
||||||
dist: MegalodonNotificationType.Poll
|
{
|
||||||
},
|
src: MisskeyNotificationType.Reaction,
|
||||||
{
|
dist: MegalodonNotificationType.Reaction,
|
||||||
src: MisskeyNotificationType.ReceiveFollowRequest,
|
},
|
||||||
dist: MegalodonNotificationType.FollowRequest
|
{
|
||||||
},
|
src: MisskeyNotificationType.PollEnded,
|
||||||
{
|
dist: MegalodonNotificationType.Poll,
|
||||||
src: MisskeyNotificationType.FollowRequestAccepted,
|
},
|
||||||
dist: MegalodonNotificationType.Follow
|
{
|
||||||
}
|
src: MisskeyNotificationType.ReceiveFollowRequest,
|
||||||
]
|
dist: MegalodonNotificationType.FollowRequest,
|
||||||
cases.forEach(c => {
|
},
|
||||||
expect(converter.decodeNotificationType(c.src)).toEqual(c.dist)
|
{
|
||||||
})
|
src: MisskeyNotificationType.FollowRequestAccepted,
|
||||||
})
|
dist: MegalodonNotificationType.Follow,
|
||||||
})
|
},
|
||||||
})
|
];
|
||||||
describe('reactions', () => {
|
cases.forEach((c) => {
|
||||||
it('should be mapped', () => {
|
expect(converter.decodeNotificationType(c.src)).toEqual(c.dist);
|
||||||
const misskeyReactions = [
|
});
|
||||||
{
|
});
|
||||||
id: '1',
|
});
|
||||||
createdAt: '2020-04-21T13:04:13.968Z',
|
});
|
||||||
user: {
|
describe("reactions", () => {
|
||||||
id: '81u70uwsja',
|
it("should be mapped", () => {
|
||||||
name: 'h3poteto',
|
const misskeyReactions = [
|
||||||
username: 'h3poteto',
|
{
|
||||||
host: null,
|
id: "1",
|
||||||
avatarUrl: 'https://s3.arkjp.net/misskey/thumbnail-63807d97-20ca-40ba-9493-179aa48065c1.png',
|
createdAt: "2020-04-21T13:04:13.968Z",
|
||||||
avatarColor: 'rgb(146,189,195)',
|
user: {
|
||||||
emojis: []
|
id: "81u70uwsja",
|
||||||
},
|
name: "h3poteto",
|
||||||
type: '❤'
|
username: "h3poteto",
|
||||||
},
|
host: null,
|
||||||
{
|
avatarUrl:
|
||||||
id: '2',
|
"https://s3.arkjp.net/misskey/thumbnail-63807d97-20ca-40ba-9493-179aa48065c1.png",
|
||||||
createdAt: '2020-04-21T13:04:13.968Z',
|
avatarColor: "rgb(146,189,195)",
|
||||||
user: {
|
emojis: [],
|
||||||
id: '81u70uwsja',
|
},
|
||||||
name: 'h3poteto',
|
type: "❤",
|
||||||
username: 'h3poteto',
|
},
|
||||||
host: null,
|
{
|
||||||
avatarUrl: 'https://s3.arkjp.net/misskey/thumbnail-63807d97-20ca-40ba-9493-179aa48065c1.png',
|
id: "2",
|
||||||
avatarColor: 'rgb(146,189,195)',
|
createdAt: "2020-04-21T13:04:13.968Z",
|
||||||
emojis: []
|
user: {
|
||||||
},
|
id: "81u70uwsja",
|
||||||
type: '❤'
|
name: "h3poteto",
|
||||||
},
|
username: "h3poteto",
|
||||||
{
|
host: null,
|
||||||
id: '3',
|
avatarUrl:
|
||||||
createdAt: '2020-04-21T13:04:13.968Z',
|
"https://s3.arkjp.net/misskey/thumbnail-63807d97-20ca-40ba-9493-179aa48065c1.png",
|
||||||
user: {
|
avatarColor: "rgb(146,189,195)",
|
||||||
id: '81u70uwsja',
|
emojis: [],
|
||||||
name: 'h3poteto',
|
},
|
||||||
username: 'h3poteto',
|
type: "❤",
|
||||||
host: null,
|
},
|
||||||
avatarUrl: 'https://s3.arkjp.net/misskey/thumbnail-63807d97-20ca-40ba-9493-179aa48065c1.png',
|
{
|
||||||
avatarColor: 'rgb(146,189,195)',
|
id: "3",
|
||||||
emojis: []
|
createdAt: "2020-04-21T13:04:13.968Z",
|
||||||
},
|
user: {
|
||||||
type: '☺'
|
id: "81u70uwsja",
|
||||||
},
|
name: "h3poteto",
|
||||||
{
|
username: "h3poteto",
|
||||||
id: '4',
|
host: null,
|
||||||
createdAt: '2020-04-21T13:04:13.968Z',
|
avatarUrl:
|
||||||
user: {
|
"https://s3.arkjp.net/misskey/thumbnail-63807d97-20ca-40ba-9493-179aa48065c1.png",
|
||||||
id: '81u70uwsja',
|
avatarColor: "rgb(146,189,195)",
|
||||||
name: 'h3poteto',
|
emojis: [],
|
||||||
username: 'h3poteto',
|
},
|
||||||
host: null,
|
type: "☺",
|
||||||
avatarUrl: 'https://s3.arkjp.net/misskey/thumbnail-63807d97-20ca-40ba-9493-179aa48065c1.png',
|
},
|
||||||
avatarColor: 'rgb(146,189,195)',
|
{
|
||||||
emojis: []
|
id: "4",
|
||||||
},
|
createdAt: "2020-04-21T13:04:13.968Z",
|
||||||
type: '❤'
|
user: {
|
||||||
}
|
id: "81u70uwsja",
|
||||||
]
|
name: "h3poteto",
|
||||||
|
username: "h3poteto",
|
||||||
|
host: null,
|
||||||
|
avatarUrl:
|
||||||
|
"https://s3.arkjp.net/misskey/thumbnail-63807d97-20ca-40ba-9493-179aa48065c1.png",
|
||||||
|
avatarColor: "rgb(146,189,195)",
|
||||||
|
emojis: [],
|
||||||
|
},
|
||||||
|
type: "❤",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const reactions = converter.reactions(misskeyReactions)
|
const reactions = converter.reactions(misskeyReactions);
|
||||||
expect(reactions).toEqual([
|
expect(reactions).toEqual([
|
||||||
{
|
{
|
||||||
count: 3,
|
count: 3,
|
||||||
me: false,
|
me: false,
|
||||||
name: '❤'
|
name: "❤",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
count: 1,
|
count: 1,
|
||||||
me: false,
|
me: false,
|
||||||
name: '☺'
|
name: "☺",
|
||||||
}
|
},
|
||||||
])
|
]);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('status', () => {
|
describe("status", () => {
|
||||||
describe('plain content', () => {
|
describe("plain content", () => {
|
||||||
it('should be exported plain content and html content', () => {
|
it("should be exported plain content and html content", () => {
|
||||||
const plainContent = 'hoge\nfuga\nfuga'
|
const plainContent = "hoge\nfuga\nfuga";
|
||||||
const content = 'hoge<br>fuga<br>fuga'
|
const content = "hoge<br>fuga<br>fuga";
|
||||||
const note: MisskeyEntity.Note = {
|
const note: MisskeyEntity.Note = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: '1',
|
userId: "1",
|
||||||
user: user,
|
user: user,
|
||||||
text: plainContent,
|
text: plainContent,
|
||||||
cw: null,
|
cw: null,
|
||||||
visibility: 'public',
|
visibility: "public",
|
||||||
renoteCount: 0,
|
renoteCount: 0,
|
||||||
repliesCount: 0,
|
repliesCount: 0,
|
||||||
reactions: {},
|
reactions: {},
|
||||||
emojis: [],
|
emojis: [],
|
||||||
fileIds: [],
|
fileIds: [],
|
||||||
files: [],
|
files: [],
|
||||||
replyId: null,
|
replyId: null,
|
||||||
renoteId: null
|
renoteId: null,
|
||||||
}
|
};
|
||||||
const megalodonStatus = converter.note(note, user.host || 'misskey.io')
|
const megalodonStatus = converter.note(note, user.host || "misskey.io");
|
||||||
expect(megalodonStatus.plain_content).toEqual(plainContent)
|
expect(megalodonStatus.plain_content).toEqual(plainContent);
|
||||||
expect(megalodonStatus.content).toEqual(content)
|
expect(megalodonStatus.content).toEqual(content);
|
||||||
})
|
});
|
||||||
it('html tags should be escaped', () => {
|
it("html tags should be escaped", () => {
|
||||||
const plainContent = '<p>hoge\nfuga\nfuga<p>'
|
const plainContent = "<p>hoge\nfuga\nfuga<p>";
|
||||||
const content = '<p>hoge<br>fuga<br>fuga<p>'
|
const content = "<p>hoge<br>fuga<br>fuga<p>";
|
||||||
const note: MisskeyEntity.Note = {
|
const note: MisskeyEntity.Note = {
|
||||||
id: '1',
|
id: "1",
|
||||||
createdAt: '2021-02-01T01:49:29',
|
createdAt: "2021-02-01T01:49:29",
|
||||||
userId: '1',
|
userId: "1",
|
||||||
user: user,
|
user: user,
|
||||||
text: plainContent,
|
text: plainContent,
|
||||||
cw: null,
|
cw: null,
|
||||||
visibility: 'public',
|
visibility: "public",
|
||||||
renoteCount: 0,
|
renoteCount: 0,
|
||||||
repliesCount: 0,
|
repliesCount: 0,
|
||||||
reactions: {},
|
reactions: {},
|
||||||
emojis: [],
|
emojis: [],
|
||||||
fileIds: [],
|
fileIds: [],
|
||||||
files: [],
|
files: [],
|
||||||
replyId: null,
|
replyId: null,
|
||||||
renoteId: null
|
renoteId: null,
|
||||||
}
|
};
|
||||||
const megalodonStatus = converter.note(note, user.host || 'misskey.io')
|
const megalodonStatus = converter.note(note, user.host || "misskey.io");
|
||||||
expect(megalodonStatus.plain_content).toEqual(plainContent)
|
expect(megalodonStatus.plain_content).toEqual(plainContent);
|
||||||
expect(megalodonStatus.content).toEqual(content)
|
expect(megalodonStatus.content).toEqual(content);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
|
@ -1,152 +1,156 @@
|
||||||
import { Parser } from '@/parser'
|
import { Parser } from "@/parser";
|
||||||
import Entity from '@/entity'
|
import Entity from "@/entity";
|
||||||
|
|
||||||
const account: Entity.Account = {
|
const account: Entity.Account = {
|
||||||
id: '1',
|
id: "1",
|
||||||
username: 'h3poteto',
|
username: "h3poteto",
|
||||||
acct: 'h3poteto@pleroma.io',
|
acct: "h3poteto@pleroma.io",
|
||||||
display_name: 'h3poteto',
|
display_name: "h3poteto",
|
||||||
locked: false,
|
locked: false,
|
||||||
created_at: '2019-03-26T21:30:32',
|
created_at: "2019-03-26T21:30:32",
|
||||||
followers_count: 10,
|
followers_count: 10,
|
||||||
following_count: 10,
|
following_count: 10,
|
||||||
statuses_count: 100,
|
statuses_count: 100,
|
||||||
note: 'engineer',
|
note: "engineer",
|
||||||
url: 'https://pleroma.io',
|
url: "https://pleroma.io",
|
||||||
avatar: '',
|
avatar: "",
|
||||||
avatar_static: '',
|
avatar_static: "",
|
||||||
header: '',
|
header: "",
|
||||||
header_static: '',
|
header_static: "",
|
||||||
emojis: [],
|
emojis: [],
|
||||||
moved: null,
|
moved: null,
|
||||||
fields: [],
|
fields: [],
|
||||||
bot: false
|
bot: false,
|
||||||
}
|
};
|
||||||
|
|
||||||
const status: Entity.Status = {
|
const status: Entity.Status = {
|
||||||
id: '1',
|
id: "1",
|
||||||
uri: 'http://example.com',
|
uri: "http://example.com",
|
||||||
url: 'http://example.com',
|
url: "http://example.com",
|
||||||
account: account,
|
account: account,
|
||||||
in_reply_to_id: null,
|
in_reply_to_id: null,
|
||||||
in_reply_to_account_id: null,
|
in_reply_to_account_id: null,
|
||||||
reblog: null,
|
reblog: null,
|
||||||
content: 'hoge',
|
content: "hoge",
|
||||||
plain_content: 'hoge',
|
plain_content: "hoge",
|
||||||
created_at: '2019-03-26T21:40:32',
|
created_at: "2019-03-26T21:40:32",
|
||||||
emojis: [],
|
emojis: [],
|
||||||
replies_count: 0,
|
replies_count: 0,
|
||||||
reblogs_count: 0,
|
reblogs_count: 0,
|
||||||
favourites_count: 0,
|
favourites_count: 0,
|
||||||
reblogged: null,
|
reblogged: null,
|
||||||
favourited: null,
|
favourited: null,
|
||||||
muted: null,
|
muted: null,
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
spoiler_text: '',
|
spoiler_text: "",
|
||||||
visibility: 'public',
|
visibility: "public",
|
||||||
media_attachments: [],
|
media_attachments: [],
|
||||||
mentions: [],
|
mentions: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
card: null,
|
card: null,
|
||||||
poll: null,
|
poll: null,
|
||||||
application: {
|
application: {
|
||||||
name: 'Web'
|
name: "Web",
|
||||||
} as Entity.Application,
|
} as Entity.Application,
|
||||||
language: null,
|
language: null,
|
||||||
pinned: null,
|
pinned: null,
|
||||||
reactions: [],
|
reactions: [],
|
||||||
bookmarked: false,
|
bookmarked: false,
|
||||||
quote: null
|
quote: null,
|
||||||
}
|
};
|
||||||
|
|
||||||
const notification: Entity.Notification = {
|
const notification: Entity.Notification = {
|
||||||
id: '1',
|
id: "1",
|
||||||
account: account,
|
account: account,
|
||||||
status: status,
|
status: status,
|
||||||
type: 'favourite',
|
type: "favourite",
|
||||||
created_at: '2019-04-01T17:01:32'
|
created_at: "2019-04-01T17:01:32",
|
||||||
}
|
};
|
||||||
|
|
||||||
const conversation: Entity.Conversation = {
|
const conversation: Entity.Conversation = {
|
||||||
id: '1',
|
id: "1",
|
||||||
accounts: [account],
|
accounts: [account],
|
||||||
last_status: status,
|
last_status: status,
|
||||||
unread: true
|
unread: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
describe('Parser', () => {
|
describe("Parser", () => {
|
||||||
let parser: Parser
|
let parser: Parser;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
parser = new Parser()
|
parser = new Parser();
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('parse', () => {
|
describe("parse", () => {
|
||||||
describe('message is heartbeat', () => {
|
describe("message is heartbeat", () => {
|
||||||
const message: string = ':thump\n'
|
const message: string = ":thump\n";
|
||||||
it('should be called', () => {
|
it("should be called", () => {
|
||||||
const spy = jest.fn()
|
const spy = jest.fn();
|
||||||
parser.on('heartbeat', spy)
|
parser.on("heartbeat", spy);
|
||||||
parser.parse(message)
|
parser.parse(message);
|
||||||
expect(spy).toHaveBeenLastCalledWith({})
|
expect(spy).toHaveBeenLastCalledWith({});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('message is not json', () => {
|
describe("message is not json", () => {
|
||||||
describe('event is delete', () => {
|
describe("event is delete", () => {
|
||||||
const message = `event: delete\ndata: 12asdf34\n\n`
|
const message = `event: delete\ndata: 12asdf34\n\n`;
|
||||||
it('should be called', () => {
|
it("should be called", () => {
|
||||||
const spy = jest.fn()
|
const spy = jest.fn();
|
||||||
parser.once('delete', spy)
|
parser.once("delete", spy);
|
||||||
parser.parse(message)
|
parser.parse(message);
|
||||||
expect(spy).toHaveBeenCalledWith('12asdf34')
|
expect(spy).toHaveBeenCalledWith("12asdf34");
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('event is not delete', () => {
|
describe("event is not delete", () => {
|
||||||
const message = `event: event\ndata: 12asdf34\n\n`
|
const message = `event: event\ndata: 12asdf34\n\n`;
|
||||||
it('should be error', () => {
|
it("should be error", () => {
|
||||||
const error = jest.fn()
|
const error = jest.fn();
|
||||||
const deleted = jest.fn()
|
const deleted = jest.fn();
|
||||||
parser.once('error', error)
|
parser.once("error", error);
|
||||||
parser.once('delete', deleted)
|
parser.once("delete", deleted);
|
||||||
parser.parse(message)
|
parser.parse(message);
|
||||||
expect(error).toHaveBeenCalled()
|
expect(error).toHaveBeenCalled();
|
||||||
expect(deleted).not.toHaveBeenCalled()
|
expect(deleted).not.toHaveBeenCalled();
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('message is json', () => {
|
describe("message is json", () => {
|
||||||
describe('event is update', () => {
|
describe("event is update", () => {
|
||||||
const message = `event: update\ndata: ${JSON.stringify(status)}\n\n`
|
const message = `event: update\ndata: ${JSON.stringify(status)}\n\n`;
|
||||||
it('should be called', () => {
|
it("should be called", () => {
|
||||||
const spy = jest.fn()
|
const spy = jest.fn();
|
||||||
parser.once('update', spy)
|
parser.once("update", spy);
|
||||||
parser.parse(message)
|
parser.parse(message);
|
||||||
expect(spy).toHaveBeenCalledWith(status)
|
expect(spy).toHaveBeenCalledWith(status);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('event is notification', () => {
|
describe("event is notification", () => {
|
||||||
const message = `event: notification\ndata: ${JSON.stringify(notification)}\n\n`
|
const message = `event: notification\ndata: ${JSON.stringify(
|
||||||
it('should be called', () => {
|
notification,
|
||||||
const spy = jest.fn()
|
)}\n\n`;
|
||||||
parser.once('notification', spy)
|
it("should be called", () => {
|
||||||
parser.parse(message)
|
const spy = jest.fn();
|
||||||
expect(spy).toHaveBeenCalledWith(notification)
|
parser.once("notification", spy);
|
||||||
})
|
parser.parse(message);
|
||||||
})
|
expect(spy).toHaveBeenCalledWith(notification);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('event is conversation', () => {
|
describe("event is conversation", () => {
|
||||||
const message = `event: conversation\ndata: ${JSON.stringify(conversation)}\n\n`
|
const message = `event: conversation\ndata: ${JSON.stringify(
|
||||||
it('should be called', () => {
|
conversation,
|
||||||
const spy = jest.fn()
|
)}\n\n`;
|
||||||
parser.once('conversation', spy)
|
it("should be called", () => {
|
||||||
parser.parse(message)
|
const spy = jest.fn();
|
||||||
expect(spy).toHaveBeenCalledWith(conversation)
|
parser.once("conversation", spy);
|
||||||
})
|
parser.parse(message);
|
||||||
})
|
expect(spy).toHaveBeenCalledWith(conversation);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue