Commit 972cb6dd authored by nanahira's avatar nanahira

tests

parent d6abd9f7
Pipeline #12263 passed with stages
in 2 minutes and 14 seconds
......@@ -3,7 +3,7 @@ import { RegisterSchema, SchemaProperty } from 'schemastery-gen';
import { BasePlugin } from '../src/base-plugin';
import { UseCommand } from 'koishi-decorators';
import { MultiInstancePlugin } from '../src/multi-plugin';
import { App } from 'koishi';
import { App, Schema } from 'koishi';
class MessageConfig {
@SchemaProperty()
......@@ -28,6 +28,14 @@ class Inner extends BasePlugin<InnerMessageConfig> {
}
}
@DefinePlugin({ schema: Schema.object({ msg: Schema.string() }) })
class Inner2 extends BasePlugin<InnerMessageConfig> {
@UseCommand('message')
async onMessage() {
return this.config.msg;
}
}
@DefinePlugin()
class Outer extends MultiInstancePlugin(Inner, OuterMessageConfig) {
@UseCommand('message2')
......@@ -41,8 +49,21 @@ class Outer extends MultiInstancePlugin(Inner, OuterMessageConfig) {
}
}
@DefinePlugin()
class Outer2 extends MultiInstancePlugin(Inner2, OuterMessageConfig) {
@UseCommand('message2')
async onMessage() {
return this.config.getMsg();
}
@UseCommand('message3')
async onInnerMessage() {
return this.instances[0].config.msg;
}
}
describe('It should register multi plugin instance', () => {
it('register command on condition', async () => {
it('should work on schemastery-gen', async () => {
const app = new App();
app.plugin(Outer, { msg: 'hello', instances: [{ msg: 'world' }] });
await app.start();
......@@ -53,4 +74,16 @@ describe('It should register multi plugin instance', () => {
expect(await outerCommand.execute({})).toBe('hello');
expect(await innerInnerCommand.execute({})).toBe('world');
});
it('should work on common schemastery', async () => {
const app = new App();
app.plugin(Outer2, { msg: 'hello', instances: [{ msg: 'world' }] });
await app.start();
const innerCommand = app.command('message');
const outerCommand = app.command('message2');
const innerInnerCommand = app.command('message3');
expect(await innerCommand.execute({})).toBe('world');
expect(await outerCommand.execute({})).toBe('hello');
expect(await innerInnerCommand.execute({})).toBe('world');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment