import { describe, expect, test, vi } from 'vitest'; import { buildPlatformHostDraftFailureNotification, buildPlatformHostDraftNotificationResetKeys, buildPlatformHostDraftReadyNotification, sendPlatformHostDraftNotificationOnce, } from './platformHostNotificationModel'; describe('platformHostNotificationModel', () => { test('builds draft ready notification from stable draft identity', () => { expect( buildPlatformHostDraftReadyNotification('match3d', [ 'match3d-work-1', 'match3d-session-1', ]), ).toEqual({ key: 'draft-ready:match3d:抓大鹅草稿 match3d-session-1', title: '生成完成', body: '抓大鹅草稿 match3d-session-1 生成任务已完成,可以继续查看草稿。', }); }); test('builds draft failure notification only when error text is useful', () => { expect( buildPlatformHostDraftFailureNotification('puzzle', [ 'puzzle-session-1', ], ' 图片生成失败。 '), ).toEqual({ key: 'draft-failed:puzzle:拼图草稿 puzzle-session-1', title: '生成失败', body: '拼图草稿 puzzle-session-1 图片生成失败。', }); expect( buildPlatformHostDraftFailureNotification('puzzle', [ 'puzzle-session-1', ], ' '), ).toBeNull(); expect(buildPlatformHostDraftReadyNotification('puzzle', [])).toBeNull(); }); test('sends host notification once and reset keys allow a later regeneration', () => { const sentKeys = new Set(); const send = vi.fn(); const notification = buildPlatformHostDraftReadyNotification('jump-hop', [ 'jump-hop-session-1', ]); expect( sendPlatformHostDraftNotificationOnce(sentKeys, notification, send), ).toBe(true); expect( sendPlatformHostDraftNotificationOnce(sentKeys, notification, send), ).toBe(false); expect(send).toHaveBeenCalledTimes(1); for (const key of buildPlatformHostDraftNotificationResetKeys('jump-hop', [ 'jump-hop-session-1', ])) { sentKeys.delete(key); } expect( sendPlatformHostDraftNotificationOnce(sentKeys, notification, send), ).toBe(true); expect(send).toHaveBeenCalledTimes(2); }); });