Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/lib/api/sync-lines.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, expectTypeOf, it } from 'vitest';
import type { z } from 'zod';
import type { SyncEntityType } from './client';
import { syncStreamLineSchema } from './sync-lines';

const timetableLine = {
Expand All @@ -7,13 +9,35 @@ const timetableLine = {
data: { id: 't', stopId: 's', serviceDate: '2026-10-10', departures: null },
};

const routeLine = {
type: 'RouteV2',
ack: 'RouteV2|1',
data: {
id: 'r',
shortName: 'AGR',
longName: 'Gameday Agronomy',
lightColor: '#f7941d',
darkColor: '#f7941d',
active: true,
isLoop: false,
},
};

describe('syncStreamLineSchema', () => {
it('accepts a line the server sends', () => {
expect(syncStreamLineSchema.parse(timetableLine)).toEqual(timetableLine);
});

it('accepts a RoutesV2 line', () => {
expect(syncStreamLineSchema.parse(routeLine)).toEqual(routeLine);
});

it('rejects a line missing a column', () => {
const { stopId: _, ...data } = timetableLine.data;
expect(syncStreamLineSchema.safeParse({ ...timetableLine, data }).success).toBe(false);
});

it('covers every line type in the api spec', () => {
expectTypeOf<z.infer<typeof syncStreamLineSchema>['type']>().toEqualTypeOf<SyncEntityType>();
});
});
13 changes: 13 additions & 0 deletions src/lib/api/sync-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ export const syncStreamLineSchema = z.discriminatedUnion('type', [
}),
),
line('RouteDeleteV1', z.object({ routeId: z.string() })),
line(
'RouteV2',
z.object({
id: z.string(),
shortName: z.string(),
longName: z.string(),
lightColor: z.string(),
darkColor: z.string(),
active: z.boolean(),
isLoop: z.boolean(),
}),
),
line('RouteDeleteV2', z.object({ routeId: z.string() })),
line(
'DirectionV1',
z.object({
Expand Down
Loading