The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/packages/apps-engine/tests/server/accessors/SlashCommandsExtend.spec.ts

47 lines
1.5 KiB

import { AsyncTest, Expect, Test } from 'alsatian';
import type { ISlashCommand } from '../../../src/definition/slashcommands';
import { SlashCommandsExtend } from '../../../src/server/accessors';
import { CommandAlreadyExistsError } from '../../../src/server/errors';
import type { AppSlashCommandManager } from '../../../src/server/managers';
export class SlashCommandsExtendAccessorTestFixture {
@Test()
public basicSlashCommandsExtend() {
Expect(() => new SlashCommandsExtend({} as AppSlashCommandManager, 'testing')).not.toThrow();
}
@AsyncTest()
public async provideCommandToCommandsExtend(): Promise<void> {
const commands = new Map<string, Array<ISlashCommand>>();
const mockManager: AppSlashCommandManager = {
addCommand(appId: string, command: ISlashCommand) {
if (commands.has(appId)) {
const cmds = commands.get(appId);
if (cmds.find((v) => v.command === command.command)) {
throw new CommandAlreadyExistsError(command.command);
}
cmds.push(command);
return;
}
commands.set(appId, Array.from([command]));
},
} as AppSlashCommandManager;
const se = new SlashCommandsExtend(mockManager, 'testing');
const mockCommand: ISlashCommand = {
command: 'mock',
i18nDescription: 'Thing',
} as ISlashCommand;
await Expect(() => se.provideSlashCommand(mockCommand)).not.toThrowAsync();
Expect(commands.size).toBe(1);
await Expect(() => se.provideSlashCommand(mockCommand)).toThrowErrorAsync(
CommandAlreadyExistsError,
'The command "mock" already exists in the system.',
);
}
}