Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/raycast

src/raycast.test.ts

57 lines · 1.8 KB · TypeScript
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
import {
	OFFICIAL_PACKAGE_ID,
	PACKAGE_NAME,
	PUBLIC_URL,
	getExportName,
	invocationUrl,
	isDryRun,
	routeExportName,
	tokenSetupUrl,
} from './helpers.ts'

const here = dirname(fileURLToPath(import.meta.url))
const root = join(here, '..')

test('official identity has no personal scope or tokens', () => {
	const manifest = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
	assert.equal(manifest.name, PACKAGE_NAME)
	assert.equal(manifest.private, false)
	assert.equal(manifest.license, 'MIT')
	assert.equal(manifest.kody.id, 'raycast')
	assert.equal(manifest.kody.jobs, undefined)
	assert.doesNotMatch(JSON.stringify(manifest), /kentcdodds/i)
	assert.doesNotMatch(readFileSync(join(root, 'README.md'), 'utf8'), /KODY_TOKEN=kody_/)
})

test('token setup URL is prefilled and never includes a raw token', () => {
	const url = tokenSetupUrl()
	assert.equal(
		url,
		`https://kody.codes/account/packages/${OFFICIAL_PACKAGE_ID}?newToken=1&name=Raycast&exportNames=*`,
	)
	assert.doesNotMatch(url, /rawToken|bearer=/i)
	assert.match(url, /newToken=1/)
	assert.equal(PUBLIC_URL, 'https://kody.codes/@kody/raycast')
})

test('invocation URL is owner-scoped', () => {
	assert.equal(
		invocationUrl('alice', 'list-packages'),
		'https://kody.codes/@alice/api/package-invocations/raycast/list-packages',
	)
	assert.equal(routeExportName('.'), '__root__')
	assert.equal(routeExportName('./invoke'), 'invoke')
	assert.equal(getExportName('.'), '')
	assert.equal(getExportName('./get-package'), 'get-package')
})

test('invoke dryRun is opt-in', () => {
	assert.equal(isDryRun({}), false)
	assert.equal(isDryRun({ dryRun: false }), false)
	assert.equal(isDryRun({ dryRun: true }), true)
})