Skip to content

Commit f080492

Browse files
ashleywolfCopilot
andcommitted
Add tests for ships data, event parsing, TBD/all-day times
- Ships tests: validate required fields, date format, URL format, description length - Event parsing tests: TBD defaults, all-day handling, multi-day endDate, validation errors Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d468996 commit f080492

2 files changed

Lines changed: 109 additions & 0 deletions

File tree

tests/event-parsing.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { parseEvent } from '../api/events'
2+
3+
describe('Event parsing - TBD and All Day times', () => {
4+
const baseEvent = {
5+
slug: 'test-event',
6+
title: 'Test Event',
7+
date: '05/15',
8+
type: 'talk',
9+
content: 'Test content',
10+
link: '/schedule/test-event',
11+
}
12+
13+
test('Event with no times defaults to TBD', () => {
14+
const parsed = parseEvent({ ...baseEvent })
15+
expect(parsed.formattedDate.startTime.utc).toBe('TBD')
16+
expect(parsed.formattedDate.startTime.pt).toBe('TBD')
17+
})
18+
19+
test('Event with explicit TBD start time', () => {
20+
const parsed = parseEvent({ ...baseEvent, UTCStartTime: 'TBD' })
21+
expect(parsed.formattedDate.startTime.utc).toBe('TBD')
22+
})
23+
24+
test('Event with all-day start time', () => {
25+
const parsed = parseEvent({ ...baseEvent, UTCStartTime: 'all-day' })
26+
expect(parsed.formattedDate.timeDisplay).toBe('all-day')
27+
})
28+
29+
test('Event with valid times parses correctly', () => {
30+
const parsed = parseEvent({
31+
...baseEvent,
32+
UTCStartTime: '14:00',
33+
UTCEndTime: '15:00',
34+
})
35+
expect(parsed.formattedDate.startTime.utc).not.toBe('TBD')
36+
expect(parsed.formattedDate.endTime.utc).not.toBe('TBD')
37+
})
38+
39+
test('Event with endDate shows formatted end date', () => {
40+
const parsed = parseEvent({
41+
...baseEvent,
42+
endDate: '05/18',
43+
UTCStartTime: '14:00',
44+
UTCEndTime: '15:00',
45+
})
46+
expect(parsed.formattedDate.endDate).toBeTruthy()
47+
})
48+
49+
test('Event without title throws', () => {
50+
expect(() => parseEvent({ ...baseEvent, title: undefined })).toThrow()
51+
})
52+
53+
test('Event with invalid type throws', () => {
54+
expect(() =>
55+
parseEvent({ ...baseEvent, type: 'invalid-type' }),
56+
).toThrow()
57+
})
58+
59+
test('Event with invalid date format throws', () => {
60+
expect(() =>
61+
parseEvent({ ...baseEvent, date: 'May 15' }),
62+
).toThrow()
63+
})
64+
})

tests/ships.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import shipsJSON from '../content/ships/ships.json'
2+
3+
const { ships } = shipsJSON
4+
5+
describe('Ships', () => {
6+
test('Ships must have a title', () => {
7+
const areAllValid = ships.every((ship) => ship.title)
8+
expect(areAllValid).toBe(true)
9+
})
10+
11+
test('Ships must have a URL', () => {
12+
const areAllValid = ships.every((ship) => ship.url)
13+
expect(areAllValid).toBe(true)
14+
})
15+
16+
test('Ships must have a date in YYYY-MM-DD format', () => {
17+
const dateRegex = /^\d{4}-\d{2}-\d{2}$/
18+
const areAllValid = ships.every((ship) => dateRegex.test(ship.date))
19+
expect(areAllValid).toBe(true)
20+
})
21+
22+
test('Ships must have a description', () => {
23+
const areAllValid = ships.every((ship) => ship.description)
24+
expect(areAllValid).toBe(true)
25+
})
26+
27+
test('Ships must have a category', () => {
28+
const areAllValid = ships.every((ship) => ship.category)
29+
expect(areAllValid).toBe(true)
30+
})
31+
32+
test('Ships descriptions no longer than 200 characters', () => {
33+
const areAllValid = ships.every(
34+
(ship) => ship.description.length <= 200,
35+
)
36+
expect(areAllValid).toBe(true)
37+
})
38+
39+
test('Ships URLs must start with https://', () => {
40+
const areAllValid = ships.every((ship) =>
41+
ship.url.startsWith('https://'),
42+
)
43+
expect(areAllValid).toBe(true)
44+
})
45+
})

0 commit comments

Comments
 (0)