MotorSignal-App/website/tests/group-ride-payload.test.ts

80 lines
3.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, it, expect } from 'vitest';
import { buildWebGroupRidePayload, type WebGroupRideInput } from '../lib/group-ride-payload';
const baseRide: WebGroupRideInput = {
id: 'ride-temp',
title: ' Canyon Dawn Patrol ',
description: ' Fast sweepers ',
region: 'Santa Cruz Mountains',
scheduledDate: '',
scheduledTime: '',
paceClassification: 'Brisk Pace',
discipline: 'Sport / Canyon',
formationProfile: 'Staggered Dual Column [B]',
joinPolicy: 'requestToJoin',
leadHandle: 'You (Organizer)',
leadAvatarText: 'YOU',
participantCount: 1,
participantLimit: 12,
distance: '50.0 Miles',
meetingPoint: 'Alice’s Restaurant, Skyline Blvd',
routeSnippet: 'Skyline > Hwy 9',
userStatus: 'joined',
status: 'scheduled',
};
const ctx = {
rideId: 'ride_123_abc',
uid: 'rider-uid-1',
leadHandle: 'rider_one',
leadDisplayName: 'Rider One',
now: new Date('2026-10-14T12:00:00.000Z'),
};
describe('buildWebGroupRidePayload (WEB Phase 3 ride creation)', () => {
it('never fabricates meeting-point coordinates', () => {
const p = buildWebGroupRidePayload(baseRide, ctx) as any;
expect(p.meetingPoint.latitude).toBeUndefined();
expect(p.meetingPoint.longitude).toBeUndefined();
expect('latitude' in p.meetingPoint).toBe(false);
expect('longitude' in p.meetingPoint).toBe(false);
// The rider's typed rally point is preserved as text.
expect(p.meetingPoint.displayName).toBe('Alice’s Restaurant, Skyline Blvd');
expect(p.meetingPoint.address).toBe('Santa Cruz Mountains');
});
it('falls back to the region for the rally point when none is typed', () => {
const p = buildWebGroupRidePayload({ ...baseRide, meetingPoint: '' }, ctx) as any;
expect(p.meetingPoint.displayName).toBe('Santa Cruz Mountains');
});
it('sets authoritative organizer and access fields and trims text', () => {
const p = buildWebGroupRidePayload(baseRide, ctx) as any;
expect(p.id).toBe('ride_123_abc');
expect(p.organizerUid).toBe('rider-uid-1');
expect(p.accessUids).toEqual(['rider-uid-1']);
expect(p.participantCount).toBe(1);
expect(p.title).toBe('Canyon Dawn Patrol');
expect(p.description).toBe('Fast sweepers');
expect(typeof p.scheduledStartAt).toBe('string');
expect(Number.isNaN(Date.parse(p.scheduledStartAt as string))).toBe(false);
});
it('honors a valid future scheduled date/time', () => {
const p = buildWebGroupRidePayload(
{ ...baseRide, scheduledDate: '2026-12-25', scheduledTime: '09:30' },
ctx
) as any;
expect(p.scheduledStartAt).toBe(new Date('2026-12-25 09:30').toISOString());
});
it('includes club identity only when provided', () => {
const withClub = buildWebGroupRidePayload({ ...baseRide, clubId: 'club-1', clubName: 'Apex MC' }, ctx) as any;
expect(withClub.clubId).toBe('club-1');
expect(withClub.clubName).toBe('Apex MC');
const withoutClub = buildWebGroupRidePayload(baseRide, ctx) as any;
expect('clubId' in withoutClub).toBe(false);
});
});