koishi-test-utils
Version:
Test utilities for Koishi
60 lines (59 loc) • 2.02 kB
TypeScript
import { AppOptions, App, Adapter, Session, Bot, AuthorInfo } from 'koishi-core';
export declare const BASE_SELF_ID = "514";
interface MockedResponse {
code: number;
body: string;
headers: Record<string, any>;
}
declare module 'koishi-core' {
namespace Bot {
interface Platforms {
mock: MockedBot;
}
}
}
declare class MockedBot extends Bot<'mock'> {
status: Bot.Status;
getMessage(channelId: string, messageId: string): Promise<{
messageId: string;
channelId: string;
content: string;
time: number;
subtype: any;
messageType: any;
author: AuthorInfo;
}>;
}
declare class MockedServer extends Adapter {
constructor(app: App);
stop(): void;
start(): Promise<void>;
get(path: string, headers?: Record<string, any>): Promise<MockedResponse>;
post(path: string, body: any, headers?: Record<string, any>): Promise<MockedResponse>;
receive(method: string, path: string, headers: Record<string, any>, content: string): Promise<MockedResponse>;
}
interface MockedAppOptions extends AppOptions {
mockStart?: boolean;
mockDatabase?: boolean;
}
export declare class MockedApp extends App {
server: MockedServer;
constructor(options?: MockedAppOptions);
get selfId(): string;
receive(meta: Partial<Session>): string;
session(userId: string, channelId?: string): TestSession;
initUser(id: string, authority?: number): Promise<void>;
initChannel(id: string, assignee?: string): Promise<void>;
}
export declare class TestSession {
app: MockedApp;
userId: string;
channelId?: string;
meta: Partial<Session.Message>;
private replies;
constructor(app: MockedApp, userId: string, channelId?: string);
receive(content: string, count?: number): Promise<string[]>;
shouldReply(message: string, reply?: string | RegExp | (string | RegExp)[]): Promise<void>;
shouldNotReply(message: string): Promise<void>;
}
export { MockedApp as App };