fix(ci): resolve Journey strict checks and test contexts

Give the upload DTO an object for file-only requests, make UI error keys discoverable, and run the digest fixtures with the same ORM context as scheduled jobs.
This commit is contained in:
Maurice
2026-11-30 17:41:53 +01:00
parent 0c08a6dcb9
commit 21391e483d
40 changed files with 47 additions and 72 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
// FE-API-JOURNEY-SOCIAL-001
//
// #1702, #1669: every call pins its method and path and hands back what the server answered.
import { http, HttpResponse } from 'msw';
import { http, HttpResponse, type JsonBodyType } from 'msw';
import { describe, expect, it } from 'vitest';
import { server } from '../../tests/helpers/msw/server';
import { journeySocialApi } from './journeySocial';
@@ -10,7 +10,7 @@ describe('journeySocialApi', () => {
it('FE-API-JOURNEY-SOCIAL-001: calls the comment, follower and link routes', async () => {
const seen: string[] = [];
const record =
(body: unknown) =>
(body: JsonBodyType) =>
({ request }: { request: Request }) => {
seen.push(`${request.method} ${new URL(request.url).pathname}`);
return HttpResponse.json(body);
@@ -149,7 +149,7 @@ export default function JourneyDayRecordingButton({
}
aria-disabled={!canTakeOver}
aria-label={label}
aria-haspopup={canTakeOver && canImportGpx ? 'menu' : undefined}
aria-haspopup={canImportGpx ? 'menu' : undefined}
data-testid="journey-day-recording"
className={ROUND}
style={{ background: 'var(--vg-surf2)' }}
@@ -6,7 +6,7 @@ import { useToast } from '../shared/Toast';
import { Tooltip } from '../shared/Tooltip';
/** One comment as the thread draws it: in the app and on the shared page alike. */
export interface EntryCommentItem {
interface EntryCommentItem {
id: number;
author_name?: string | null;
is_guest: boolean;
@@ -285,18 +285,17 @@ interface GuestThreadState {
addComment: (entryId: number, name: string, body: string) => Promise<GuestOutcome>;
}
const GUEST_OUTCOME_KEYS: Record<Exclude<GuestOutcome, 'ok'>, string> = {
closed: 'journey.comments.closed',
gone: 'journey.public.notFoundMessage',
locked: 'journey.comments.locked',
rate_limited: 'common.tooManyAttempts',
invalid: 'journey.comments.invalid',
failed: 'journey.comments.failed',
};
/** The thread under an entry on the shared page, for readers who sign with a name. */
export function GuestEntryComments({ entryId, thread }: { entryId: number; thread: GuestThreadState }) {
const { t } = useTranslation();
const messages = {
closed: t('journey.comments.closed'),
gone: t('journey.public.notFoundMessage'),
locked: t('journey.comments.locked'),
rate_limited: t('common.tooManyAttempts'),
invalid: t('journey.comments.invalid'),
failed: t('journey.comments.failed'),
};
if (!thread.commentsOpen) return null;
return (
<JourneyEntryComments
@@ -305,7 +304,7 @@ export function GuestEntryComments({ entryId, thread }: { entryId: number; threa
guest
onAdd={async (body, name) => {
const outcome = await thread.addComment(entryId, name, body);
return outcome === 'ok' ? null : t(GUEST_OUTCOME_KEYS[outcome]);
return outcome === 'ok' ? null : messages[outcome];
}}
/>
);
@@ -8,18 +8,19 @@ export function useJourneyLiveData<T>(journeyId: number | null, eventName: strin
const [loaded, setLoaded] = useState<{ journeyId: number; data: T } | null>(null);
const [failedFor, setFailedFor] = useState<number | null>(null);
const activeId = useRef(journeyId);
const latestRead = useRef(0);
const latestRead = useRef<symbol | null>(null);
useLayoutEffect(() => {
activeId.current = journeyId;
return () => {
activeId.current = null;
latestRead.current++;
latestRead.current = null;
};
}, [journeyId]);
const refresh = useCallback(async () => {
if (journeyId === null) return;
const version = ++latestRead.current;
const version = Symbol();
latestRead.current = version;
await read(journeyId).then(
(data) => {
if (latestRead.current === version) setLoaded({ journeyId, data });
@@ -23,7 +23,7 @@ export function expiryIso(day: string): string | null {
}
/** Today as a date field's lower bound. */
export function todayDay(): string {
function todayDay(): string {
return expiryDay(new Date().toISOString());
}
@@ -107,7 +107,10 @@ function buildHook(over: Record<string, unknown> = {}): Record<string, unknown>
acceptDawarich: vi.fn(async () => {}), dismissDawarich: vi.fn(),
// The recorded days a journey keeps (JRN-01) and the day take-over (JRN-02): none here,
// their dialogs have suites of their own.
recordings: { byDate: new Map(), dialog: null, open: vi.fn() },
recordings: { byDate: new Map(), bySource: { dawarich: new Map(), gpx: new Map() }, dialog: null, open: vi.fn() },
gpxImport: { busy: false, importDayFile: vi.fn(), removeDay: vi.fn() },
canImportGpx: false,
comments: { byEntry: new Map(), canModerate: false, add: vi.fn(), setHidden: vi.fn(), remove: vi.fn() },
canTakeOverRecording: false, recordingNeedsConnection: false,
dayImport: { open: vi.fn(), dialog: null },
// Preparing the recorded days (JRN-03): not read here, so nothing is marked and the settings
@@ -14,15 +14,6 @@ import { useTranslation } from '../../i18n';
import { GLASS } from '../sharedTrip/SharedChrome';
import type { PublicSocialOutcome } from './journeyPublicModel';
const OUTCOME_KEYS: Record<Exclude<PublicSocialOutcome, 'ok'>, string> = {
closed: 'journey.follow.closed',
gone: 'journey.public.notFoundMessage',
locked: 'journey.comments.locked',
rate_limited: 'common.tooManyAttempts',
invalid: 'journey.follow.invalid',
failed: 'journey.follow.failed',
};
/**
* "Follow" on a shared journey (#1669): one glass pill in the hero, and a small
* dialog that takes an address. The server answers the same for an address that
@@ -34,6 +25,14 @@ export function JourneyPublicFollow({
onSubscribe: (email: string, locale: string) => Promise<PublicSocialOutcome>;
}) {
const { t, locale } = useTranslation();
const messages = {
closed: t('journey.follow.closed'),
gone: t('journey.public.notFoundMessage'),
locked: t('journey.comments.locked'),
rate_limited: t('common.tooManyAttempts'),
invalid: t('journey.follow.invalid'),
failed: t('journey.follow.failed'),
};
const labelId = useId();
const [open, setOpen] = useState(false);
const [email, setEmail] = useState('');
@@ -60,7 +59,7 @@ export function JourneyPublicFollow({
const outcome = await onSubscribe(email.trim(), locale || 'en');
setBusy(false);
if (outcome === 'ok') setSent(true);
else setError(t(OUTCOME_KEYS[outcome]));
else setError(messages[outcome]);
};
return (
@@ -3,12 +3,6 @@ import { useState, type FormEvent, type ReactNode } from 'react';
import { useTranslation } from '../../i18n';
import type { PublicUnlockOutcome } from './journeyPublicModel';
const OUTCOME_KEYS: Record<Exclude<PublicUnlockOutcome, 'ok' | 'expired'>, string> = {
wrong: 'journey.public.passwordWrong',
rate_limited: 'common.tooManyAttempts',
failed: 'journey.public.passwordFailed',
};
function GateFrame({
icon,
title,
@@ -41,6 +35,11 @@ export function JourneyPublicPasswordCard({
onUnlock: (password: string) => Promise<PublicUnlockOutcome>;
}) {
const { t } = useTranslation();
const messages = {
wrong: t('journey.public.passwordWrong'),
rate_limited: t('common.tooManyAttempts'),
failed: t('journey.public.passwordFailed'),
};
const [password, setPassword] = useState('');
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
@@ -53,7 +52,7 @@ export function JourneyPublicPasswordCard({
const outcome = await onUnlock(password);
setBusy(false);
if (outcome === 'ok' || outcome === 'expired') return;
setError(t(OUTCOME_KEYS[outcome]));
setError(messages[outcome]);
};
return (