atagen

malice

public
Star0
Watch0
e99ada4450ecaa8f2bbfb50cf78be269cefa8752
2
ssh://brewery@pls.lobotomise.me:33/atagen/malice.git

Blame: web/test/message-sound.test.ts

c8d898e6eb59atagen2026-10-27 03:55 UTC1
import assert from 'node:assert/strict';
c8d898e6eb59atagen2026-10-27 03:55 UTC2
import { test } from 'node:test';
c8d898e6eb59atagen2026-10-27 03:55 UTC3
import { parseMessageSound, shouldPlaySound, SOUND_THROTTLE_MS } from '../src/lib/message-sound-model.ts';
c8d898e6eb59atagen2026-10-27 03:55 UTC4
c8d898e6eb59atagen2026-10-27 03:55 UTC5
test('parse falls back to defaults', () => {
c8d898e6eb59atagen2026-10-27 03:55 UTC6
  assert.deepEqual(parseMessageSound(null), { mode: 'mentions_dms', sound: null });
c8d898e6eb59atagen2026-10-27 03:55 UTC7
  assert.deepEqual(parseMessageSound({ mode: 'bogus', sound: 'http://x' }), { mode: 'mentions_dms', sound: null });
c8d898e6eb59atagen2026-10-27 03:55 UTC8
  assert.deepEqual(parseMessageSound({ mode: 'all', sound: 'mxc://h/a' }), { mode: 'all', sound: 'mxc://h/a' });
c8d898e6eb59atagen2026-10-27 03:55 UTC9
});
c8d898e6eb59atagen2026-10-27 03:55 UTC10
c8d898e6eb59atagen2026-10-27 03:55 UTC11
test('mode decides which arrivals play', () => {
c8d898e6eb59atagen2026-10-27 03:55 UTC12
  const room = { direct: false };
c8d898e6eb59atagen2026-10-27 03:55 UTC13
  const dm = { direct: true };
c8d898e6eb59atagen2026-10-27 03:55 UTC14
  const plain = { mention: false };
c8d898e6eb59atagen2026-10-27 03:55 UTC15
  assert.equal(shouldPlaySound('off', dm, { mention: true }, 0, 10_000), false);
c8d898e6eb59atagen2026-10-27 03:55 UTC16
  assert.equal(shouldPlaySound('all', room, plain, 0, 10_000), true);
c8d898e6eb59atagen2026-10-27 03:55 UTC17
  assert.equal(shouldPlaySound('mentions_dms', room, plain, 0, 10_000), false);
c8d898e6eb59atagen2026-10-27 03:55 UTC18
  assert.equal(shouldPlaySound('mentions_dms', room, { mention: true }, 0, 10_000), true);
c8d898e6eb59atagen2026-10-27 03:55 UTC19
  assert.equal(shouldPlaySound('mentions_dms', dm, plain, 0, 10_000), true);
c8d898e6eb59atagen2026-10-27 03:55 UTC20
});
c8d898e6eb59atagen2026-10-27 03:55 UTC21
c8d898e6eb59atagen2026-10-27 03:55 UTC22
test('throttles repeated plays', () => {
c8d898e6eb59atagen2026-10-27 03:55 UTC23
  const room = { direct: true };
c8d898e6eb59atagen2026-10-27 03:55 UTC24
  assert.equal(shouldPlaySound('all', room, { mention: false }, 10_000, 10_000 + SOUND_THROTTLE_MS - 1), false);
c8d898e6eb59atagen2026-10-27 03:55 UTC25
  assert.equal(shouldPlaySound('all', room, { mention: false }, 10_000, 10_000 + SOUND_THROTTLE_MS), true);
c8d898e6eb59atagen2026-10-27 03:55 UTC26
});