testcases
This commit is contained in:
		
							
								
								
									
										96
									
								
								tests/discord/noneofthat.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								tests/discord/noneofthat.test.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,96 @@
 | 
				
			|||||||
 | 
					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"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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 mockJellyfinHandler: JellyfinHandler = <JellyfinHandler><unknown>{
 | 
				
			||||||
 | 
							getRandomMovieNames: jest.fn().mockReturnValue(["movie1"])
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						const votes = new VoteController(mockClient, mockJellyfinHandler)
 | 
				
			||||||
 | 
						const mockMessageContent = votes.createVoteMessageText(testEventId, testEventDate, 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<@&> Wir gucken MovieNew am 01.01. um 01:00`
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						//	test('checkForPollsToClose', async () => {
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//		const testGuild: Guild = <Guild><unknown>{
 | 
				
			||||||
 | 
						//			scheduledEvents: {
 | 
				
			||||||
 | 
						//				fetch: jest.fn().mockImplementation(() => {
 | 
				
			||||||
 | 
						//					return new Promise(resolve => {
 | 
				
			||||||
 | 
						//						resolve([
 | 
				
			||||||
 | 
						//							{ name: "Event Name" },
 | 
				
			||||||
 | 
						//							{ name: "Event: VOTING OFFEN", scheduledStartTimestamp: "" },
 | 
				
			||||||
 | 
						//							{ name: "another voting" },
 | 
				
			||||||
 | 
						//						]
 | 
				
			||||||
 | 
						//						)
 | 
				
			||||||
 | 
						//					})
 | 
				
			||||||
 | 
						//				})
 | 
				
			||||||
 | 
						//			}
 | 
				
			||||||
 | 
						//		}
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//		const result = await votes.checkForPollsToClose(testGuild)
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//	})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						test('getVotesByEmote', async () => {
 | 
				
			||||||
 | 
							const mockMessage: Message = <Message><unknown>{
 | 
				
			||||||
 | 
								cleanContent: mockMessageContent,
 | 
				
			||||||
 | 
								reactions: {
 | 
				
			||||||
 | 
									resolve: jest.fn().mockImplementation((input: any) => {
 | 
				
			||||||
 | 
										return votesList.find(e => e.emote === input)
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							const result = await votes.getVotesByEmote(mockMessage, 'guildId', 'requestId')
 | 
				
			||||||
 | 
							expect(result.length).toEqual(5)
 | 
				
			||||||
 | 
							expect(result).toEqual(votesList.filter(x => x.movie != NONE_OF_THAT))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
@@ -3,6 +3,7 @@ import VoteController, { Vote, VoteMessageInfo } from "../../server/helper/vote.
 | 
				
			|||||||
import { JellyfinHandler } from "../../server/jellyfin/handler"
 | 
					import { JellyfinHandler } from "../../server/jellyfin/handler"
 | 
				
			||||||
import { ExtendedClient } from "../../server/structures/client"
 | 
					import { ExtendedClient } from "../../server/structures/client"
 | 
				
			||||||
import { VoteMessage } from "../../server/helper/messageIdentifiers"
 | 
					import { VoteMessage } from "../../server/helper/messageIdentifiers"
 | 
				
			||||||
 | 
					import { Message, MessageReaction } from "discord.js"
 | 
				
			||||||
test('parse votes from vote message', async () => {
 | 
					test('parse votes from vote message', async () => {
 | 
				
			||||||
	const testMovies = [
 | 
						const testMovies = [
 | 
				
			||||||
		'Movie1',
 | 
							'Movie1',
 | 
				
			||||||
@@ -33,11 +34,11 @@ test('parse votes from vote message', async () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	const msg: VoteMessage = <VoteMessage><unknown>{
 | 
						const msg: VoteMessage = <VoteMessage><unknown>{
 | 
				
			||||||
		cleanContent: testMessage,
 | 
							cleanContent: testMessage,
 | 
				
			||||||
		guild:{
 | 
							guild: {
 | 
				
			||||||
			id:testGuildId,
 | 
								id: testGuildId,
 | 
				
			||||||
			scheduledEvents:{
 | 
								scheduledEvents: {
 | 
				
			||||||
				fetch: jest.fn().mockImplementation((input:any)=>{
 | 
									fetch: jest.fn().mockImplementation((input: any) => {
 | 
				
			||||||
					if(input === testEventId)
 | 
										if (input === testEventId)
 | 
				
			||||||
						return {
 | 
											return {
 | 
				
			||||||
							scheduledStartAt: testEventDate
 | 
												scheduledStartAt: testEventDate
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
@@ -83,3 +84,93 @@ test('parse votes from vote message', () => {
 | 
				
			|||||||
	const result = voteController.parseGuildIdAndEventIdFromWholeMessage(testMessage)
 | 
						const result = voteController.parseGuildIdAndEventIdFromWholeMessage(testMessage)
 | 
				
			||||||
	expect(result).toEqual({ guildId: testGuildId, eventId: testEventId })
 | 
						expect(result).toEqual({ guildId: testGuildId, eventId: testEventId })
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test.skip('handles complete none_of_that vote', () => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const mockJellyfinHandler: JellyfinHandler = <JellyfinHandler><unknown>{
 | 
				
			||||||
 | 
							getRandomMovieNames: jest.fn().mockReturnValue(["movie1"])
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const testMovies = [
 | 
				
			||||||
 | 
							'Movie1',
 | 
				
			||||||
 | 
							'Movie2',
 | 
				
			||||||
 | 
							'Movie3',
 | 
				
			||||||
 | 
							'Movie4',
 | 
				
			||||||
 | 
							'Movie5',
 | 
				
			||||||
 | 
						]
 | 
				
			||||||
 | 
						const testEventId = '1234321'
 | 
				
			||||||
 | 
						const testEventDate = new Date('2023-01-01')
 | 
				
			||||||
 | 
						const testGuildId = "888999888"
 | 
				
			||||||
 | 
						const mockClient: ExtendedClient = <ExtendedClient><unknown>{
 | 
				
			||||||
 | 
							user: {
 | 
				
			||||||
 | 
								id: 'mockId'
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						const voteController = new VoteController(mockClient, mockJellyfinHandler)
 | 
				
			||||||
 | 
						const mockMessageContent = voteController.createVoteMessageText(testEventId, testEventDate, testMovies, testGuildId, "requestId")
 | 
				
			||||||
 | 
						const reactedUponMessage: VoteMessage = <VoteMessage><unknown>{
 | 
				
			||||||
 | 
							cleanContent: mockMessageContent,
 | 
				
			||||||
 | 
							guild: {
 | 
				
			||||||
 | 
								id: 'id',
 | 
				
			||||||
 | 
								roles: {
 | 
				
			||||||
 | 
									resolve: jest.fn().mockReturnValue({
 | 
				
			||||||
 | 
										members: [{}, {}, {}, {}, {}]//content does not matter
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								scheduledEvents: {
 | 
				
			||||||
 | 
									fetch: jest.fn().mockReturnValue([
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											name: 'voting offen'
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									])
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							unpin: jest.fn().mockImplementation(() => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
							delete: jest.fn().mockImplementation(() => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
							reactions: {
 | 
				
			||||||
 | 
								resolve: jest.fn().mockImplementation((input: any) => {
 | 
				
			||||||
 | 
									console.log(JSON.stringify(input))
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
								cache: {
 | 
				
			||||||
 | 
									get: jest.fn().mockReturnValue({
 | 
				
			||||||
 | 
										users: {
 | 
				
			||||||
 | 
											cache: [
 | 
				
			||||||
 | 
												{
 | 
				
			||||||
 | 
													id: "mockId"//to filter out
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
												{
 | 
				
			||||||
 | 
													id: "userId1"
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
												{
 | 
				
			||||||
 | 
													id: "userId2"
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
												{
 | 
				
			||||||
 | 
													id: "userId3"
 | 
				
			||||||
 | 
												}
 | 
				
			||||||
 | 
											]
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									})
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						const msgReaction: MessageReaction = <MessageReaction><unknown>{
 | 
				
			||||||
 | 
							message: reactedUponMessage
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockClient.getAnnouncementChannelForGuild = jest.fn().mockReturnValue({
 | 
				
			||||||
 | 
							messages: {
 | 
				
			||||||
 | 
								fetch: jest.fn().mockReturnValue([
 | 
				
			||||||
 | 
									reactedUponMessage
 | 
				
			||||||
 | 
								])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const res = voteController.handleNoneOfThatVote(msgReaction, reactedUponMessage, 'requestId', 'guildId')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user