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.

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

import { getTaskDetailPagePath, getTaskDetailPageUrl } from './url';

describe('getTaskDetailPageUrl', () => {
  it('uses a public short link while the portal keeps a stable task id', () => {
    expect(
      getTaskDetailPageUrl({
        appOrigin: 'https://app.example.com',
        taskId: 'task_stable',
        identifier: 'T-3',
        workspaceSlug: 'team',
        agentId: 'agt_1',
      }),
    ).toBe('https://app.example.com/team/agent/agt_1/task/T-3');
  });
  it('builds a workspace-aware agent task URL', () => {
    expect(
      getTaskDetailPageUrl({
        agentId: 'agt-owner',
        appOrigin: 'https://app.example.com',
        taskId: 'T-245',
        workspaceSlug: 'lobehub',
      }),
    ).toBe('https://app.example.com/lobehub/agent/agt-owner/task/T-245');
  });

  it('falls back to the unscoped task route without an agent', () => {
    expect(getTaskDetailPageUrl({ appOrigin: 'https://app.example.com', taskId: 'T-245' })).toBe(
      'https://app.example.com/task/T-245',
    );
  });

  it('appends the readable title slug when a title is known', () => {
    expect(
      getTaskDetailPageUrl({
        appOrigin: 'https://app.example.com',
        taskId: 'T-245',
        title: '飞书适配器支持 POST 图文消息',
        workspaceSlug: 'lobehub',
      }),
    ).toBe('https://app.example.com/lobehub/task/T-245/飞书适配器支持-post-图文消息');
  });

  it('returns undefined without a resolvable absolute URL', () => {
    expect(getTaskDetailPageUrl({ appOrigin: 'https://app.example.com' })).toBeUndefined();
    expect(getTaskDetailPageUrl({ taskId: 'T-245' })).toBeUndefined();
  });
});

describe('getTaskDetailPagePath', () => {
  it('scopes a task from another workspace to that workspace', () => {
    expect(
      getTaskDetailPagePath({
        agentId: 'agt_1',
        identifier: 'T-198',
        title: 'Ship it',
        workspaceSlug: 'lobe-team',
      }),
    ).toBe('/lobe-team/agent/agt_1/task/T-198/ship-it');
  });

  it('has no path without a task reference', () => {
    expect(getTaskDetailPagePath({ workspaceSlug: 'lobe-team' })).toBeUndefined();
  });
});