mirror of
https://github.com/sern-handler/handler
synced 2026-06-27 18:22:14 +00:00
test: add tests
This commit is contained in:
35
test/core/create-plugin.test.ts
Normal file
35
test/core/create-plugin.test.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { CommandControlPlugin, CommandInitPlugin, EventControlPlugin, EventInitPlugin } from '../../src/core/create-plugins'
|
||||
import { PluginType, controller } from '../../src/index'
|
||||
|
||||
describe('create-plugins', () => {
|
||||
it('should make proper control plugins', () => {
|
||||
const pl = EventControlPlugin(() => controller.next())
|
||||
expect(pl)
|
||||
.to.have.all.keys(['type', 'execute'])
|
||||
expect(pl.type).toBe(PluginType.Control)
|
||||
expect(pl.execute).an('function')
|
||||
const pl2 = CommandControlPlugin(() => controller.next())
|
||||
expect(pl2)
|
||||
.to.have.all.keys(['type', 'execute'])
|
||||
expect(pl2.type).toBe(PluginType.Control)
|
||||
expect(pl2.execute).an('function')
|
||||
|
||||
})
|
||||
it('should make proper init plugins', () => {
|
||||
const pl = EventInitPlugin(() => controller.next())
|
||||
expect(pl)
|
||||
.to.have.all.keys(['type', 'execute'])
|
||||
expect(pl.type).toBe(PluginType.Init)
|
||||
expect(pl.execute).an('function')
|
||||
|
||||
const pl2 = CommandInitPlugin(() => controller.next())
|
||||
expect(pl2)
|
||||
.to.have.all.keys(['type', 'execute'])
|
||||
expect(pl2.type).toBe(PluginType.Init)
|
||||
expect(pl2.execute).an('function')
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
46
test/core/functions.test.ts
Normal file
46
test/core/functions.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, it } from "vitest";
|
||||
import { PluginType, SernOptionsData, controller } from '../../src/index'
|
||||
import { partitionPlugins, treeSearch } from "../../src/core/functions";
|
||||
import { expect } from "chai";
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { ApplicationCommandOptionType } from "discord.js";
|
||||
|
||||
describe('functions', () => {
|
||||
function createRandomPlugins(len: number) {
|
||||
const random = () => Math.floor(Math.random()*2)+1; // 1 or 2, plugin enum
|
||||
return Array.from({ length: len }, () => ({ type: random(), execute: () => random() === 1 ? controller.next():controller.stop() }))
|
||||
}
|
||||
function createRandomChoice() {
|
||||
return {
|
||||
type: faker.number.int({ min: 1, max: 11}),
|
||||
name: faker.word.noun(),
|
||||
description: faker.word.adjective(),
|
||||
}
|
||||
}
|
||||
it('should partition plugins correctly', () => {
|
||||
const plugins = createRandomPlugins(100);
|
||||
const [ onEvent, init ] = partitionPlugins(plugins)
|
||||
for(const el of onEvent)
|
||||
expect(el.type).to.equal(PluginType.Control)
|
||||
|
||||
for(const el of init)
|
||||
expect(el.type).to.equal(PluginType.Init)
|
||||
})
|
||||
|
||||
it('should tree search options tree depth 1', () => {
|
||||
const options : SernOptionsData[] = [
|
||||
createRandomChoice(),
|
||||
createRandomChoice(),
|
||||
createRandomChoice(),
|
||||
{ type: ApplicationCommandOptionType.String,
|
||||
name: 'autocomplete',
|
||||
description: 'here',
|
||||
autocomplete: true,
|
||||
command : { onEvent: [], execute:(a) => {} }
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user