Skip to content

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

Package listing

@kody/morning-briefing

src/google-setup.test.ts

31 lines · 1.2 KB · TypeScript
import assert from 'node:assert/strict'
import test from 'node:test'
import {
	GOOGLE_CALENDAR_CONNECT_URL,
	GOOGLE_INBOX_CONNECT_URL,
	googleCalendarSetupError,
	googleInboxSetupError,
} from './google-setup.ts'

test('calendar 403 names calendar.readonly and the built-in connect URL', () => {
	const error = googleCalendarSetupError(
		{ status: 403, message: 'ACCESS_TOKEN_SCOPE_INSUFFICIENT' },
		'personal',
	)
	assert.match(error.message, /calendar\.readonly/)
	assert.match(error.message, /personal/)
	assert.equal(error.message.includes(GOOGLE_CALENDAR_CONNECT_URL), true)
})

test('inbox 403 names gmail.readonly and the BYO connect URL', () => {
	const error = googleInboxSetupError({ status: 403, message: 'insufficient_scope' }, 'google')
	assert.match(error.message, /gmail\.readonly/)
	assert.match(error.message, /restricted/)
	assert.equal(error.message.includes(GOOGLE_INBOX_CONNECT_URL), true)
})

test('unrelated errors keep their original message', () => {
	const original = new Error('Calendar backend exploded')
	assert.equal(googleCalendarSetupError(original, 'personal'), original)
	assert.equal(googleInboxSetupError(new Error('network down'), 'personal').message, 'network down')
})