Merge pull request #355 from h3poteto/misskey/reactions

Add test for misskey reactions
This commit is contained in:
AkiraFukushima 2020-04-22 21:03:05 +09:00 committed by GitHub
commit f15306f2f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 1 deletions

View file

@ -252,7 +252,7 @@ namespace MisskeyAPI {
const result: Array<MegalodonEntity.Reaction> = []
r.map(e => {
const i = result.findIndex(res => res.name === e.type)
if (i) {
if (i >= 0) {
result[i].count++
} else {
result.push({

View file

@ -0,0 +1,80 @@
import MisskeyAPI from '@/misskey/api_client'
describe('api_client', () => {
describe('reactions', () => {
it('should be mapped', () => {
const misskeyReactions = [
{
id: '1',
createdAt: '2020-04-21T13:04:13.968Z',
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: '❤'
},
{
id: '2',
createdAt: '2020-04-21T13:04:13.968Z',
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: '❤'
},
{
id: '3',
createdAt: '2020-04-21T13:04:13.968Z',
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: '☺'
},
{
id: '4',
createdAt: '2020-04-21T13:04:13.968Z',
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 = MisskeyAPI.Converter.reactions(misskeyReactions)
expect(reactions).toEqual([
{
count: 3,
me: false,
name: '❤'
},
{
count: 1,
me: false,
name: '☺'
}
])
})
})
})