This commit is contained in:
parent
85770a6031
commit
c58c3c61a8
30
tests/createdEvent.test.ts
Normal file
30
tests/createdEvent.test.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { getRepetitonInfo } from "../server/handler/repeatingEvents/helper"
|
||||||
|
|
||||||
|
describe('ScheduledEvent Creation Events', () => {
|
||||||
|
|
||||||
|
test('Daily Event with absolute end date', () => {
|
||||||
|
const eventObject = {
|
||||||
|
"id": "965576921410859018",
|
||||||
|
"guildId": "907936880190967850",
|
||||||
|
"channelId": "907936880190967854",
|
||||||
|
"creatorId": "191951058111692800",
|
||||||
|
"name": "Created event",
|
||||||
|
"description": "$rep:daily:2022-05-22",
|
||||||
|
"scheduledStartTimestamp": 1650294000782,
|
||||||
|
"scheduledEndTimestamp": null,
|
||||||
|
"privacyLevel": "GUILD_ONLY",
|
||||||
|
"status": "SCHEDULED",
|
||||||
|
"entityType": "VOICE",
|
||||||
|
"entityId": null,
|
||||||
|
"userCount": null,
|
||||||
|
"creator": null,
|
||||||
|
"entityMetadata": null
|
||||||
|
}
|
||||||
|
const rInfo = getRepetitonInfo(eventObject.description)
|
||||||
|
expect(rInfo).toBeDefined()
|
||||||
|
expect(rInfo.endDate).toBeDefined()
|
||||||
|
expect(rInfo.endDate).toEqual(new Date("2022-05-22"))
|
||||||
|
expect(rInfo.schedule).toEqual('daily')
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
@ -1,7 +1,9 @@
|
|||||||
import { findInScheduleTypes } from '../server/helper/typeFind'
|
import { findInScheduleTypes } from '../server/helper/typeFind'
|
||||||
import { supportedSchedule } from '../server/types/scheduledEventTypes'
|
import { supportedSchedule } from '../server/types/scheduledEventTypes'
|
||||||
import { getRepetitonInfo } from '../server/handler/repeatingEvents/helper'
|
import { createEventInGuild, getRepetitonInfo } from '../server/handler/repeatingEvents/helper'
|
||||||
import { RepetitonInfo } from '../server/types/scheduledEventTypes'
|
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', () => {
|
describe('Schedule names are parsed correctly', () => {
|
||||||
const dailyValue: supportedSchedule = 'daily'
|
const dailyValue: supportedSchedule = 'daily'
|
||||||
const weeklyValue: supportedSchedule = 'weekly'
|
const weeklyValue: supportedSchedule = 'weekly'
|
||||||
@ -33,3 +35,62 @@ describe('Parsing of Repetition Info from Description String',()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
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/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)
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user