Files
wibosim/server/src/inbox.test.js
T
db9979andClaude Opus 5.5 50cbde8655 Posteingang als eigene Seite wie ein Mailprogramm (0.31.0)
Ordner nach Art der Meldung, kompakte Liste nach Tagen, Lesespalte mit
passenden Aktionen; gleichartige Meldungen gebündelt. Stern, Archiv,
Löschen, ungelesen, Mehrfachauswahl, Suche und Tastaturkürzel.
Server: inboxAct, bis zu 200 Meldungen, markierte bleiben erhalten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
2026-12-04 19:37:24 +00:00

61 lines
2.8 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import os from 'node:os';
import fs from 'node:fs';
import path from 'node:path';
process.env.NODE_ENV = 'test';
process.env.TIME_MODE = 'turbo';
process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'wibosim-test-'));
const { settings } = await import('./settings.js');
const { Store } = await import('./store.js');
const { Game } = await import('./game.js');
Object.assign(settings.game, { dayMs: 60_000, tickMs: 1000, rivalsEnabled: false, ipoEveryDays: 0, agmEnabled: false });
settings.news.enabled = false;
async function setup() {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'wibosim-inbox-'));
const g = new Game({ store: new Store(dir), now: () => Date.now() });
const p = (await g.register({ name: 'Postfach', password: 'geheim123' })).player;
p.inbox = [];
return { g, p };
}
test('Posteingang: Stern, Archiv, ungelesen, löschen; Archiviertes zählt nicht als ungelesen', async () => {
const { g, p } = await setup();
for (let i = 0; i < 4; i++) g.notify(p.id, { kind: 'quest', title: `Aufgabe ${i}`, text: `Text ${i} (+25 XP)` });
const [a, b, c, d] = p.inbox; // neueste zuerst
assert.equal(g.social.unread(p), 4);
let r = g.social.inboxAct(p, [a.id], 'star');
assert.equal(r.n, 1);
assert.equal(p.inbox.find((x) => x.id === a.id).star, true);
g.social.inboxAct(p, [a.id], 'unstar');
assert.equal(p.inbox.find((x) => x.id === a.id).star, undefined);
r = g.social.inboxAct(p, [b.id, c.id], 'archive');
assert.equal(r.unread, 2, 'archivierte Meldungen gelten als gelesen');
assert.ok(p.inbox.filter((x) => x.arch).length === 2);
g.social.inboxAct(p, [b.id], 'unarchive');
assert.equal(p.inbox.find((x) => x.id === b.id).arch, undefined);
g.social.inboxAct(p, [d.id], 'read');
g.social.inboxAct(p, [d.id], 'unread');
assert.equal(p.inbox.find((x) => x.id === d.id).read, false);
r = g.social.inboxAct(p, [d.id], 'delete');
assert.equal(p.inbox.length, 3);
assert.ok(!p.inbox.some((x) => x.id === d.id));
assert.throws(() => g.social.inboxAct(p, [a.id], 'explode'), /Unbekannte Aktion/);
assert.throws(() => g.social.inboxAct(p, [], 'read'), /Keine Meldung/);
assert.throws(() => g.social.inboxAct(p, ['gibtsnicht'], 'read'), /gibt es nicht mehr/);
});
test('Posteingang: Obergrenze streicht zuerst alte Meldungen ohne Stern', async () => {
const { g, p } = await setup();
g.notify(p.id, { kind: 'info', title: 'Wichtig, alt' });
const keep = p.inbox[0].id;
g.social.inboxAct(p, [keep], 'star');
for (let i = 0; i < 205; i++) g.notify(p.id, { kind: 'info', title: `Meldung ${i}` });
assert.equal(p.inbox.length, 200);
assert.ok(p.inbox.some((x) => x.id === keep), 'markierte Meldung bleibt');
assert.equal(p.inbox[0].title, 'Meldung 204');
});