From ccc17c4750cbf559f9d9bfffeeb34efa0e0a8b08 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Sat, 14 Jan 2023 19:00:33 +0000 Subject: [PATCH] Add Utility for testing appservice commands in integration tests. --- .../utils/AppserviceBotCommandClient.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/appservice/utils/AppserviceBotCommandClient.ts diff --git a/test/appservice/utils/AppserviceBotCommandClient.ts b/test/appservice/utils/AppserviceBotCommandClient.ts new file mode 100644 index 00000000..609da802 --- /dev/null +++ b/test/appservice/utils/AppserviceBotCommandClient.ts @@ -0,0 +1,20 @@ +import { MjolnirAppService } from "../../../src/appservice/AppService"; +import { ReadItem } from "../../../src/commands/interface-manager/CommandReader"; +import { findCommandTable } from "../../../src/commands/interface-manager/InterfaceCommand"; +import { ArgumentStream } from "../../../src/commands/interface-manager/ParamaterParsing"; +import { CommandResult } from "../../../src/commands/interface-manager/Validation"; + +export class AppservideBotCommandClient { + constructor(private readonly appservice: MjolnirAppService) { + + } + + public async sendCommand>(...items: ReadItem[]): Promise { + const stream = new ArgumentStream(items); + const matchingCommand = findCommandTable("appservice bot").findAMatchingCommand(stream); + if (!matchingCommand) { + throw new TypeError(`Couldn't finnd a command from these items ${JSON.stringify(items)}`); + } + return await matchingCommand.parseThenInvoke({ appservice: this.appservice }, ...stream.rest()) as CommandReturnType; + } +}