node-event-bot/tests/repetition.test.ts

93 lines
3.0 KiB
TypeScript

import { Schedule } from '../server/types/scheduledEventTypes'
import { buildNewRepetitionString, getRepetitonInfo } from '../server/handler/repeatingEvents/helper'
import { RepetitonInfo } from '../server/types/scheduledEventTypes'
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: 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",
"channelId": "907936880190967854",
"creatorId": "191951058111692800",
"name": "Created event",
"description": "$rep:daily:2022-05-22",
"createdTimestamp": 1650294000782,
"createdAt": new Date("2022-04-01"),
"scheduledStartTimestamp": 1650294000782,
"scheduledEndTimestamp": null,
"privacyLevel": "GUILD_ONLY",
"status": "ACTIVE",
"entityType": "VOICE",
"entityId": null,
"userCount": null,
"creator": null,
guild: {}
}
const newEvent = {
"id": "965576921410859018",
"guildId": "907936880190967850",
"channelId": "907936880190967854",
"creatorId": "191951058111692800",
"createdTimestamp": 1650294000782,
"name": "Created event",
"description": "$rep:daily:2022-05-22",
"scheduledStartTimestamp": 1650294000782,
"scheduledEndTimestamp": null,
"privacyLevel": "GUILD_ONLY",
"status": "COMPLETED",
"entityType": "VOICE",
"entityId": null,
"userCount": null,
"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)
//})