Skip to content
← Public packages

@kody/integrations-sh

Client for the public integrations.sh registry: search, detect, cached surface, and live discover.

tests/integrations-sh.test.ts

93 lines · 2.7 KB · TypeScript
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { normalizeProviderDomain } from '../src/domain.ts'
import { mapSearchResult, mapSurfaceDocument } from '../src/types.ts'
import {
	buildDetectUrl,
	buildDiscoverUrl,
	buildSearchUrl,
	buildSurfaceUrl,
} from '../src/urls.ts'

test('normalizeProviderDomain accepts bare hostnames and rejects schemes', () => {
	assert.equal(normalizeProviderDomain('GitHub.com'), 'github.com')
	assert.throws(() => normalizeProviderDomain('https://github.com'), {
		message: /URL scheme/,
	})
	assert.throws(() => normalizeProviderDomain('github.com/api'), {
		message: /without a path/,
	})
})

test('buildSearchUrl encodes query, kind, limit, and offset', () => {
	assert.equal(
		buildSearchUrl({ query: 'linear app', kind: 'openapi', limit: 5, offset: 10 }),
		'https://integrations.sh/api/search?q=linear+app&kind=openapi&limit=5&offset=10',
	)
	assert.equal(
		buildDetectUrl('stripe.com'),
		'https://integrations.sh/api/stripe.com/detect',
	)
	assert.equal(
		buildSurfaceUrl('stripe.com'),
		'https://integrations.sh/api/stripe.com/surface',
	)
	assert.equal(
		buildDiscoverUrl('stripe.com'),
		'https://integrations.sh/api/stripe.com/discover',
	)
})

test('mapSearchResult keeps connect-target surfaces and drops junk kinds', () => {
	const mapped = mapSearchResult({
		domain: 'github.com',
		name: 'GitHub',
		description: 'Dev platform',
		kinds: ['openapi', 'mcp', 'nope'],
		url: 'https://integrations.sh/github.com',
		surfaces: [
			{ kind: 'openapi', slug: 'github-rest', url: 'https://api.github.com' },
			{ kind: 'nope', slug: 'bad' },
		],
	})
	assert.deepEqual(mapped, {
		domain: 'github.com',
		name: 'GitHub',
		description: 'Dev platform',
		kinds: ['openapi', 'mcp'],
		url: 'https://integrations.sh/github.com',
		surfaces: [
			{ kind: 'openapi', slug: 'github-rest', url: 'https://api.github.com' },
		],
	})
})

test('mapSurfaceDocument maps credentials and evidence', () => {
	const mapped = mapSurfaceDocument({
		domain: 'linear.app',
		summary: 'Issue tracker',
		discoveredAt: '2026-01-01T00:00:00.000Z',
		credentials: {
			api_key: {
				type: 'api_key',
				label: 'Linear API key',
				setup: 'Create a key',
			},
		},
		surfaces: [
			{
				type: 'http',
				slug: 'linear-graphql',
				name: 'Linear GraphQL',
				spec: 'https://client.linear.app/openapi.json',
				basis: { via: 'discovered', evidence: ['https://developers.linear.app'] },
			},
		],
	})
	assert.equal(mapped?.domain, 'linear.app')
	assert.equal(mapped?.credentials.api_key?.type, 'api_key')
	assert.equal(mapped?.surfaces[0]?.slug, 'linear-graphql')
	assert.deepEqual(mapped?.surfaces[0]?.evidence, [
		'https://developers.linear.app',
	])
})