import assert from 'node:assert/strict'; import { test } from 'node:test'; import { ChannelType } from 'discord.js'; import { FollowBot } from '../src/bot.ts'; import { loadConfig } from '../src/config.ts'; import { Store } from '../src/db.ts'; /** 정원이 찬 채널 A(봇이 들어가 있음, joinable=false)와 같은 상태의 채널 B */ function fakeGuild() { const guild: any = { id: 'g', members: { me: {} }, voiceStates: { cache: new Map() } }; const channel = (id: string) => ({ id, guild, type: ChannelType.GuildVoice, joinable: false, permissionsFor: () => ({ has: () => true }) }); const A = channel('A'); const B = channel('B'); guild.voiceStates.cache.set('u1', { id: 'u1', channelId: 'A', channel: A, member: { user: { bot: false } } }); guild.voiceStates.cache.set('u2', { id: 'u2', channelId: 'B', channel: B, member: { user: { bot: false } } }); return guild; } test('봇이 들어가 정원이 찬 지금 채널의 동의자는 그대로 따라간다 (나갔다 들어오기 반복 X)', async () => { const store = new Store(':memory:'); store.consent({ id: 'u1', username: 'a' }); store.consent({ id: 'u2', username: 'b' }); const cfg = loadConfig({ PUBLIC_URL: 'http://localhost', DISCORD_CLIENT_ID: 'c', DISCORD_CLIENT_SECRET: 's' }, false); const bot = new FollowBot(cfg, store); const guild = fakeGuild(); assert.deepEqual(bot.consentedPresence(guild), []); // 들어가 있지 않으면 꽉 찬 채널은 못 들어감 (bot as any).recorders.set('g', { channelId: 'A' }); assert.deepEqual(bot.consentedPresence(guild), [{ userId: 'u1', channelId: 'A' }]); // 지금 채널 A 는 유지, 꽉 찬 B 는 제외 (bot as any).recorders.clear(); await bot.client.destroy(); store.close(); });