82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
import { Guild, GuildScheduledEvent, Message } from "discord.js"
|
|
import VoteController from "../../server/helper/vote.controller"
|
|
import { JellyfinHandler } from "../../server/jellyfin/handler"
|
|
import { ExtendedClient } from "../../server/structures/client"
|
|
import { Emoji, NONE_OF_THAT } from "../../server/constants"
|
|
import { isVoteMessage } from "../../server/helper/messageIdentifiers"
|
|
|
|
describe('vote controller - none_of_that functions', () => {
|
|
const testEventId = '1234321'
|
|
const testEventDate = new Date('2023-01-01')
|
|
const testGuildId = "888999888"
|
|
const testMovies = [
|
|
'Movie1',
|
|
'Movie2',
|
|
'Movie3',
|
|
'Movie4',
|
|
'Movie5',
|
|
]
|
|
const votesList = [
|
|
{ emote: Emoji.one, count: 1, movie: testMovies[0] },
|
|
{ emote: Emoji.two, count: 2, movie: testMovies[1] },
|
|
{ emote: Emoji.three, count: 3, movie: testMovies[2] },
|
|
{ emote: Emoji.four, count: 1, movie: testMovies[3] },
|
|
{ emote: Emoji.five, count: 1, movie: testMovies[4] },
|
|
{ emote: NONE_OF_THAT, count: 2, movie: NONE_OF_THAT },
|
|
]
|
|
const mockClient: ExtendedClient = <ExtendedClient><unknown>{
|
|
user: {
|
|
id: 'mockId'
|
|
}
|
|
}
|
|
const mockEvent: GuildScheduledEvent = <GuildScheduledEvent><unknown>{
|
|
scheduledStartAt: testEventDate,
|
|
id: testEventId,
|
|
guild: testGuildId
|
|
}
|
|
const mockJellyfinHandler: JellyfinHandler = <JellyfinHandler><unknown>{
|
|
getRandomMovieNames: jest.fn().mockReturnValue(["movie1"])
|
|
}
|
|
const votes = new VoteController(mockClient, mockJellyfinHandler)
|
|
const mockMessageContent = votes.createVoteMessageText(mockEvent, testMovies, testGuildId, "requestId")
|
|
|
|
test('sendVoteClosedMessage', async () => {
|
|
mockClient.getAnnouncementChannelForGuild = jest.fn().mockReturnValue({
|
|
send: jest.fn().mockImplementation((options: any) => {
|
|
return new Promise((resolve) => {
|
|
resolve(options)
|
|
})
|
|
})
|
|
})
|
|
const scheduledEvent: GuildScheduledEvent = <GuildScheduledEvent>{
|
|
scheduledStartAt: testEventDate,
|
|
guildId: testGuildId,
|
|
id: testEventId
|
|
}
|
|
|
|
const res = await votes.sendVoteClosedMessage(scheduledEvent, 'MovieNew', 'guild', 'request')
|
|
expect(res).toEqual({
|
|
allowedMentions: {
|
|
parse: ["roles"]
|
|
},
|
|
content: `[Abstimmung beendet] für https://discord.com/events/${testGuildId}/${testEventId}\n<@&WATCHPARTY_ANNOUNCEMENT_ROLE> Wir gucken MovieNew am 01.01. um 01:00`
|
|
})
|
|
})
|
|
|
|
test('getVotesByEmote', async () => {
|
|
const mockMessage: Message = <Message><unknown>{
|
|
cleanContent: mockMessageContent,
|
|
reactions: {
|
|
resolve: jest.fn().mockImplementation((input: any) => {
|
|
return votesList.find(e => e.emote === input)
|
|
})
|
|
}
|
|
}
|
|
if (isVoteMessage(mockMessage)) {
|
|
const result = await votes.getVotesByEmote(mockMessage, 'guildId', 'requestId')
|
|
expect(result.length).toEqual(5)
|
|
expect(result).toEqual(votesList.filter(x => x.movie != NONE_OF_THAT))
|
|
}
|
|
})
|
|
})
|