import {
  describe,
  expect,
  it,
  vi
} from 'vitest';
import {
  BUILT_IN_SLASH_COMMANDS,
  BUILT_IN_SLASH_COMMAND_SOURCE,
  BUILT_IN_SLASH_COMMAND_SOURCE_KEY,
  buildBuiltInSlashCommandEntries
} from './chat-builtin-slash-commands.rules';

describe('built-in slash commands', () => {
  it('includes a global lenny command that sends the Lenny face', () => {
    const lenny = BUILT_IN_SLASH_COMMANDS.find((command) => command.name === 'lenny');

    expect(lenny?.text).toBe('( ͡° ͜ʖ ͡°)');
  });

  it('adapts definitions to global slash command entries tagged as built-in', () => {
    const entries = buildBuiltInSlashCommandEntries(
      () => {},
      (key) => `i18n:${key}`
    );
    const lenny = entries.find((entry) => entry.contribution.name === 'lenny');

    expect(lenny?.pluginId).toBe(`i18n:${BUILT_IN_SLASH_COMMAND_SOURCE_KEY}`);
    expect(lenny?.id).toBe(`${BUILT_IN_SLASH_COMMAND_SOURCE}:lenny`);
    expect(lenny?.contribution.scope).toBe('global');
    expect(lenny?.contribution.description).toBe('i18n:chat.slashCommand.lennyDescription');
  });

  it('runs the command by sending its text', () => {
    const sendText = vi.fn();
    const entries = buildBuiltInSlashCommandEntries(sendText);

    entries
      .find((entry) => entry.contribution.name === 'lenny')
      ?.contribution.run({
        args: {},
        command: 'lenny',
        rawArgs: '',
        server: null,
        source: 'slashCommand',
        textChannel: null,
        user: null,
        voiceChannel: null
      });

    expect(sendText).toHaveBeenCalledWith('( ͡° ͜ʖ ͡°)');
  });
});
