51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
import { describe, it, expect } from 'vitest'
|
|
import { readFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { dirname, join } from 'node:path'
|
|
import { parseICS } from '../src/lib/ical-io.js'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
const GOLDEN = readFileSync(join(__dirname, 'golden-org.ics'), 'utf-8')
|
|
|
|
describe('parseICS', () => {
|
|
const { meta, events } = parseICS(GOLDEN)
|
|
|
|
it('parses calendar meta', () => {
|
|
expect(meta.prodid).toBe('-//Allocate//iCal4j 1.0//EN')
|
|
expect(meta.version).toBe('2.0')
|
|
expect(meta.calscale).toBe('GREGORIAN')
|
|
expect(meta.vtimezones.length).toBe(1)
|
|
})
|
|
|
|
it('parses all 61 events', () => {
|
|
expect(events).toHaveLength(61)
|
|
})
|
|
|
|
it('parses first event fields correctly', () => {
|
|
const e = events[0]
|
|
expect(e.summary).toBe('ACC INFO SYS, Tutorial')
|
|
expect(e.location).toBe('CA_B_B471')
|
|
expect(e.dtstartDate).toBe('2026-07-27')
|
|
expect(e.dtstartTime).toBe('18:00')
|
|
expect(e.dtendTime).toBe('20:00')
|
|
expect(e.tzid).toBe('Australia/Melbourne')
|
|
expect(e.rrule).toBeNull()
|
|
expect(e.exdates).toEqual([])
|
|
})
|
|
|
|
it('preserves description with escaped commas', () => {
|
|
const e = events[0]
|
|
expect(e.description).toContain('ACF2400_CA_S2_ON-CAMPUS')
|
|
expect(e.description).toContain('ACC INFO SYS')
|
|
})
|
|
|
|
it('captures dtstamp in _raw', () => {
|
|
expect(events[0]._raw.dtstamp).toBe('20260711T085008Z')
|
|
})
|
|
|
|
it('events have UIDs', () => {
|
|
expect(events[0].uid).toBe('uid0')
|
|
expect(events[60].uid).toBe('uid60')
|
|
})
|
|
})
|