threadTitleProcessor.test.tsx1.1 KBView on GitHub
import { threadTitleUpdatedResponseProcessor } from '@/store/agentConnection/responseProcessors/threadTitleUpdatedResponseProcessor';

describe('threadTitleUpdatedResponseProcessor', () => {
  it('validates a well-formed event', () => {
    expect(
      threadTitleUpdatedResponseProcessor.validate?.({
        type: 'thread-title-updated',
        threadId: 't1',
        title: 'Numeral pricing follow-up',
      } as never),
    ).toBe(true);
  });

  it('rejects a malformed event', () => {
    expect(
      threadTitleUpdatedResponseProcessor.validate?.({ type: 'thread-title-updated' } as never),
    ).toBe(false);
  });

  it('routes to updateThreadName and stores the summary', () => {
    const updateThreadName = jest.fn();
    const mergeChatContext = jest.fn();
    threadTitleUpdatedResponseProcessor.execute(
      { type: 'thread-title-updated', threadId: 't1', title: 'My title', summary: 'about X' } as never,
      { updateThreadName, mergeChatContext } as never,
    );
    expect(updateThreadName).toHaveBeenCalledWith('t1', 'My title');
    expect(mergeChatContext).toHaveBeenCalledWith('t1', { summary: 'about X' });
  });
});