import test from 'node:test'; import assert from 'node:assert/strict'; import { occupancy } from '../occupancy.js'; function guild({ available = true, states = [], voice = true } = {}) { return { available, channels: { cache: new Map([['voice', { isVoiceBased: () => voice }]]) }, voiceStates: { cache: new Map(states.map((state, index) => [index, state])) }, }; } test('cached state without member or user is unknown', () => { assert.deepEqual(occupancy(guild({ states: [{ channelId: 'voice' }] }), 'voice'), { known: false, humans: 0 }); }); test('confirmed bots are ignored and confirmed humans count', () => { assert.deepEqual(occupancy(guild({ states: [ { channelId: 'voice', member: { user: { bot: true } } }, { channelId: 'voice', member: { user: { bot: false } } }, ] }), 'voice'), { known: true, humans: 1 }); }); test('available cached voice channel without states is empty', () => { assert.deepEqual(occupancy(guild(), 'voice'), { known: true, humans: 0 }); }); test('unavailable guild is unknown', () => { assert.deepEqual(occupancy(guild({ available: false }), 'voice'), { known: false, humans: 0 }); });