Skip to content

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

Package listing

@kody/sessionize

src/smoke-test.ts

66 lines · 1.9 KB · TypeScript
import getEvent from './get-event.ts'
import getSchedule from './get-schedule.ts'
import listSessions from './list-sessions.ts'
import listSpeakers from './list-speakers.ts'
import { SESSIONIZE_DEMO_ENDPOINT_ID } from './types.ts'

export type SmokeTestInput = {
	/** Defaults to Sessionize's official demo endpoint. */
	endpointId?: string
}

/**
 * Hit a live Sessionize endpoint and confirm sessions, speakers, and schedule.
 *
 * @example
 * import smokeTest from 'kody:@kody/sessionize/smoke-test'
 * const result = await smokeTest()
 * // => { ok: true, endpointId: 'jl4ktls0', sessionCount: 11, speakerCount: 10 }
 */
export default async function smokeTest(input: SmokeTestInput = {}): Promise<{
	ok: boolean
	endpointId: string
	sessionCount: number
	speakerCount: number
	roomCount: number
	listedSessionCount: number
	listedSpeakerCount: number
	scheduleDayCount: number
	sampleSessions: Array<{ id: string; title: string; room: string | null }>
	sampleSpeakers: Array<{ id: string; fullName: string }>
}> {
	const endpointId = input.endpointId ?? SESSIONIZE_DEMO_ENDPOINT_ID
	const [event, sessions, speakers, schedule] = await Promise.all([
		getEvent({ endpointId }),
		listSessions({ endpointId }),
		listSpeakers({ endpointId }),
		getSchedule({ endpointId }),
	])

	const ok =
		event.sessionCount > 0 &&
		event.speakerCount > 0 &&
		sessions.count > 0 &&
		speakers.count > 0 &&
		schedule.days.length > 0

	return {
		ok,
		endpointId,
		sessionCount: event.sessionCount,
		speakerCount: event.speakerCount,
		roomCount: event.roomCount,
		listedSessionCount: sessions.count,
		listedSpeakerCount: speakers.count,
		scheduleDayCount: schedule.days.length,
		sampleSessions: event.sessions.slice(0, 3).map((session) => ({
			id: session.id,
			title: session.title,
			room: session.room,
		})),
		sampleSpeakers: event.speakers.slice(0, 3).map((speaker) => ({
			id: speaker.id,
			fullName: speaker.fullName,
		})),
	}
}