Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.1 KB
Raw Blame
import { describe, expect, it } from 'vitest';

import { publishResourceEvent, resourceChannelId } from '../index';

describe('resourceEvents', () => {
  it('formats a stable channel id per resource', () => {
    expect(resourceChannelId({ id: 'doc-1', type: 'document' })).toBe('resource:document:doc-1');
    expect(resourceChannelId({ id: 'topic-1', type: 'topic' })).toBe('resource:topic:topic-1');
  });

  it('publish is best-effort and never throws (no Redis → in-memory)', async () => {
    await expect(
      publishResourceEvent(
        { id: 'doc-1', type: 'document' },
        { actorId: 'u1', type: 'doc.updated' },
      ),
    ).resolves.toBeUndefined();

    await expect(
      publishResourceEvent(
        { id: 'topic-1', type: 'topic' },
        { actorId: 'u1', type: 'topic.commentsChanged' },
      ),
    ).resolves.toBeUndefined();

    await expect(
      publishResourceEvent(
        { id: 'doc-1', type: 'document' },
        { actorId: 'u1', data: { holderId: null }, type: 'lock.changed' },
      ),
    ).resolves.toBeUndefined();
  });
});