← Public packages
@kentcdodds/pie-night
Pie night sign-ups: hosts start an event, guests add the pies they are bringing and watch the list fill in live. Installable, with optional push notifications.
Files
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { cleanText, formatEventWhen, isHoneypotFilled, parseEventInput, parsePieInput, pieLook } from '../src/pies.ts'
test('pieLook picks a fun look by name', () => {
assert.equal(pieLook('Grandma\'s Apple Crumble').emoji, '🍎')
assert.equal(pieLook('Coconut cream').emoji, '🥥')
assert.equal(pieLook('PUMPKIN').emoji, '🍂')
assert.equal(pieLook('Banana cream').emoji, '🍌')
assert.equal(pieLook('Mystery pie').emoji, '🥧')
})
test('cleanText trims, collapses and caps', () => {
assert.equal(cleanText(' hi \n\t there\u0000 ', 50), 'hi there')
assert.equal(cleanText('x'.repeat(100), 10).length, 10)
})
test('parsePieInput requires who and pie', () => {
assert.equal(parsePieInput({ who: '', pie: 'Apple' }).ok, false)
assert.equal(parsePieInput({ who: 'Bob', pie: ' ' }).ok, false)
assert.equal(parsePieInput({ who: 'Bob', pie: 'x'.repeat(500) }).ok, false)
const ok = parsePieInput({ who: ' The Smiths ', pie: 'Apple', note: 'gluten free' })
assert.deepEqual(ok, { ok: true, value: { who: 'The Smiths', pie: 'Apple', note: 'gluten free' } })
})
test('honeypot', () => {
assert.equal(isHoneypotFilled({ website: 'http://spam' }), true)
assert.equal(isHoneypotFilled({ website: '' }), false)
})
const EVENT = { title: 'Pie Night', blurb: '', place: '', date: '2026-11-27', time: '18:00', theme: 'harvest' as const }
test('event parsing and formatting', () => {
assert.deepEqual(formatEventWhen(EVENT), { day: 'Friday, November 27', time: '6 PM', short: 'Fri, Nov 27', medium: 'Friday, Nov 27' })
assert.equal(formatEventWhen({ date: '2027-01-02', time: '18:30' }).time, '6:30 PM')
assert.equal(parseEventInput({ date: 'nope' }, EVENT).ok, false)
assert.equal(parseEventInput({ time: '25:00' }, EVENT).ok, false)
const next = parseEventInput({ title: 'Pie Night 2', date: '2027-11-26', time: '19:00', theme: 'nope' }, EVENT)
assert.equal(next.ok && next.value.theme, 'harvest')
assert.equal(next.ok && next.value.date, '2027-11-26')
})
test('new events get the default thank-you message; edits may clear it', async () => {
const { DEFAULT_BLURB } = await import('../src/pies.ts')
const created = parseEventInput({ title: 'Pies', date: '2026-11-27', time: '18:00', blurb: '' })
assert.equal(created.ok && created.value.blurb, DEFAULT_BLURB)
const edited = parseEventInput({ blurb: '' }, { ...EVENT, blurb: 'hi' })
assert.equal(edited.ok && edited.value.blurb, '')
})
test('event codes are forgiving and safe', async () => {
const { slugify, validSlug } = await import('../src/pies.ts')
assert.equal(slugify('Smith Family 2026'), 'smith-family-2026')
assert.equal(slugify(' SMITH family 2026 '), 'smith-family-2026')
assert.equal(slugify("Grandma's Pie Night!"), 'grandmas-pie-night')
assert.equal(slugify('Crème brûlée'), 'creme-brulee')
assert.equal(validSlug('smith-family-2026'), true)
assert.equal(validSlug('admin'), false)
assert.equal(validSlug(''), false)
assert.equal(validSlug('../x'), false)
})
test('co-host lists are cleaned and skip the creator', async () => {
const { cleanHosts } = await import('../src/pies.ts')
assert.deepEqual(cleanHosts(['Bob', ' bob ', 'alice', 'host', 'bad name!'], 'host'), ['bob', 'alice'])
})
test('parsePieBatch saves several pies under one name', async () => {
const { parsePieBatch, LIMITS } = await import('../src/pies.ts')
const ok = parsePieBatch({ who: 'The Smiths', pies: [{ pie: 'Apple' }, { pie: '', note: '' }, { pie: 'Pecan', note: 'nut free? no!' }] })
assert.deepEqual(ok, { ok: true, value: [{ who: 'The Smiths', pie: 'Apple', note: '' }, { who: 'The Smiths', pie: 'Pecan', note: 'nut free? no!' }] })
assert.equal(parsePieBatch({ who: 'A', pies: [] }).ok, false)
assert.equal(parsePieBatch({ who: 'A', pies: [{ pie: '', note: 'warm' }] }).ok, false)
assert.equal(parsePieBatch({ who: 'A', pies: Array.from({ length: LIMITS.batch + 1 }, () => ({ pie: 'Apple' })) }).ok, false)
assert.equal(parsePieBatch({ who: 'A', pie: 'Cherry' }).ok, true)
})