feat: build the Cool City public route demo
ci / check (push) Successful in 55s

- add /cool, /cool?vote=1, /cool/stage and /cool/city on the existing Nuxt/Onyx stack
- wire real route/shade metrics and OSM geometry from the route bundle; city-gap data for the city view
- show shade % and direct-sun minutes together; recommend Accessible for Ruth with the 15% ramp trade-off
- add in-memory time/scene/round state and one anonymous vote per session, polled every 2 s
- keep the retail module linked but out of the Cool City story
This commit is contained in:
Noel Sabia committed 2026-11-14 13:49:22 +01:00
1 parent 33063afbdf
commit 2bc52a314d
28 files changed
+8633 -45

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
import { beforeEach, describe, expect, it } from 'vitest'
import {
getCoolState,
getCoolVoteTally,
isValidCoolSessionId,
recordCoolVote,
resetCoolDemoStore,
resetCoolRound,
updateCoolState,
} from '../server/utils/cool-votes'
describe('Cool City demo state and vote tally', () => {
beforeEach(() => resetCoolDemoStore())
it('starts with the Ruth card and 10:00, shortest, closed', () => {
const state = getCoolState('preselection')
expect(state.scene).toBe('ruth')
expect(state.time).toBe('10:00')
expect(state.selectedRoute).toBe('shortest')
expect(state.voteOpen).toBe(false)
expect(getCoolVoteTally('preselection').total).toBe(0)
})
it('updates scene, time, route and vote phase', () => {
updateCoolState('preselection', { scene: 'routes', time: '16:00', selectedRoute: 'accessible' })
updateCoolState('preselection', { scene: 'vote', voteOpen: true })
const state = getCoolState('preselection')
expect(state.scene).toBe('vote')
expect(state.time).toBe('16:00')
expect(state.selectedRoute).toBe('accessible')
expect(state.voteOpen).toBe(true)
})
it('does not count duplicate sessions', () => {
updateCoolState('preselection', { scene: 'vote', voteOpen: true })
const first = recordCoolVote('preselection', 'accessible', 'session_12345678')
expect(first.duplicate).toBe(false)
expect(first.tally.counts.accessible).toBe(1)
const duplicate = recordCoolVote('preselection', 'shortest', 'session_12345678')
expect(duplicate.duplicate).toBe(true)
expect(duplicate.route).toBe('accessible')
expect(duplicate.tally.counts.shortest).toBe(0)
expect(duplicate.tally.total).toBe(1)
})
it('keeps preselection and final rounds separate', () => {
updateCoolState('preselection', { scene: 'vote', voteOpen: true })
updateCoolState('final', { scene: 'vote', voteOpen: true })
recordCoolVote('preselection', 'shortest', 'session_aaaaaaaa')
recordCoolVote('final', 'accessible', 'session_bbbbbbbb')
expect(getCoolVoteTally('preselection').counts.shortest).toBe(1)
expect(getCoolVoteTally('final').counts.accessible).toBe(1)
expect(getCoolVoteTally('final').counts.shortest).toBe(0)
})
it('refuses votes before the round is open', () => {
expect(() => recordCoolVote('preselection', 'accessible', 'session_12345678')).toThrow(
'Voting is not open',
)
})
it('resets votes and state for one round only', () => {
updateCoolState('preselection', { scene: 'vote', voteOpen: true })
updateCoolState('final', { scene: 'vote', voteOpen: true })
recordCoolVote('preselection', 'accessible', 'session_aaaaaaaa')
recordCoolVote('final', 'shortest', 'session_bbbbbbbb')
resetCoolRound('preselection')
expect(getCoolState('preselection').scene).toBe('ruth')
expect(getCoolVoteTally('preselection').total).toBe(0)
expect(getCoolVoteTally('final').total).toBe(1)
})
it('accepts opaque random session IDs and rejects unsafe values', () => {
expect(isValidCoolSessionId('8a1f9a2e-9e2c-4f6b-9c2b-3a4b5c6d7e8f')).toBe(true)
expect(isValidCoolSessionId('session_12345678')).toBe(true)
expect(isValidCoolSessionId('short')).toBe(false)
expect(isValidCoolSessionId('has spaces in it')).toBe(false)
expect(isValidCoolSessionId('')).toBe(false)
expect(isValidCoolSessionId(undefined)).toBe(false)
})
})