-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1932 from h3poteto/fix/unwrap
Stop using force unwrap for mapReactions
- Loading branch information
Showing
2 changed files
with
164 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import FirefishAPI from '@/firefish/api_client' | ||
import MegalodonEntity from '@/entity' | ||
|
||
describe('api_client', () => { | ||
describe('mapReactions', () => { | ||
it('should work', () => { | ||
const emojis: Array<FirefishAPI.Entity.Emoji> = [ | ||
{ | ||
name: 'foxverified', | ||
url: 'https://example.com/files/foxverified', | ||
category: null | ||
}, | ||
{ | ||
name: 'verificado', | ||
url: 'https://example.com/files/verificado', | ||
category: null | ||
}, | ||
{ | ||
name: '[email protected]', | ||
url: 'https://example.com/proxy/firefishexample/kawaii', | ||
category: null | ||
}, | ||
{ | ||
name: 'ablobcatnodfast@.', | ||
url: 'https://example.com/files/ablobcatnodfast', | ||
category: null | ||
} | ||
] | ||
const reactions: { [key: string]: number } = { | ||
':ablobcatnodfast@.:': 2, | ||
':[email protected]:': 1 | ||
} | ||
|
||
const res = FirefishAPI.Converter.mapReactions(emojis, reactions) | ||
expect(res).toHaveLength(2) | ||
expect(res).toContainEqual({ | ||
count: 2, | ||
me: false, | ||
name: 'ablobcatnodfast', | ||
url: 'https://example.com/files/ablobcatnodfast', | ||
static_url: 'https://example.com/files/ablobcatnodfast' | ||
} as MegalodonEntity.Reaction) | ||
|
||
expect(res).toContainEqual({ | ||
count: 1, | ||
me: false, | ||
name: '[email protected]', | ||
url: 'https://example.com/proxy/firefishexample/kawaii', | ||
static_url: 'https://example.com/proxy/firefishexample/kawaii' | ||
} as MegalodonEntity.Reaction) | ||
}) | ||
it('does not have emojis', () => { | ||
const emojis: Array<FirefishAPI.Entity.Emoji> = [] | ||
const reactions: { [key: string]: number } = { | ||
':ablobcatnodfast@.:': 2, | ||
':[email protected]:': 1 | ||
} | ||
|
||
const res = FirefishAPI.Converter.mapReactions(emojis, reactions) | ||
expect(res).toHaveLength(2) | ||
expect(res).toContainEqual({ | ||
count: 2, | ||
me: false, | ||
name: 'ablobcatnodfast' | ||
} as MegalodonEntity.Reaction) | ||
|
||
expect(res).toContainEqual({ | ||
count: 1, | ||
me: false, | ||
name: '[email protected]' | ||
} as MegalodonEntity.Reaction) | ||
}) | ||
it('reactions with me', () => { | ||
const emojis: Array<FirefishAPI.Entity.Emoji> = [ | ||
{ | ||
name: 'foxverified', | ||
url: 'https://example.com/files/foxverified', | ||
category: null | ||
}, | ||
{ | ||
name: 'verificado', | ||
url: 'https://example.com/files/verificado', | ||
category: null | ||
}, | ||
{ | ||
name: '[email protected]', | ||
url: 'https://example.com/proxy/firefishexample/kawaii', | ||
category: null | ||
}, | ||
{ | ||
name: 'ablobcatnodfast@.', | ||
url: 'https://example.com/files/ablobcatnodfast', | ||
category: null | ||
} | ||
] | ||
const reactions: { [key: string]: number } = { | ||
':ablobcatnodfast@.:': 2, | ||
':[email protected]:': 1 | ||
} | ||
|
||
const res = FirefishAPI.Converter.mapReactions(emojis, reactions, ':ablobcatnodfast@.:') | ||
expect(res).toHaveLength(2) | ||
expect(res).toContainEqual({ | ||
count: 2, | ||
me: true, | ||
name: 'ablobcatnodfast', | ||
url: 'https://example.com/files/ablobcatnodfast', | ||
static_url: 'https://example.com/files/ablobcatnodfast' | ||
} as MegalodonEntity.Reaction) | ||
|
||
expect(res).toContainEqual({ | ||
count: 1, | ||
me: false, | ||
name: '[email protected]', | ||
url: 'https://example.com/proxy/firefishexample/kawaii', | ||
static_url: 'https://example.com/proxy/firefishexample/kawaii' | ||
} as MegalodonEntity.Reaction) | ||
}) | ||
}) | ||
}) |