tests
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
mightypanders 2022-04-21 19:46:13 +02:00
parent 85770a6031
commit c58c3c61a8
2 changed files with 94 additions and 3 deletions

View 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')
})
})

View File

@ -1,7 +1,9 @@
import { findInScheduleTypes } from '../server/helper/typeFind'
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 { 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'
@ -20,8 +22,8 @@ describe('Schedule names are parsed correctly', () => {
expect(findInScheduleTypes('MONTHly')).toEqual(monthlyValue)
})
})
describe('Parsing of Repetition Info from Description String',()=>{
test('Happy Path',()=>{
describe('Parsing of Repetition Info from Description String', () => {
test('Happy Path', () => {
const inputString = '$rep:daily:1/3'
const expectedInfo: RepetitonInfo = {
totalAmount: 3,
@ -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)
})