Luigit
repositories / Unfugwart

Unfugwart

Discord caretaker for Abteilung Unfug

owned by admin

test/private-replies.test.js

Raw
import test from 'node:test';
import assert from 'node:assert/strict';
import { MessageFlags } from 'discord.js';
import { DiscordUi } from '../discord-ui.js';

function fixture() {
  const mapping = { serverId: 'game', guildId: 'guild', voiceChannelId: 'voice', displayName: 'Game', controlRoleName: 'Unfugwart' };
  const entry = { mapping, control: { state: () => ({}), manualStart: async () => ({ status: 'success' }) }, poller: { state: () => ({ status: 'offline', phase: 'offline' }), poll: async () => {} } };
  return new DiscordUi({ client: { guilds: { cache: new Map() } }, config: { panelUrl: 'https://panel.example' }, entries: new Map([['voice', entry]]) });
}

test('initial replies and followups use ephemeral flags without deprecated options', async () => {
  const ui = fixture();
  try {
    for (const replied of [false, true]) {
      let options;
      const capture = async value => { options = value; };
      await ui.safeReply({ replied, reply: capture, followUp: capture }, ui.response(null, 'Test', 'Private response.'));
      assert.equal(options.flags, MessageFlags.Ephemeral);
      assert.equal(Object.hasOwn(options, 'ephemeral'), false);
      assert.ok(options.embeds.length);
    }
  } finally { ui.close(); }
});

test('setup, status and control deferrals use ephemeral flags', async () => {
  const ui = fixture();
  try {
    for (const action of ['setup', 'status', 'start']) {
      let options;
      const request = { isChatInputCommand: () => true, commandName: 'server', guildId: 'guild', guild: { id: 'guild', roles: { cache: new Map([['role', { id: 'role', name: 'Unfugwart' }]]) } }, member: { roles: { cache: new Set(['role']) } }, options: { getString: name => name === 'aktion' ? action : 'game' },
        async deferReply(value) { options = value; this.deferred = true; }, async editReply() {} };
      await ui.interaction(request);
      assert.deepEqual(options, { flags: MessageFlags.Ephemeral });
    }
  } finally { ui.close(); }
});