Skip to content
← Public packages

@kody/github

Call GitHub REST, GraphQL, and pull requests with a GitHub OAuth App or a personal access token.

FollowFork

Files

auth-options.test.ts

31 lines · 1.2 KB · TypeScript
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { REMOVED_AUTH_OPTIONS, rejectRemovedAuthOptions } from '../src/auth-options.ts'

test('no removed options passes', () => {
	assert.doesNotThrow(() => rejectRemovedAuthOptions({ owner: 'o', repo: 'r', prNumber: 1 }))
	assert.doesNotThrow(() => rejectRemovedAuthOptions({ secretName: undefined, integrationName: null }))
	assert.doesNotThrow(() => rejectRemovedAuthOptions(undefined))
})

for (const key of REMOVED_AUTH_OPTIONS) {
	test(`${key} throws and points to the credentials map`, () => {
		assert.throws(
			() => rejectRemovedAuthOptions({ [key]: 'githubKodyBotToken' }),
			(error: Error) => {
				assert.match(error.message, new RegExp(`removed the "${key}" option`))
				assert.match(error.message, /credential slot named "github"/)
				assert.match(error.message, /--credential github=githubKodyBotToken/)
				assert.match(error.message, /\{ credentials: \{ github: "githubKodyBotToken" \} \}/)
				return true
			},
		)
	})
}

test('several removed options are all named', () => {
	assert.throws(
		() => rejectRemovedAuthOptions({ secretName: 'a', account: 'b' }),
		/removed the "secretName", "account" options/,
	)
})