Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | import { describe, expect, test } from 'bun:test'; |
| 2 | import { readFileSync } from 'node:fs'; |
| 3 | import { join } from 'node:path'; |
| 4 | import { createElement, type ComponentType } from 'react'; |
| 5 | import { renderToStaticMarkup } from 'react-dom/server'; |
| 6 | import { |
| 7 | getKbLegacySegments, |
| 8 | getKbGuideUrl, |
| 9 | getPublishedKbGuides, |
| 10 | resolveKbAlias, |
| 11 | } from '@/lib/kb/repository'; |
| 12 | import { knowledgeBaseSource } from '@/lib/source'; |
| 13 | import * as kbArticleShellModule from '@/components/kb/kb-article-shell'; |
| 14 | |
| 15 | const guideRouteSource = readFileSync( |
| 16 | join(import.meta.dir, '../../app/(home)/kb/guide/[slug]/page.tsx'), |
| 17 | 'utf8', |
| 18 | ); |
| 19 | const legacyRouteSource = readFileSync( |
| 20 | join(import.meta.dir, '../../app/(home)/kb/[...legacy]/page.tsx'), |
| 21 | 'utf8', |
| 22 | ); |
| 23 | const guideLayoutSource = readFileSync( |
| 24 | join(import.meta.dir, '../../app/(home)/kb/guide/layout.tsx'), |
| 25 | 'utf8', |
| 26 | ); |
| 27 | const articleShellSource = readFileSync( |
| 28 | join(import.meta.dir, '../../components/kb/kb-article-shell.tsx'), |
| 29 | 'utf8', |
| 30 | ); |
| 31 | |
| 32 | describe('public KB routes', () => { |
| 33 | test('loads the generated root and flat guide through Fumadocs', () => { |
| 34 | const guide = getPublishedKbGuides()[0]; |
| 35 | expect(guide).toBeDefined(); |
| 36 | expect(knowledgeBaseSource.getPage([])?.url).toBe('/kb'); |
| 37 | expect( |
| 38 | knowledgeBaseSource.getPage([ |
| 39 | 'guide', |
| 40 | guide!.slug, |
| 41 | ])?.url, |
| 42 | ).toBe(getKbGuideUrl(guide!)); |
| 43 | expect(knowledgeBaseSource.getPage(['sdk-and-api'])).toBeUndefined(); |
| 44 | }); |
| 45 | |
| 46 | test('builds flat canonical URLs and resolves imported path aliases', () => { |
| 47 | const guide = getPublishedKbGuides().find( |
| 48 | candidate => candidate.aliases.some(alias => alias.startsWith('/kb/')), |
| 49 | ); |
| 50 | expect(guide).toBeDefined(); |
| 51 | const pathAlias = guide!.aliases.find(alias => alias.startsWith('/kb/'))!; |
| 52 | expect(getKbGuideUrl(guide!)).toBe(`/kb/guide/${guide!.slug}`); |
| 53 | expect(resolveKbAlias(pathAlias)).toBe(`/kb/guide/${guide!.slug}`); |
| 54 | }); |
| 55 | |
| 56 | test('exposes exactly one Fumadocs page per published guide', () => { |
| 57 | const pageUrls = new Set(knowledgeBaseSource.getPages().map(page => page.url)); |
| 58 | for (const guide of getPublishedKbGuides()) { |
| 59 | expect(pageUrls.has(getKbGuideUrl(guide))).toBe(true); |
| 60 | } |
| 61 | }); |
| 62 | |
| 63 | test('renders feedback controls and redirects aliases before notFound', () => { |
| 64 | expect(guideRouteSource).toContain('<Feedback page={page.url} />'); |
| 65 | expect(legacyRouteSource).toContain('resolveKbAlias'); |
| 66 | expect(legacyRouteSource.indexOf('permanentRedirect')).toBeLessThan( |
| 67 | legacyRouteSource.indexOf('notFound()'), |
| 68 | ); |
| 69 | }); |
| 70 | |
| 71 | test('renders a concise last-verified date beside the existing feedback control', () => { |
| 72 | const KbGuideVerification = ( |
| 73 | kbArticleShellModule as { |
| 74 | KbGuideVerification?: ComponentType<{ lastVerifiedAt: string }>; |
| 75 | } |
| 76 | ).KbGuideVerification; |
| 77 | expect(typeof KbGuideVerification).toBe('function'); |
| 78 | if (!KbGuideVerification) return; |
| 79 | |
| 80 | const html = renderToStaticMarkup(createElement(KbGuideVerification, { |
| 81 | lastVerifiedAt: '2026-08-17', |
| 82 | })); |
| 83 | expect(html).toContain('Last verified'); |
| 84 | expect(html).toContain('<time dateTime="2026-08-17">Aug 17, 2026</time>'); |
| 85 | expect(guideRouteSource).toContain( |
| 86 | '<KbGuideVerification lastVerifiedAt={lastVerifiedAt} />', |
| 87 | ); |
| 88 | expect(guideRouteSource).toContain('<Feedback page={page.url} />'); |
| 89 | }); |
| 90 | |
| 91 | test('provides DocsPage context without exposing the generated guide tree', () => { |
| 92 | expect(guideLayoutSource).toContain('<DocsLayout'); |
| 93 | expect(guideLayoutSource).toContain('enabled: false'); |
| 94 | }); |
| 95 | |
| 96 | test('uses a curated article navigation instead of listing every guide', () => { |
| 97 | expect(guideLayoutSource).toContain('<KbArticleShell>'); |
| 98 | expect(articleShellSource).toContain('Browse all toolkits'); |
| 99 | expect(articleShellSource).toContain('PRODUCT_AREAS'); |
| 100 | expect(articleShellSource).toContain('[grid-area:sidebar]'); |
| 101 | expect(articleShellSource).toContain('md:layout:[--fd-sidebar-width:268px]'); |
| 102 | expect(guideRouteSource).toContain('<KbMobileArticleNavigation />'); |
| 103 | for (const guide of getPublishedKbGuides()) { |
| 104 | expect(articleShellSource).not.toContain(guide.title); |
| 105 | } |
| 106 | }); |
| 107 | |
| 108 | test('prebuilds every published legacy path for permanent redirects', () => { |
| 109 | const legacySegments = getKbLegacySegments(); |
| 110 | const expected = getPublishedKbGuides().flatMap(guide => guide.aliases) |
| 111 | .filter(alias => alias.startsWith('/kb/')) |
| 112 | .map(alias => alias.slice('/kb/'.length).split('/')); |
| 113 | for (const segments of expected) expect(legacySegments).toContainEqual(segments); |
| 114 | expect(legacyRouteSource).toContain('generateStaticParams'); |
| 115 | expect(legacyRouteSource).toContain('getKbLegacySegments'); |
| 116 | }); |
| 117 | }); |