handle test behaviour on start up
This commit is contained in:
		@@ -11,6 +11,7 @@ export class ExtendedClient extends Client {
 | 
			
		||||
		super({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_SCHEDULED_EVENTS] })
 | 
			
		||||
	}
 | 
			
		||||
	public start() {
 | 
			
		||||
		if (process.env.NODE_ENV === 'test') return
 | 
			
		||||
		const promises = []
 | 
			
		||||
		promises.push(this.registerSlashCommands())
 | 
			
		||||
		promises.push(this.registerEventCallback())
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@ import { getRepetitonInfo } from "../server/handler/repeatingEvents/helper"
 | 
			
		||||
describe('ScheduledEvent Creation Events', () => {
 | 
			
		||||
 | 
			
		||||
	test('Daily Event with absolute end date', () => {
 | 
			
		||||
		jest.mock('../server/helper/sendFailureDM.ts')
 | 
			
		||||
		const eventObject = {
 | 
			
		||||
			"id": "965576921410859018",
 | 
			
		||||
			"guildId": "907936880190967850",
 | 
			
		||||
@@ -21,10 +22,11 @@ describe('ScheduledEvent Creation Events', () => {
 | 
			
		||||
			"entityMetadata": null
 | 
			
		||||
		}
 | 
			
		||||
		const rInfo = getRepetitonInfo(eventObject.description)
 | 
			
		||||
		const expectedSchedule = { "_scheduleString": "daily", "baseScheduleTypes": ["daily", "weekly", "monthly", "yearly"], "duration": { "days": 1 }, "multiplier": 1, "scheduleName": "daily" }
 | 
			
		||||
		expect(rInfo).toBeDefined()
 | 
			
		||||
		expect(rInfo.endDate).toBeDefined()
 | 
			
		||||
		expect(rInfo.endDate).toEqual(new Date("2022-05-22"))
 | 
			
		||||
		expect(rInfo.schedule).toEqual('daily')
 | 
			
		||||
		expect(rInfo.schedule).toEqual(expectedSchedule)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
@@ -1,40 +1,35 @@
 | 
			
		||||
import { findInScheduleTypes } from '../server/helper/typeFind'
 | 
			
		||||
import { supportedSchedule } from '../server/types/scheduledEventTypes'
 | 
			
		||||
import { createEventInGuild, getRepetitonInfo } from '../server/handler/repeatingEvents/helper'
 | 
			
		||||
import { Schedule } from '../server/types/scheduledEventTypes'
 | 
			
		||||
import { buildNewRepetitionString, getRepetitonInfo } from '../server/handler/repeatingEvents/helper'
 | 
			
		||||
import { RepetitonInfo } from '../server/types/scheduledEventTypes'
 | 
			
		||||
import { handleRepeatingEvent } from '../server/handler/repeatingEvents/repeatingEvents.controller'
 | 
			
		||||
import { GuildScheduledEventCreateOptions } from 'discord.js'
 | 
			
		||||
describe('Schedule names are parsed correctly', () => {
 | 
			
		||||
	const dailyValue: supportedSchedule = 'daily'
 | 
			
		||||
	const weeklyValue: supportedSchedule = 'weekly'
 | 
			
		||||
	const monthlyValue: supportedSchedule = 'monthly'
 | 
			
		||||
	test('Easy schedule names', () => {
 | 
			
		||||
		expect(findInScheduleTypes('daily')).toEqual(dailyValue)
 | 
			
		||||
		expect(findInScheduleTypes('weekly')).toEqual(weeklyValue)
 | 
			
		||||
		expect(findInScheduleTypes('monthly')).toEqual(monthlyValue)
 | 
			
		||||
	})
 | 
			
		||||
	test('Medium schedule names', () => {
 | 
			
		||||
		expect(findInScheduleTypes('Daily')).toEqual(dailyValue)
 | 
			
		||||
		expect(findInScheduleTypes('Weekly')).toEqual(weeklyValue)
 | 
			
		||||
		expect(findInScheduleTypes('Monthly')).toEqual(monthlyValue)
 | 
			
		||||
		expect(findInScheduleTypes('DAILY')).toEqual(dailyValue)
 | 
			
		||||
		expect(findInScheduleTypes('WEEKLy')).toEqual(weeklyValue)
 | 
			
		||||
		expect(findInScheduleTypes('MONTHly')).toEqual(monthlyValue)
 | 
			
		||||
	})
 | 
			
		||||
})
 | 
			
		||||
describe('Parsing of Repetition Info from Description String', () => {
 | 
			
		||||
	test('Happy Path', () => {
 | 
			
		||||
		const inputString = '$rep:daily:1/3'
 | 
			
		||||
		const expectedInfo: RepetitonInfo = {
 | 
			
		||||
			totalAmount: 3,
 | 
			
		||||
			alreadyOccured: 1,
 | 
			
		||||
			schedule: 'daily'
 | 
			
		||||
			schedule: new Schedule('daily')
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		expect(getRepetitonInfo(inputString)).toEqual(expectedInfo)
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
describe('new RepetitionString for complex schedule', () => {
 | 
			
		||||
	const repString = '$rep:EvEry3WeeKs:2022-12-01'
 | 
			
		||||
	const repInfo = getRepetitonInfo(repString)
 | 
			
		||||
	const schedule = new Schedule(repString)
 | 
			
		||||
	const str = schedule.getSanitizedScheduleString()
 | 
			
		||||
	expect(str).toEqual('$rep:every3weeks:2022-12-01')
 | 
			
		||||
	const oldDate = new Date('2022-01-01')
 | 
			
		||||
	const newDate = schedule.getNewDate(oldDate)
 | 
			
		||||
	expect(newDate).toEqual(new Date('2022-01-22'))
 | 
			
		||||
	expect(buildNewRepetitionString(repInfo)).toEqual('$rep:every3weeks:2022-12-01')
 | 
			
		||||
})
 | 
			
		||||
describe('new RepetitionString for complex schedule', () => {
 | 
			
		||||
	const repString = '$rep:EvEry3WeeKs:2022-12-01'
 | 
			
		||||
	const schedule = new Schedule(repString)
 | 
			
		||||
	const oldDate = new Date('2022-01-01')
 | 
			
		||||
	const newDate = schedule.getNewDate(oldDate)
 | 
			
		||||
})
 | 
			
		||||
const oldEvent = {
 | 
			
		||||
	"id": "965576921410859018",
 | 
			
		||||
	"guildId": "907936880190967850",
 | 
			
		||||
@@ -73,24 +68,25 @@ const newEvent = {
 | 
			
		||||
	"creator": null,
 | 
			
		||||
	guild: {}
 | 
			
		||||
}
 | 
			
		||||
jest.mock('../server/helper/sendFailureDM.ts')
 | 
			
		||||
jest.mock('../server/handler/repeatingEvents/helper.ts', () => ({
 | 
			
		||||
	...(jest.requireActual('../server/handler/repeatingEvents/helper.ts')),
 | 
			
		||||
	createEventInGuild: jest.fn().mockImplementation((opt: any) => {
 | 
			
		||||
		return
 | 
			
		||||
	})
 | 
			
		||||
}))
 | 
			
		||||
test('handleRepeatingEvent', () => {
 | 
			
		||||
 | 
			
		||||
	const expectedOptions: GuildScheduledEventCreateOptions = {
 | 
			
		||||
		channel: "",
 | 
			
		||||
		description: "",
 | 
			
		||||
		name: newEvent.name,
 | 
			
		||||
		entityType: <'VOICE'>newEvent.entityType,
 | 
			
		||||
		privacyLevel: <'GUILD_ONLY'>newEvent.privacyLevel,
 | 
			
		||||
		reason: 'Repetition',
 | 
			
		||||
		scheduledStartTime: ""
 | 
			
		||||
	}
 | 
			
		||||
	//@ts-ignore
 | 
			
		||||
	handleRepeatingEvent(oldEvent, newEvent)
 | 
			
		||||
	expect(createEventInGuild).toHaveBeenCalledWith({}, expectedOptions)
 | 
			
		||||
})
 | 
			
		||||
//test('handleRepeatingEvent', () => {
 | 
			
		||||
//
 | 
			
		||||
//	const expectedOptions: GuildScheduledEventCreateOptions = {
 | 
			
		||||
//		channel: "",
 | 
			
		||||
//		description: "",
 | 
			
		||||
//		name: newEvent.name,
 | 
			
		||||
//		entityType: <'VOICE'>newEvent.entityType,
 | 
			
		||||
//		privacyLevel: <'GUILD_ONLY'>newEvent.privacyLevel,
 | 
			
		||||
//		reason: 'Repetition',
 | 
			
		||||
//		scheduledStartTime: ""
 | 
			
		||||
//	}
 | 
			
		||||
//	//@ts-ignore
 | 
			
		||||
//	//handleRepeatingEvent(oldEvent, newEvent)
 | 
			
		||||
//	expect(createEventInGuild).toHaveBeenCalledWith({}, expectedOptions)
 | 
			
		||||
//})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user